-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement
Table.add_group_number
, with operations Unique
and `Equ…
…al_Count` (#11818) * wip * one test * wip * wip * more tests * changelog * docs, more tests * switch in enso * counter overflow * run under db tests * fmt * merge * move group + order into method * wip * bucket * Revert "bucket" This reverts commit 7ada84c. * aliases * review (cherry picked from commit 739ee3a)
- Loading branch information
1 parent
e8ff34e
commit a855497
Showing
11 changed files
with
557 additions
and
0 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
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
24 changes: 24 additions & 0 deletions
24
distribution/lib/Standard/Table/0.0.0-dev/src/Grouping_Method.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,24 @@ | ||
from Standard.Base import all | ||
import Standard.Base.Errors.Common.Missing_Argument | ||
|
||
polyglot java import org.enso.table.operations.AddGroupNumber | ||
|
||
## Specifies a method for grouping rows in `add_group_number`. | ||
type Grouping_Method | ||
## Group rows by the specified columns. | ||
|
||
Arguments: | ||
- on: Rows that have the same values for these columns will be grouped | ||
together. At least one column must be specified. | ||
Unique (on:(Vector | Text | Integer | Regex)=(Missing_Argument.throw "on")) | ||
|
||
## Create the specified number of groups with the same number of rows in | ||
each group (except possibly the last one). | ||
|
||
Arguments | ||
- group_count: The number of groups to divide the table into. | ||
- order_by: (Optional.) Specifies the order in which rows should be | ||
assigned to groups. Only affects the assignment of group numbers, not | ||
the ordering of the output rows. Defaults to the order of the rows in | ||
the table. | ||
Equal_Count (group_count:Integer=(Missing_Argument.throw "group_count")) (order_by:(Vector | Text)=[]) |
50 changes: 50 additions & 0 deletions
50
distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Add_Group_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,50 @@ | ||
private | ||
|
||
from Standard.Base import all | ||
import Standard.Base.Errors.Common.Unsupported_Argument_Types | ||
import Standard.Base.Errors.Illegal_Argument.Illegal_Argument | ||
|
||
import project.Column.Column | ||
import project.Grouping_Method.Grouping_Method | ||
import project.Internal.Java_Problems | ||
import project.Internal.Problem_Builder.Problem_Builder | ||
import project.Internal.Table_Helpers | ||
import project.Set_Mode.Set_Mode | ||
import project.Table.Table | ||
from project.Internal.Add_Row_Number import rename_columns_if_needed | ||
|
||
polyglot java import java.lang.ArithmeticException | ||
polyglot java import org.enso.table.operations.AddGroupNumber | ||
|
||
add_group_number (table:Table) (grouping_method:Grouping_Method) (name:Text) (from:Integer) (step:Integer) (on_problems:Problem_Behavior=..Report_Warning) -> Table = | ||
problem_builder = Problem_Builder.new error_on_missing_columns=True | ||
|
||
handle_arithmetic_exception _ = | ||
Error.throw (Illegal_Argument.Error "The row number has exceeded the 64-bit integer range. BigInteger numbering is currently not supported. Please use a smaller start/step.") | ||
|
||
Panic.catch ArithmeticException handler=handle_arithmetic_exception <| Panic.catch Unsupported_Argument_Types handler=handle_arithmetic_exception <| | ||
Java_Problems.with_problem_aggregator on_problems java_problem_aggregator-> | ||
new_storage = case grouping_method of | ||
Grouping_Method.Unique group_by -> | ||
_illegal_if group_by.is_empty "..Unique requires a non-empty 'group_by'" <| | ||
grouping = _prepare_group_by table problem_builder group_by | ||
AddGroupNumber.numberGroupsUnique table.row_count from step grouping java_problem_aggregator | ||
Grouping_Method.Equal_Count group_count order_by -> | ||
_illegal_if (group_count < 1) "group_count must be at least 1" <| | ||
ordering = _prepare_ordering table problem_builder order_by | ||
AddGroupNumber.numberGroupsEqualCount table.row_count group_count from step (ordering.at 0) (ordering.at 1) java_problem_aggregator | ||
new_column = Column.from_storage name new_storage | ||
renamed_table = rename_columns_if_needed table name on_problems Table.new | ||
problem_builder.attach_problems_before on_problems <| | ||
renamed_table.set new_column name set_mode=Set_Mode.Add | ||
|
||
_prepare_group_by table problem_builder group_by = | ||
table.columns_helper.select_columns_helper group_by Case_Sensitivity.Default True problem_builder . map c->c.java_column | ||
|
||
_prepare_ordering table problem_builder order_by = | ||
ordering = Table_Helpers.resolve_order_by table.columns order_by problem_builder | ||
ordering_columns = ordering.map c->c.column.java_column | ||
directions = ordering.map c->c.associated_selector.direction.to_sign | ||
[ordering_columns, directions] | ||
|
||
_illegal_if b msg ~cont = if b then Error.throw (Illegal_Argument.Error msg) else cont |
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
Oops, something went wrong.