Skip to content

Refactor is*View ViewReaderUtil methods #18570

Merged
findepi merged 9 commits intomasterfrom
findepi/view-inspection-methods
Aug 11, 2023
Merged

Refactor is*View ViewReaderUtil methods #18570
findepi merged 9 commits intomasterfrom
findepi/view-inspection-methods

Conversation

@findepi
Copy link
Copy Markdown
Member

@findepi findepi commented Aug 7, 2023

A "trino view" and "trino materialized view" need separate handling in
connectors (regardless what philosophical question whether materialized
view is also a view), so let this be expressed on utility function
level.

This changes

  • isTrinoMaterializedView refactor-only change, no behavioral changes,
  • isPrestoView - deprecated, replaced with isTrinoView which returns
    false for materialized views; isPrestoView is equivalent of
    isTrinoView || isTrinoMaterializedView,
  • isHiveOrTrinoView - deprecated, replaced with isSomeKindOfAView which
    still returns true for materialized views (but returns false for
    Hive's own materialzied view which is treated as an ordinary table by
    Trino),
  • isHiveView - new method.

@findepi findepi added the no-release-notes This pull request does not require release notes entry label Aug 7, 2023
@cla-bot cla-bot bot added the cla-signed label Aug 7, 2023
@findepi findepi force-pushed the findepi/view-inspection-methods branch from 5ef7b79 to ef9e1e4 Compare August 7, 2023 16:44
@github-actions github-actions bot added tests:hive iceberg Iceberg connector delta-lake Delta Lake connector hive Hive connector labels Aug 7, 2023
@findepi findepi force-pushed the findepi/view-inspection-methods branch from ef9e1e4 to 42bcd40 Compare August 8, 2023 09:07
@findepi
Copy link
Copy Markdown
Member Author

findepi commented Aug 8, 2023

(just rebased)

@findepi findepi force-pushed the findepi/view-inspection-methods branch from 42bcd40 to 15b8ee1 Compare August 8, 2023 09:55
Copy link
Copy Markdown
Member Author

@findepi findepi Aug 8, 2023

Choose a reason for hiding this comment

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

In theory, the old code could replace an MV with a View (see #15622)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could we add a test to verify it isn't allowed now ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

it would be very hard to write such a test. from linked PR desc

This would have only been possible during a rare race condition since the engine also checks that an existing entity is not a MV before calling on the connector to create or replace the view.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

In theory, the old code could replace an MV with a View.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could we add a test to verify it isn't allowed now ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

same answer here: #18570 (comment)

@findepi findepi force-pushed the findepi/view-inspection-methods branch 2 times, most recently from c001569 to 790056a Compare August 9, 2023 11:31
@findepi
Copy link
Copy Markdown
Member Author

findepi commented Aug 9, 2023

rebased to resolve logical conflicts

@findepi
Copy link
Copy Markdown
Member Author

findepi commented Aug 9, 2023

CI happy. please review.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we have a test verifying that COMMENT ON VIEW doesn't work on an MV ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

idk. note that i am not changing this. toConnectorViewDefinition(...).orElseThrow on next line throws for anything that's not a view

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could we add a test to verify it isn't allowed now ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could we add a test to verify it isn't allowed now ?

@findepi
Copy link
Copy Markdown
Member Author

findepi commented Aug 10, 2023

there are conflicts, will rebase

Just to help review later commits.
The check above excludes everything that does not look like a
Presto/Trino view, so the second check looks redundant.

This also makes one method parameter redundant, removed.
The method is supposed to get a Trino view that's going to be updated.
Its check for `translateHiveViews` was redundant, the calling code is
never supposed to operate on a Hive view, regardless of
`translateHiveViews` flag. (And if it matter, the `translateHiveViews`
condition would probably be negated.) It was probably not user-facing
problem as the calling code is likely unreachable when Hive view
translation is not enabled.

The commit also adds a check that the table object being operated on
does not represent a Trino Materialized View. The previously checked
`isPrestoView` returns true for both, but the table is supposed to
represent ordinary Trino View.
Previously the `isTrinoView` would be true for Trino VIEW or Trino
MATERIALIZED VIEW (since `isPrestoView()` returns true for both). This
wasn't intentional, the code reserved `isTrinoMaterializedView` variable
for MVs.

This didn't had any end-user visible effect because the variables are
currently later OR-ed.
Just for easier review of subsequent commits.
A "trino view" and "trino materialized view" need separate handling in
connectors (regardless what philosophical question whether materialized
view is also a view), so let this be expressed on utility function
level.

This changes

- `isTrinoMaterializedView` refactor-only change, no behavioral changes,
- `isPrestoView` - deprecated, replaced with `isTrinoView` which returns
  false for materialized views; `isPrestoView` is equivalent of
  `isTrinoView || isTrinoMaterializedView`,
- `isHiveOrTrinoView` - deprecated, replaced with `isSomeKindOfAView` which
  still returns true for materialized views (but returns false for
  Hive's own materialzied view which is treated as an ordinary table by
  Trino),
- `isHiveView` - new method.
@findepi findepi force-pushed the findepi/view-inspection-methods branch from 790056a to 4ea0a43 Compare August 10, 2023 12:02
@findepi
Copy link
Copy Markdown
Member Author

findepi commented Aug 10, 2023

will merge if still green


String tableType = getTableType(table);
Map<String, String> parameters = getTableParameters(table);
if (isPrestoView(parameters) && isHiveOrPrestoView(getTableType(table))) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

isSomeKindOfView?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Table table = getTable();

if (isPrestoView(table) && isHiveOrPrestoView(table)) {
if (isTrinoView(table) || isTrinoMaterializedView(table)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

isSomeKindOfView?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

no, we we allow trino V and MV here (and fail on eg Hive views which are not supported by Iceberg -- they are neither tables or views, so something needs to throw on them)

@findepi findepi merged commit 7dea413 into master Aug 11, 2023
@findepi findepi deleted the findepi/view-inspection-methods branch August 11, 2023 07:54
@github-actions github-actions bot added this to the 424 milestone Aug 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed delta-lake Delta Lake connector hive Hive connector iceberg Iceberg connector no-release-notes This pull request does not require release notes entry

Development

Successfully merging this pull request may close these issues.

3 participants