Skip to content

Commit

Permalink
Fixes from the live demo. (#7243)
Browse files Browse the repository at this point in the history
- Removed defaults from `cross_tab`. It caused an out-of-heap space error when it attempted to build a 205k x 205k table. Now has a hard limit of 10,000 columns - we can increase this once we have more concrete test data.
![image](https://github.com/enso-org/enso/assets/4699705/bc38d41c-56dc-41bd-8a7c-fa89ecfa7f79)

- Adjusted the dropdowns on `Aggregate_Column` for `columns` and `order_by` to be dropdowns as nested Vector editors are not supported.
![image](https://github.com/enso-org/enso/assets/4699705/f4a7c7cc-6a21-462c-a39e-65fbab82c367)

- Altered `Aggregate_Column` so `new_name` now `new_name:Text=""` and not taking `Nothing` anymore. Makes it appear correctly in IDE.
![image](https://github.com/enso-org/enso/assets/4699705/196a49ba-4274-44bb-b876-0372c8f62746)

- Added dropdowns for `fill_empty`, `fill_nothing` and `replace` on `Table`.
![image](https://github.com/enso-org/enso/assets/4699705/9ee5cec2-82d5-4452-b650-67015ac9fee5)

- Added `replace` to Database table throwing `Unsupport_Database_Operation`.
  • Loading branch information
jdunkerley authored Jul 9, 2023
1 parent 8020916 commit 1fb60df
Show file tree
Hide file tree
Showing 13 changed files with 163 additions and 83 deletions.
56 changes: 47 additions & 9 deletions distribution/lib/Standard/Database/0.0.0-dev/src/Data/Table.enso
Original file line number Diff line number Diff line change
Expand Up @@ -1512,7 +1512,7 @@ type Table
@name_column Widget_Helpers.make_column_name_selector
@values (Widget_Helpers.make_aggregate_column_selector include_group_by=False)
cross_tab : Vector (Integer | Text | Column_Selector | Aggregate_Column) | Text | Integer -> (Text | Integer) -> Aggregate_Column | Vector Aggregate_Column -> Problem_Behavior -> Table ! Missing_Input_Columns | Invalid_Aggregate_Column | Floating_Point_Equality | Invalid_Aggregation | Unquoted_Delimiter | Additional_Warnings
cross_tab self group_by=[] name_column=self.column_names.first values=Aggregate_Column.Count (on_problems=Report_Warning) =
cross_tab self group_by name_column values=Aggregate_Column.Count (on_problems=Report_Warning) =
## Avoid unused arguments warning. We cannot rename arguments to `_`,
because we need to keep the API consistent with the in-memory table.
_ = [group_by, name_column, values, on_problems]
Expand Down Expand Up @@ -1981,8 +1981,7 @@ type Table
been replaced with the provided default(s).

Arguments:
- selectors: Single instance or a Vector of names, indexes or
`Column_Selector`s.
- columns: The column(s) to fill missing values of.
- default: The value to replace missing values with. If this argument
is a column, the value from `default` at the corresponding position
will be used.
Expand All @@ -1991,17 +1990,19 @@ type Table
Fill missing values in two columns with the value 20.5.

fill_nothing = table.fill_nothing ["col0", "col1"] 20.5
fill_nothing : Text | Integer | Column_Selector | Vector (Integer | Text | Column_Selector) -> Column | Any -> Table
fill_nothing self selectors default =
@columns Widget_Helpers.make_column_name_vector_selector
fill_nothing : Vector (Integer | Text | Column_Selector) | Text | Integer -> Column | Any -> Table
fill_nothing self columns default =
transformer col = col.fill_nothing default
Table_Helpers.replace_columns_with_transformed_columns self selectors transformer
Table_Helpers.replace_columns_with_transformed_columns self columns transformer

## ALIAS Fill Empty, if_empty

Returns a new column where empty Text values have been replaced with the
provided default(s).

Arguments:
- columns: The column(s) to fill empty values.
- default: The value to replace empty values with. If this argument
is a column, the value from `default` at the corresponding position
will be used.
Expand All @@ -2010,10 +2011,47 @@ type Table
Fill empty values in two columns with the value "hello".

fill_empty = table.fill_empty ["col0", "col1"] "hello"
fill_empty : Text | Integer | Column_Selector | Vector (Integer | Text | Column_Selector) -> Column | Any -> Table
fill_empty self selectors default =
@columns Widget_Helpers.make_column_name_vector_selector
fill_empty : Vector (Integer | Text | Column_Selector) | Text | Integer -> Column | Any -> Table
fill_empty self columns default =
transformer col = col.fill_empty default
Table_Helpers.replace_columns_with_transformed_columns self selectors transformer
Table_Helpers.replace_columns_with_transformed_columns self columns transformer

## Replaces the first, or all occurrences of `term` with `new_text` in each
row of the specified column. If `term` is empty, the function returns the
table unchanged.

This method follows the exact replacement semantics of the
`Text.replace` method.

Arguments:
- columns: The column(s) to replace values on.
- term: The term to find. Can be `Text`, `Regex`, or a `Column` of
strings.
- replacement: The text to replace matches with.
- case_sensitivity: Specifies if the text values should be compared case
sensitively.
- only_first: If True, only replace the first match.

> Example
Replace dashes with underscores.

table.replace "-" "_"

> Example
Remove leading and trailing spaces from cells.

column.replace "^\s*(.*?)\s*$".to_regex "$1"

> Example
Replace texts in quotes with parentheses.

column.replace '"(.*?)"'.to_regex '($1)'
@columns Widget_Helpers.make_column_name_vector_selector
replace : Vector (Integer | Text | Column_Selector) | Text | Integer -> Text | Column | Regex -> Text | Column -> Case_Sensitivity -> Boolean -> Column
replace self columns term="" new_text="" case_sensitivity=Case_Sensitivity.Sensitive only_first=False =
_ = [columns, term, new_text, case_sensitivity, only_first]
Error.throw (Unsupported_Database_Operation.Error "Text replace is currently not supported in the database backend.")

## PRIVATE

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ type Aggregate_Column
- column: the column (specified by name, expression or index) to group
by.
- new_name: name of new column.
Group_By (column:Text|Integer|Column|Any) (new_name:Text|Nothing=Nothing) # Column needed because of 6866
Group_By (column:Text|Integer|Column|Any) (new_name:Text="") # Column needed because of 6866

## Creates a new column with the row count of each group. If no rows,
evaluates to 0.

Arguments:
- new_name: name of new column.
Count (new_name:Text|Nothing=Nothing)
Count (new_name:Text="")

## Creates a new column with the count of unique items in the selected
column(s) within each group. If no rows, evaluates to 0.
Expand All @@ -32,7 +32,7 @@ type Aggregate_Column
multiple selection.
- new_name: name of new column.
- ignore_nothing: if all values are Nothing won't be included.
Count_Distinct (columns:(Text | Integer | Column_Selector | Vector (Integer | Text | Column_Selector | Column))=0) (new_name:Text|Nothing=Nothing) (ignore_nothing:Boolean=False) # Column needed because of 6866
Count_Distinct (columns:(Text | Integer | Column_Selector | Vector (Integer | Text | Column_Selector | Column))=0) (new_name:Text="") (ignore_nothing:Boolean=False) # Column needed because of 6866

## ALIAS Count_Not_Null

Expand All @@ -42,7 +42,7 @@ type Aggregate_Column
Arguments:
- column: the column (specified by name, expression or index) to count.
- new_name: name of new column.
Count_Not_Nothing (column:Text|Integer|Column|Any=0) (new_name:Text|Nothing=Nothing) # Column needed because of 6866
Count_Not_Nothing (column:Text|Integer|Column|Any=0) (new_name:Text="") # Column needed because of 6866

## ALIAS Count_Null, Count_Missing

Expand All @@ -52,39 +52,39 @@ type Aggregate_Column
Arguments:
- column: the column (specified by name, expression or index) to count.
- new_name: name of new column.
Count_Nothing (column:Text|Integer|Column|Any=0) (new_name:Text|Nothing=Nothing) # Column needed because of 6866
Count_Nothing (column:Text|Integer|Column|Any=0) (new_name:Text="") # Column needed because of 6866

## Creates a new column with the count of not `Nothing` (null) and non-empty
("") values of the column within each group. If no rows, evaluates to 0.

Arguments:
- column: the column (specified by name, expression or index) to count.
- new_name: name of new column.
Count_Not_Empty (column:Text|Integer|Column|Any=0) (new_name:Text|Nothing=Nothing) # Column needed because of 6866
Count_Not_Empty (column:Text|Integer|Column|Any=0) (new_name:Text="") # Column needed because of 6866

## Creates a new column with the count of `Nothing` (null) or empty ("")
text values of the column within each group. If no rows, evaluates to 0.

Arguments:
- column: the column (specified by name, expression or index) to count.
- new_name: name of new column.
Count_Empty (column:Text|Integer|Column|Any=0) (new_name:Text|Nothing=Nothing) # Column needed because of 6866
Count_Empty (column:Text|Integer|Column|Any=0) (new_name:Text="") # Column needed because of 6866

## Creates a new column with the sum of values (ignoring missing values) of
the column within each group. If no rows, evaluates to `Nothing`.

Arguments:
- column: the column (specified by name, expression or index) to total.
- new_name: name of new column.
Sum (column:Text|Integer|Column|Any=0) (new_name:Text|Nothing=Nothing) # Column needed because of 6866
Sum (column:Text|Integer|Column|Any=0) (new_name:Text="") # Column needed because of 6866

## Creates a new column with the mean of values (ignoring missing values) of
the column within each group. If no rows, evaluates to `Nothing`.

Arguments:
- column: the column (specified by name, expression or index) to average.
- new_name: name of new column.
Average (column:Text|Integer|Column|Any=0) (new_name:Text|Nothing=Nothing) # Column needed because of 6866
Average (column:Text|Integer|Column|Any=0) (new_name:Text="") # Column needed because of 6866

## Creates a new column with the median of values (ignoring missing values)
of the column within each group. If no rows, evaluates to `Nothing`.
Expand All @@ -93,7 +93,7 @@ type Aggregate_Column
- column: column (specified by name, expression or index) to calculate
median on.
- new_name: name of new column.
Median (column:Text|Integer|Column|Any=0) (new_name:Text|Nothing=Nothing) # Column needed because of 6866
Median (column:Text|Integer|Column|Any=0) (new_name:Text="") # Column needed because of 6866

## Creates a new column with the median of values (ignoring missing values)
of the column within each group. If no rows, evaluates to `Nothing`.
Expand All @@ -103,7 +103,7 @@ type Aggregate_Column
- column: column (specified by name, expression or index) to compute
percentile.
- new_name: name of new column.
Percentile (percentile:Number=0.5) (column:Text|Integer|Column|Any=0) (new_name:Text|Nothing=Nothing) # Column needed because of 6866
Percentile (percentile:Number=0.5) (column:Text|Integer|Column|Any=0) (new_name:Text="") # Column needed because of 6866

## Creates a new column with the mode of values (ignoring missing values)
of the column within each group. If no rows, evaluates to `Nothing`.
Expand All @@ -112,7 +112,7 @@ type Aggregate_Column
- column: column (specified by name, expression or index) to find the
most common value.
- new_name: name of new column.
Mode (column:Text|Integer|Column|Any=0) (new_name:Text|Nothing=Nothing) # Column needed because of 6866
Mode (column:Text|Integer|Column|Any=0) (new_name:Text="") # Column needed because of 6866

## Creates a new column with the standard deviation of values (ignoring
missing values) of the column within each group. If no rows, evaluates to
Expand All @@ -123,7 +123,7 @@ type Aggregate_Column
standard deviation.
- new_name: name of new column.
- population: specifies if group is a sample or the population
Standard_Deviation (column:Text|Integer|Column|Any=0) (new_name:Text|Nothing=Nothing) (population:Boolean=False) # Column needed because of 6866
Standard_Deviation (column:Text|Integer|Column|Any=0) (new_name:Text="") (population:Boolean=False) # Column needed because of 6866

## Creates a new column with the values concatenated together. `Nothing`
values will become an empty string. If no rows, evaluates to `Nothing`.
Expand All @@ -136,7 +136,7 @@ type Aggregate_Column
- suffix: added at the end of the result.
- quote_char: character used to quote the values if the value is `Empty`
or contains the separator.
Concatenate (column:Text|Integer|Column|Any=0) (new_name:Text|Nothing=Nothing) (separator:Text="") (prefix:Text="") (suffix:Text="") (quote_char:Text="") # Column needed because of 6866
Concatenate (column:Text|Integer|Column|Any=0) (new_name:Text="") (separator:Text="") (prefix:Text="") (suffix:Text="") (quote_char:Text="") # Column needed because of 6866

## Creates a new column with the first value in each group. If no rows,
evaluates to `Nothing`.
Expand All @@ -149,7 +149,7 @@ type Aggregate_Column
not missing value returned.
- order_by: required for database tables. Specifies how to order the
results within the group.
First (column:Text|Integer|Column|Any=0) (new_name:Text|Nothing=Nothing) (ignore_nothing:Boolean=True) (order_by:(Text | Vector (Text | Sort_Column) | Nothing)=Nothing) # Column needed because of 6866
First (column:Text|Integer|Column|Any=0) (new_name:Text="") (ignore_nothing:Boolean=True) (order_by:(Text | Vector (Text | Sort_Column) | Nothing)=Nothing) # Column needed because of 6866

## Creates a new column with the last value in each group. If no rows,
evaluates to `Nothing`.
Expand All @@ -162,7 +162,7 @@ type Aggregate_Column
not missing value returned.
- order_by: required for database tables. Specifies how to order the
results within the group.
Last (column:Text|Integer|Column|Any=0) (new_name:Text|Nothing=Nothing) (ignore_nothing:Boolean=True) (order_by:(Text | Vector (Text | Sort_Column) | Nothing)=Nothing) # Column needed because of 6866
Last (column:Text|Integer|Column|Any=0) (new_name:Text="") (ignore_nothing:Boolean=True) (order_by:(Text | Vector (Text | Sort_Column) | Nothing)=Nothing) # Column needed because of 6866

## Creates a new column with the maximum value in each group. If no rows,
evaluates to `Nothing`.
Expand All @@ -171,7 +171,7 @@ type Aggregate_Column
- column: column (specified by name, expression or index) to find the
group maximum.
- new_name: name of new column.
Maximum (column:Text|Integer|Column|Any=0) (new_name:Text|Nothing=Nothing) # Column needed because of 6866
Maximum (column:Text|Integer|Column|Any=0) (new_name:Text="") # Column needed because of 6866

## Creates a new column with the maximum value in each group. If no rows,
evaluates to `Nothing`.
Expand All @@ -180,7 +180,7 @@ type Aggregate_Column
- column: column (specified by name, expression or index) to find the
group minimum.
- new_name: name of new column.
Minimum (column:Text|Integer|Column|Any=0) (new_name:Text|Nothing=Nothing) # Column needed because of 6866
Minimum (column:Text|Integer|Column|Any=0) (new_name:Text="") # Column needed because of 6866

## Creates a new column with the shortest text in each group. If no rows,
evaluates to `Nothing`.
Expand All @@ -189,7 +189,7 @@ type Aggregate_Column
- column: column (specified by name, expression or index) to find the
group shortest value.
- new_name: name of new column.
Shortest (column:Text|Integer|Column|Any=0) (new_name:Text|Nothing=Nothing) # Column needed because of 6866
Shortest (column:Text|Integer|Column|Any=0) (new_name:Text="") # Column needed because of 6866

## Creates a new column with the longest text in each group. If no rows,
evaluates to `Nothing`.
Expand All @@ -198,4 +198,4 @@ type Aggregate_Column
- column: column (specified by name, expression or index) to find the
group longest value.
- new_name: name of new column.
Longest (column:Text|Integer|Column|Any=0) (new_name:Text|Nothing=Nothing) # Column needed because of 6866
Longest (column:Text|Integer|Column|Any=0) (new_name:Text="") # Column needed because of 6866
Loading

0 comments on commit 1fb60df

Please sign in to comment.