Skip to content

Commit

Permalink
bucket
Browse files Browse the repository at this point in the history
  • Loading branch information
GregoryTravis committed Dec 16, 2024
1 parent 8441eb0 commit 7ada84c
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ type DB_Table

The following grouping methods are supported:
- `Unique`: Group rows by the specified columns.
- Equal_Count: Create the specified number of groups with the same
- Equal_Bucket_Count: Create the specified number of groups with the same
number of rows in each group (except possibly the last one).

? Ordering of rows
Expand Down Expand Up @@ -1000,7 +1000,7 @@ type DB_Table
4 | 2
5 | 1
table = table_builder [['x', [1, 2, 3, 4, 5]], ['y', [5, 4, 3, 2, 1]]]
table2 = tabble.add_group_number (..Equal_Count 3) "g"
table2 = tabble.add_group_number (..Equal_Bucket_Count 3) "g"
table2.at 'g' . to_vector
# => [0, 0, 1, 1, 2]
## table2:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ type Grouping_Method
each group (except possibly the last one).

Arguments
- group_count: The number of groups to divide the table into.
- bucket_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)=[])
Equal_Bucket_Count (bucket_count:Integer=(Missing_Argument.throw "bucket_count")) (order_by:(Vector | Text)=[])
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ add_group_number (table:Table) (grouping_method:Grouping_Method) (name:Text) (fr
_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==0) "group_count must be at least 1" <|
Grouping_Method.Equal_Bucket_Count bucket_count order_by ->
_illegal_if (bucket_count==0) "bucket_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
AddGroupNumber.numberGroupsEqualCount table.row_count bucket_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 <|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ make_grouping_method_selector table:Table display:Display=..Always -> Widget =
columns_selector = Vector_Editor item_editor=column_selector item_default=table.column_names.first.pretty display=display

unique = Option "Unique" "..Unique" [["on", columns_selector]]
equal_count = Option "Equal Count" "..Equal_Count" [["order_by", columns_selector]]
equal_count = Option "Equal Count" "..Equal_Bucket_Count" [["order_by", columns_selector]]
names=[unique, equal_count]

Single_Choice display=display values=names
Expand Down
4 changes: 2 additions & 2 deletions distribution/lib/Standard/Table/0.0.0-dev/src/Table.enso
Original file line number Diff line number Diff line change
Expand Up @@ -2342,7 +2342,7 @@ type Table

The following grouping methods are supported:
- `Unique`: Group rows by the specified columns.
- Equal_Count: Create the specified number of groups with the same
- Equal_Bucket_Count: Create the specified number of groups with the same
number of rows in each group (except possibly the last one).

? Ordering of rows
Expand Down Expand Up @@ -2399,7 +2399,7 @@ type Table
4 | 2
5 | 1
table = table_builder [['x', [1, 2, 3, 4, 5]], ['y', [5, 4, 3, 2, 1]]]
table2 = tabble.add_group_number (..Equal_Count 3) "g"
table2 = tabble.add_group_number (..Equal_Bucket_Count 3) "g"
table2.at 'g' . to_vector
# => [0, 0, 1, 1, 2]
## table2:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ add_specs suite_builder setup =
group_builder.specify "add_group_number should report unsupported" <|
table_builder = setup.light_table_builder
t = table_builder [['x', [1, 2, 3, 4, 5]], ['y', [5, 4, 3, 2, 1]], ['z', [1, 5, 4, 2, 3]]]
t.add_group_number (..Equal_Count 3) "g" . should_fail_with (Unsupported_Database_Operation.Error "add_group_number")
t.add_group_number (..Equal_Bucket_Count 3) "g" . should_fail_with (Unsupported_Database_Operation.Error "add_group_number")

add_group_number_specs suite_builder setup =
prefix = setup.prefix
Expand All @@ -50,28 +50,28 @@ add_group_number_specs suite_builder setup =
group_builder.specify "should add group number by equal counts" <|
t = table_builder [['x', [1, 2, 3, 4, 5]], ['y', [5, 4, 3, 2, 1]], ['z', [1, 5, 4, 2, 3]]]

g0 = t.add_group_number (..Equal_Count 3) "g"
g0 = t.add_group_number (..Equal_Bucket_Count 3) "g"
g0.at 'g' . to_vector . should_equal [0, 0, 1, 1, 2]

g1 = t.add_group_number (..Equal_Count 3 order_by=['x']) "g"
g1 = t.add_group_number (..Equal_Bucket_Count 3 order_by=['x']) "g"
g1.at 'g' . to_vector . should_equal [0, 0, 1, 1, 2]

g2 = t.add_group_number (..Equal_Count 3 order_by=['y']) "g"
g2 = t.add_group_number (..Equal_Bucket_Count 3 order_by=['y']) "g"
g2.at 'g' . to_vector . should_equal [2, 1, 1, 0, 0]

g3 = t.add_group_number (..Equal_Count 3 order_by='z') "g"
g3 = t.add_group_number (..Equal_Bucket_Count 3 order_by='z') "g"
g3.at 'g' . to_vector . should_equal [0, 2, 1, 0, 1]

g4 = t.add_group_number (..Equal_Count 2) "g"
g4 = t.add_group_number (..Equal_Bucket_Count 2) "g"
g4.at 'g' . to_vector . should_equal [0, 0, 0, 1, 1]

g5 = t.add_group_number (..Equal_Count 2 order_by=['x']) "g"
g5 = t.add_group_number (..Equal_Bucket_Count 2 order_by=['x']) "g"
g5.at 'g' . to_vector . should_equal [0, 0, 0, 1, 1]

g6 = t.add_group_number (..Equal_Count 2 order_by=['y']) "g"
g6 = t.add_group_number (..Equal_Bucket_Count 2 order_by=['y']) "g"
g6.at 'g' . to_vector . should_equal [1, 1, 0, 0, 0]

g7 = t.add_group_number (..Equal_Count 2 order_by='z') "g"
g7 = t.add_group_number (..Equal_Bucket_Count 2 order_by='z') "g"
g7.at 'g' . to_vector . should_equal [0, 1, 1, 0, 0]

group_builder.specify "should add group number by unique values" <|
Expand All @@ -89,7 +89,7 @@ add_group_number_specs suite_builder setup =
group_builder.specify "should add group number by equal counts, with from and step" <|
t = table_builder [['x', [1, 2, 3, 4, 5]], ['y', [5, 4, 3, 2, 1]], ['z', [1, 5, 4, 2, 3]]]

g0 = t.add_group_number (..Equal_Count 3) "g" from=10 step=3
g0 = t.add_group_number (..Equal_Bucket_Count 3) "g" from=10 step=3
g0.at 'g' . to_vector . should_equal [10, 10, 13, 13, 16]

group_builder.specify "must specify group_by with Unique" <|
Expand All @@ -110,7 +110,7 @@ add_group_number_specs suite_builder setup =
group_builder.specify "should fail if columns provided in order_by do not exist" <|
t = table_builder [['x', [1, 2, 3, 4, 5]], ['y', [5, 4, 3, 2, 1]], ['z', [1, 5, 4, 2, 3]]]

t.add_group_number (..Equal_Count 3 order_by=['q']) "g" . should_fail_with Missing_Input_Columns
t.add_group_number (..Equal_Bucket_Count 3 order_by=['q']) "g" . should_fail_with Missing_Input_Columns

group_builder.specify "will fail if the row number exceeds Long range" <|
max_long = Java_Long.MAX_VALUE
Expand Down

0 comments on commit 7ada84c

Please sign in to comment.