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

Open
wants to merge 24 commits into
base: develop
Choose a base branch
from

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?

@@ -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?

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.

## 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

@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?

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.
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