fix create view on exist table throw view exist exception#10186
fix create view on exist table throw view exist exception#10186sopel39 merged 1 commit intotrinodb:masterfrom
Conversation
There was a problem hiding this comment.
IMO we should move this logic to the CreateViewTask and handle it in a similar way e.g. RenameViewTask handles it (including a check for materialized view). It would work then for all connectors (looks like iceberg connector may have the same issue) + would support MVs.
There was a problem hiding this comment.
Yes, I also think it should work for all connectors, so the one that really needs to be enhanced is CreateViewTask. So I will resubmit a pr to make an enhancement to CreateViewTask, can I close this pr now?
There was a problem hiding this comment.
I think it's ok to make changes in this PR (you can squash commits if you need to)
There was a problem hiding this comment.
Ok i will do it in the next few days
There was a problem hiding this comment.
cc @lukasz-stec , I am very confused about the function of ConnectorMetadata#getTableHandle in hive.it should return null when the relation is views (just like the comment says in this function). But if I create a view, it will not return null in hive because of tableActions will add a table when view create
There was a problem hiding this comment.
yeah, hive connector implementation of ConnectorMetadata#getTableHandle breaks the contract. I don't think it's that easy to fix though (some features may depend on this behavior)
There was a problem hiding this comment.
IMO we can first judge whether the view exists according to Metadata#isView, if the view does not exist, then judge whether the table exists, we also need to verify whether this is feasible on other connectors. Do you think we need open other issus about hive connector implementation of ConnectorMetadata#getTableHandle breaks the contract.
There was a problem hiding this comment.
IMO we can first judge whether the view exists according to Metadata#isView
yes + metadata.isMaterializedView to check if its MV
Do you think we need open other issus about hive connector implementation of ConnectorMetadata#getTableHandle breaks the contract.
Good question. There is this ticket #8349 which is a kind of prerequisite for fixing the hive connector but maybe we need another one.
There was a problem hiding this comment.
Hello, @lukasz-stec .Could you review my code again? Thank you!
There was a problem hiding this comment.
the tests above are mostly checking this (mock) logic. If the checks are moved to CreateTableTask (see comment below) this will be unnecessary and you can extend the test class from BaseDataDefinitionTaskTest.
047fc0a to
8f8fb37
Compare
There was a problem hiding this comment.
How about using assertThat(metadata.isView(testSession, viewName)).isTrue(); instead of checcking getCreateViewCallCount?
There was a problem hiding this comment.
I would revert this and use metadata.isView instead
There was a problem hiding this comment.
Yes,it can be revert if we use metadata.isView to check create view
There was a problem hiding this comment.
I think this make break for our case of hive connector returning tableHandle for views when replace=true
There was a problem hiding this comment.
sorry, @lukasz-stec . I don't understand what you mean, , can you elaborate more?
There was a problem hiding this comment.
Sorry, I should say may break...
So because getTableHandle will return not empty TableHandle for a view in hive connector, when statement.isReplace() == true (i.e. CREATE OR REPLACE VIEW was used) the method will trow
throw semanticException(TABLE_ALREADY_EXISTS, statement, "Table '%s' already exists", name); and it should replace the view definition successfuly.
There was a problem hiding this comment.
Thank you for your reminder, I still need to check if it is view when statement.isReplace() == true.Sorry ,can you review again.
a546725 to
478045c
Compare
There was a problem hiding this comment.
Because the view named test_view is add to MockConnectorMetadata by withGetViews in TestEventListenerBasic, so metadata.isViews will always return true and throw a exception
There was a problem hiding this comment.
Because the view named test_view is add to MockConnectorMetadata by withGetViews in TestEventListenerBasic, so metadata.isViews will always return true and throw a exception
Should use use different view name here then?
core/trino-main/src/main/java/io/trino/execution/CreateViewTask.java
Outdated
Show resolved
Hide resolved
c5b4d9c to
7b98bd0
Compare
There was a problem hiding this comment.
Change the order:
- MV
- view
- table
This is the metadata check order that we use in other places. Let's be consistent here
There was a problem hiding this comment.
@sopel39 I had changed the order,can you reviewer again,thank you
There was a problem hiding this comment.
Check isView only after isMaterializedView (see other comment below)
core/trino-main/src/main/java/io/trino/execution/CreateViewTask.java
Outdated
Show resolved
Hide resolved
7b98bd0 to
08d8b09
Compare
plugin/trino-memory/src/test/java/io/trino/plugin/memory/TestMemoryConnectorTest.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Because the view named test_view is add to MockConnectorMetadata by withGetViews in TestEventListenerBasic, so metadata.isViews will always return true and throw a exception
Should use use different view name here then?
50ffb45 to
5e3c356
Compare
core/trino-main/src/test/java/io/trino/execution/TestCreateViewTask.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/test/java/io/trino/execution/TestCreateViewTask.java
Outdated
Show resolved
Hide resolved
plugin/trino-memory/src/test/java/io/trino/plugin/memory/TestMemoryConnectorTest.java
Outdated
Show resolved
Hide resolved
testing/trino-tests/src/test/java/io/trino/execution/TestEventListenerBasic.java
Outdated
Show resolved
Hide resolved
5e3c356 to
5897e63
Compare
|
Fixes #10186 |
|
merged thanks! |
fix hive connector create view on exist table throw view exist exception. #10037
before:
after:
Fixes #10186