Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Table.replace for the in-memory backend #8935

Merged
merged 36 commits into from
Feb 6, 2024

Conversation

GregoryTravis
Copy link
Contributor

@GregoryTravis GregoryTravis commented Feb 1, 2024

Checklist

Please ensure that the following checklist has been satisfied before submitting the PR:

  • The documentation has been updated, if necessary.
  • Screenshots/screencasts have been attached, if there are any visual changes. For interactive or animated visual changes, a screencast is preferred.
  • All code follows the
    Scala,
    Java,
    and
    Rust
    style guides. In case you are using a language not listed above, follow the Rust style guide.
  • All code has been tested:
    • Unit tests have been written where possible.
    • If GUI codebase was changed, the GUI was tested when built using ./run ide build.

@GregoryTravis GregoryTravis marked this pull request as ready for review February 1, 2024 20:00
Comment on lines +89 to +93
group_builder.specify "(edge-case) should allow lookup with itself" <|
table = table_builder [['x', [2, 1, 4, 3]], ['y', [20, 10, 40, 30]]]
expected = table_builder [['x', [20, 10, 40, 30]], ['y', [20, 10, 40, 30]]]
result = table.replace table 'x'
result . should_equal expected
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got that from Lookup_Spec.enso 😀

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:D

Copy link
Member

@radeusgd radeusgd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but some comments.

IMO we should not be using Table.new internally too much - there are more 'specialized' operations for these things. Using them will make writing the DB version later on much easier (as in DB we cannot easily Table.new, but we can still set/select_columns/rename_columns/remove_columns easily.


## Create a lookup table with just `to_column` and `from_column`,
renamed to match the base table's `column` and its duplicate,
respectively.
lookup_table_renamed = Table.new [lookup_table.at from_column . rename duplicate_key_column_name, lookup_table.at to_column . rename column]
lookup_table_renamed = lookup_table.select_columns [from_column, to_column] . rename_columns (Map.from_vector [[from_column, duplicate_key_column_name], [to_column, column]])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw. you are doing this select twice... once here and once above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -2045,19 +2045,18 @@ type Table
self.select_columns column . if_not_error <| lookup_table.select_columns [from_column, to_column] . if_not_error <|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do this:

Suggested change
self.select_columns column . if_not_error <| lookup_table.select_columns [from_column, to_column] . if_not_error <|
selected_lookup_columns = lookup_table.select_columns [from_column, to_column]
self.select_columns column . if_not_error <| selected_lookup_columns . if_not_error <|

then you can use selected_lookup_columns instead of running the select twice for no need.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Member

@radeusgd radeusgd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing most of the issues.

Please consider doing the suggested change to avoid calling select_columns twice unnecessarily (the cost is negligible but it's just not clean to call it twice without need) before merging.

I think ideally it would be good to add the check you suggested - if to_column or from_column has any value other than its default and a Map is provided - that should be an error since the argument should be ignored.

Copy link
Member

@jdunkerley jdunkerley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be good to use Table.from (that:Map) otherwise looks great.

@column Widget_Helpers.make_column_name_selector
@from_column Widget_Helpers.make_column_name_selector
@to_column Widget_Helpers.make_column_name_selector
replace : Table | Map -> (Text | Integer) -> (Text | Integer | Nothing) -> (Text | Integer | Nothing) -> Boolean -> Problem_Behavior -> Table ! Missing_Input_Columns | Non_Unique_Key | Unmatched_Rows_In_Lookup
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add support for to Table from a Map.
image

Then we can take a Table and use conversions.

We can then use 0 for the from_column and 1 for to_column.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've enough changes in part 2 (Database Table.replace) that I'd like to change to conversion style after that's done.

#8984

Comment on lines +2046 to +2047
from_column_resolved = from_column.if_nothing 0
to_column_resolved = to_column.if_nothing 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we use a Map conversion we can avoid needing this.

Comment on lines +2810 to +2816
## PRIVATE
A helper that creates a two-column table from a map.
map_to_lookup_table : Map Any Any -> Text -> Text -> Table
map_to_lookup_table map key_column value_column =
keys_and_values = map.to_vector
Table.new [[key_column, keys_and_values.map .first], [value_column, keys_and_values.map .second]]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can avoid this if we do the conversion approach.

@GregoryTravis GregoryTravis added the CI: Ready to merge This PR is eligible for automatic merge label Feb 6, 2024
@GregoryTravis GregoryTravis changed the title Implement Table.replace for the in-memory backend. Implement Table.replace for the in-memory backend Feb 6, 2024
@mergify mergify bot merged commit 6554972 into develop Feb 6, 2024
25 of 26 checks passed
@mergify mergify bot deleted the wip/gmt/8578-Table.replace branch February 6, 2024 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: Ready to merge This PR is eligible for automatic merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants