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

Refine single-column Table to act as a Column #12165

Merged
merged 32 commits into from
Feb 4, 2025

Conversation

radeusgd
Copy link
Member

@radeusgd radeusgd commented Jan 28, 2025

Pull Request Description

Important Notes

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,
    TypeScript,
    and
    Rust
    style guides. In case you are using a language not listed above, follow the Rust style guide.
  • Unit tests have been written where possible.
  • If meaningful changes were made to logic or tests affecting Enso Cloud integration in the libraries,
    or the Snowflake database integration, a run of the Extra Tests has been scheduled.
    • If applicable, it is suggested to paste a link to a successful run of the Extra Tests.

@radeusgd radeusgd self-assigned this Jan 28, 2025
@radeusgd radeusgd added the CI: No changelog needed Do not require a changelog entry for this PR. label Jan 28, 2025
@radeusgd radeusgd force-pushed the wip/radeusgd/12137-table-as-single-column branch from 03cd724 to 7be3f68 Compare January 28, 2025 16:29
@radeusgd radeusgd marked this pull request as ready for review January 29, 2025 17:59
Comment on lines -550 to +552
result.catch SQL_Error _->
if result.is_error then
Error.throw (Table_Not_Found.Error name)
result
Copy link
Member Author

Choose a reason for hiding this comment

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

Since #11777 we can simplify the error handling code, let's use it :)

Comment on lines +3932 to +3938
## Converts all table contents to a text value in delimited format.

Arguments:
- format: Allows to customize the delimiter and other settings of the
format. Defaults to tab-separated values.
to_delimited self (format:Delimited_Format = ..Delimited '\t') -> Text =
Delimited_Writer.write_text self format
Copy link
Member Author

Choose a reason for hiding this comment

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

We have agreed that Text.from Table conversion wasn't that useful and so we are turning it into a method on Table instead.

Does that name seem good or any suggestions for a better one?

Copy link
Member

Choose a reason for hiding this comment

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

Matches with to_xml

Comment on lines +3932 to +3938
## Converts all table contents to a text value in delimited format.

Arguments:
- format: Allows to customize the delimiter and other settings of the
format. Defaults to tab-separated values.
to_delimited self (format:Delimited_Format = ..Delimited '\t') -> Text =
Delimited_Writer.write_text self format
Copy link
Member

Choose a reason for hiding this comment

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

Matches with to_xml

refine_table (table : Table) =
if is_single_column table . not then table else
column = table.at 0
# This should be consistent with `Column_Refinements.refine_column` - the code needs to be copied because we need to spell out all the types.
Copy link
Member

Choose a reason for hiding this comment

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

Probably one we need to talk over with Jaroslav to see if we can do anything better longer term.

Value_Type.Time -> (table : Table & Column & Time_Of_Day)
Value_Type.Date_Time True -> (table : Table & Column & Date_Time)
Value_Type.Decimal _ scale ->
is_integer = scale == 0
Copy link
Contributor

Choose a reason for hiding this comment

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

What about scale < 0? It can still be an integer, so would Table & Column & Integer be the right type in that case?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point! I forgot it can be negative.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated in bc718a2

@@ -77,26 +77,26 @@ _merge_input_and_tables (input_table : Table) (tables_for_rows : Vector Read_Man

multiplicated_inputs = duplicate_rows input_table counts
Runtime.assert (unified_data.row_count == multiplicated_inputs.row_count)
Runtime.assert (unified_metadata.is_nothing || (unified_metadata.row_count == unified_data.row_count))
Runtime.assert ((Nothing == unified_metadata) || (unified_metadata.row_count == unified_data.row_count))
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this change needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Due to #12185.

Essentially - unified_metadata is a Table. But if it contains 1 column, it also now is a & Column. And due to #12185 bug, when calling unified_metadata.is_nothing, instead of dispatching to the Any.is_nothing implementation, it dispatches to Column.is_nothing and returns Column instead of Boolean - the assert then crashes as it expects a boolean.

Nothing == x goes around this issue and checks the is this a Nothing value property correctly.

t1 = setup.table_builder [["A", [23]]]
t1.should_be_a DB_Table
(t1:DB_Column).name.should_equal "A"
Test.expect_panic Type_Error (t1:Integer).to_vector
Copy link
Contributor

Choose a reason for hiding this comment

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

I am confused by this test. to_vector is not a method of Integer, so I would expect a method-not-found error here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, it is a typo, thanks for noticing!

Copy link
Member Author

Choose a reason for hiding this comment

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

The test was still succeeding because it t1:Integer is (expectedly) failing with Type_Error. So it never reached the to_vector method call... But it shouldn't have been there, I removed it.

## The internal constructor used to construct a DB_Table instance.

It can perform some additional operations, like refining the type,
so it should always be preferred over calling `DB_Table.Value` directly.
Copy link
Member

Choose a reason for hiding this comment

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

How would I know this without reading this comment? Guess we need some sort of convention for module private constructors similar to what we have for module priavte methods

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, I will add a comment in Value constructor that it should not be used directly.

Copy link
Member Author

Choose a reason for hiding this comment

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

We can also consider changing the name of the constructor from Value to something like Internal_Value or Internals - to make it more apparent that this is some internal thing that should only be used in limited places. What do you think?

Copy link
Member

@AdRiley AdRiley left a comment

Choose a reason for hiding this comment

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

Seeing it in use has led me to a new question. (And I think this is the question that has been in my head all week trying to get out. :))

If the types are hidden then how are they any use? And I think the answer we have been saying is: well they can be cast to the hidden types. And the GUI will cast them to the hidden types. But how will the GUI know it can cast them to the hidden types if they are hidden?

@radeusgd
Copy link
Member Author

radeusgd commented Feb 3, 2025

But how will the GUI know it can cast them to the hidden types if they are hidden?

@AdRiley The idea is that the GUI should be able to 'extract' even the 'hidden' part of the type.

As far as I understand it was supposed to be handled by PR #11583 (and perhaps some followup changes). I think the idea is that the types sent to the IDE include not only the 'visible' but also the 'hidden' part. Now - I think the message currently does not distinguish which part is which - it just sends all the types a value has. Perhaps we will need to expand the protocol to include such a distinction (e.g. if we only wanted to insert the casts for hidden types, as including it for visible ones may be redundant).

@radeusgd radeusgd added the CI: Ready to merge This PR is eligible for automatic merge label Feb 3, 2025
…t because original type should be preferred

Note: a Column may be _converted_ to Table but is not a Column&Table, and conversions are not checked in case-of, so the other direction is not a problem
@mergify mergify bot merged commit 7031afe into develop Feb 4, 2025
41 of 44 checks passed
@mergify mergify bot deleted the wip/radeusgd/12137-table-as-single-column branch February 4, 2025 22:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: No changelog needed Do not require a changelog entry for this PR. CI: Ready to merge This PR is eligible for automatic merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow a Table that has just 1 column to act as Column
4 participants