-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
the general framework, simple case passing
- Loading branch information
Showing
7 changed files
with
69 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Add_Row_Number.enso
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from Standard.Base import all | ||
|
||
import project.Data.Column.Column | ||
import project.Data.Column_Selector.Column_Selector | ||
import project.Data.Sort_Column.Sort_Column | ||
import project.Data.Set_Mode.Set_Mode | ||
import project.Data.Table.Table | ||
import project.Internal.Problem_Builder.Problem_Builder | ||
import project.Internal.Table_Helpers | ||
import project.Internal.Unique_Name_Strategy.Unique_Name_Strategy | ||
|
||
from project.Errors import Duplicate_Output_Column_Names | ||
from project.Internal.Java_Exports import make_long_builder | ||
|
||
## PRIVATE | ||
add_row_number : Table -> Text -> Integer -> Integer -> (Column_Selector | Vector Text) -> Vector (Text | Sort_Column) | Text | Sort_Column -> Problem_Behavior -> Table | ||
add_row_number table name="Row" from=1 step=1 group_by=[] order_by=[] on_problems=Problem_Behavior.Report_Warning = | ||
problem_builder = Problem_Builder.new error_on_missing_columns=True | ||
grouping_columns = table.columns_helper.select_columns_helper group_by True problem_builder | ||
ordering_columns = Table_Helpers.resolve_order_by table.columns order_by problem_builder | ||
problem_builder.attach_problems_before on_problems <| | ||
new_column = case ordering_columns.is_empty of | ||
True -> | ||
case grouping_columns.is_empty of | ||
True -> make_range_column name from step table.row_count | ||
False -> Error.throw "TODO: not implemented yet" | ||
False -> Error.throw "TODO: not implemented yet" | ||
|
||
column_names = table.column_names | ||
renamed_table = if column_names.contains name . not then table else | ||
problems = [Duplicate_Output_Column_Names.Error [name]] | ||
on_problems.attach_problems_before problems <| | ||
unique_name_strategy = Unique_Name_Strategy.new | ||
unique_name_strategy.mark_used column_names | ||
new_name = unique_name_strategy.make_unique name | ||
new_columns = table.columns.map column-> | ||
if column.name == name then column.rename new_name else column | ||
Table.new new_columns | ||
renamed_table.set new_column name set_mode=Set_Mode.Add | ||
|
||
## PRIVATE | ||
make_range_column name start step length = | ||
builder = make_long_builder length | ||
0.up_to length . each ix-> | ||
builder.appendLong (start + ix*step) | ||
storage = builder.seal | ||
Column.from_storage name storage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters