-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Refactor is*View ViewReaderUtil methods #18570
Conversation
5ef7b79
to
ef9e1e4
Compare
ef9e1e4
to
42bcd40
Compare
(just rebased) |
42bcd40
to
15b8ee1
Compare
@@ -87,7 +87,7 @@ public void createView(ConnectorSession session, SchemaTableName schemaViewName, | |||
|
|||
Optional<io.trino.plugin.hive.metastore.Table> existing = metastore.getTable(schemaViewName.getSchemaName(), schemaViewName.getTableName()); | |||
if (existing.isPresent()) { | |||
if (!replace || !isPrestoView(existing.get())) { |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
@@ -728,7 +729,7 @@ private void doCreateView(ConnectorSession session, SchemaTableName schemaViewNa | |||
{ | |||
Optional<com.amazonaws.services.glue.model.Table> existing = getTableAndCacheMetadata(session, schemaViewName); | |||
if (existing.isPresent()) { | |||
if (!replace || !isPrestoView(getTableParameters(existing.get()))) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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)
c001569
to
790056a
Compare
rebased to resolve logical conflicts |
CI happy. please review. |
@@ -1455,7 +1455,7 @@ public void setTableComment(ConnectorSession session, ConnectorTableHandle table | |||
@Override | |||
public void setViewComment(ConnectorSession session, SchemaTableName viewName, Optional<String> comment) | |||
{ | |||
Table view = getView(viewName); | |||
Table view = getTrinoView(viewName); |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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
@@ -87,7 +87,7 @@ public void createView(ConnectorSession session, SchemaTableName schemaViewName, | |||
|
|||
Optional<io.trino.plugin.hive.metastore.Table> existing = metastore.getTable(schemaViewName.getSchemaName(), schemaViewName.getTableName()); | |||
if (existing.isPresent()) { | |||
if (!replace || !isPrestoView(existing.get())) { |
There was a problem hiding this comment.
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 ?
@@ -728,7 +729,7 @@ private void doCreateView(ConnectorSession session, SchemaTableName schemaViewNa | |||
{ | |||
Optional<com.amazonaws.services.glue.model.Table> existing = getTableAndCacheMetadata(session, schemaViewName); | |||
if (existing.isPresent()) { | |||
if (!replace || !isPrestoView(getTableParameters(existing.get()))) { |
There was a problem hiding this comment.
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 ?
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.
790056a
to
4ea0a43
Compare
will merge if still green |
Map<String, String> parameters = getTableParameters(table); | ||
if (isPrestoView(parameters) && isHiveOrPrestoView(getTableType(table))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isSomeKindOfView?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
( #18570 (comment) )
@@ -73,7 +73,7 @@ protected final String getRefreshedLocation(boolean invalidateCaches) | |||
} | |||
Table table = getTable(); | |||
|
|||
if (isPrestoView(table) && isHiveOrPrestoView(table)) { | |||
if (isTrinoView(table) || isTrinoMaterializedView(table)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isSomeKindOfView?
There was a problem hiding this comment.
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)
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 withisTrinoView
which returnsfalse for materialized views;
isPrestoView
is equivalent ofisTrinoView || isTrinoMaterializedView
,isHiveOrTrinoView
- deprecated, replaced withisSomeKindOfAView
whichstill 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.