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

Add TableDefinition column name helpers #4813

Merged

Conversation

devinrsmith
Copy link
Member

@devinrsmith devinrsmith commented Nov 10, 2023

Adds some helper methods for on TableDefinition#checkHasColumn, TableDefinition#checkHasColumns, and TableDefinition#getColumnNameSet.

Additionally, fixes up call sites that were (ab)using Table#getColumnSourceMap to simply get the keySet. This invokes a potentially extraneous Table#coalesce which can be avoided in these cases.

In support of common scaffolding so #4771 won't need to call Table#getColumnSource for validation purposes.

This is a potentially useful built-in, along with TableDefinition#getColumnNameSet.

As part of this change, NoSuchColumnException was moved to table-api.

The win here is that BaseTable#checkAvailableColumns no longer coalesces, and BaseTable and HierarchicalTableImpls are straightforward without duplicated logic.
@devinrsmith devinrsmith added this to the November 2023 milestone Nov 10, 2023
@devinrsmith devinrsmith self-assigned this Nov 10, 2023
@devinrsmith devinrsmith marked this pull request as ready for review November 11, 2023 00:47
@@ -818,7 +818,7 @@ public void testAggAllByWithFormatColumn() {
assertEquals(2.0, cs.get(0));

result = dataTable.formatColumns("Doubles=Decimal(`##0.00%`)").headBy(1);
Set<String> columnNames = result.getColumnSourceMap().keySet();
List<String> columnNames = result.getDefinition().getColumnNames();
Copy link
Member

Choose a reason for hiding this comment

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

Why not use your new set method?

Copy link
Member Author

Choose a reason for hiding this comment

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

test impl only checks size and iterates through it - no need for Set afaict.

Copy link
Member

Choose a reason for hiding this comment

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

Sure. Just a question of an on-demand allocation vs. a cached one.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, I see the "concern"; this brings up the larger question of do we want / need to document the APIs in terms of whether they are cached or not / implementation details? I don't necessarily want to box us into defining TableDefinition#getColumnNames() as on-demand, TableDefinition#getColumnNamesSet as cached.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not unreasonable IMO that we could make the case that TableDefinition impl should go from

    private final List<ColumnDefinition<?>> columns;
    private Map<String, ColumnDefinition<?>> columnNameMap;

to

    private final Map<String, ColumnDefinition<?>> columnNameMap;

. Majority of work is probably auditing usage of io.deephaven.engine.table.TableDefinition#getColumns() to see who actually needs a List vs a Collection (which could be achieved efficiently by columnNameMap.values()).

Copy link
Member

Choose a reason for hiding this comment

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

I suspect you're right that the vast majority of the time an ordered collection is sufficient. No need to scope creep this PR for that.

@devinrsmith devinrsmith enabled auto-merge (squash) November 14, 2023 18:55
@devinrsmith devinrsmith merged commit e60cb54 into deephaven:main Nov 15, 2023
10 checks passed
@devinrsmith devinrsmith deleted the nightly/table-definition-columns branch November 15, 2023 14:47
@github-actions github-actions bot locked and limited conversation to collaborators Nov 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants