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
[FLINK-10229] [sql-client] Support listing of views #6631
Conversation
@walterddr and @hequn8128 Can you help me to review this PR? thanks. |
@yanghua Thanks for your PR. I will take a look this weekend. :-) |
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.
@yanghua I left some suggestions, please take a look. Suggestions mainly include:
- Correct documents about
SHOW VIEWS
. - Sort view names in alphabetical order.
- Add list views in
Executor
and refactor test cases.
Best, Hequn
docs/dev/table/sqlClient.md
Outdated
@@ -503,6 +503,12 @@ Views created within a CLI session can also be removed again using the `DROP VIE | |||
DROP VIEW MyNewView | |||
{% endhighlight %} | |||
|
|||
Views created within a CLI session can also be shown again using the `SHOW VIEWS` statement: |
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.
Views created in a session environment file can also be listed, so change the description to:
Displays all of the views in the current session using the `SHOW VIEWS` statement:
@@ -332,6 +336,17 @@ private void callShowTables() { | |||
terminal.flush(); | |||
} | |||
|
|||
private void callShowViews() { | |||
final Set<String> views = context.getViews().keySet(); |
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.
Get views from Executor
like listTables
so that to provide listViews for external systems and gateway mode.
if (views.isEmpty()) { | ||
terminal.writer().println(CliStrings.messageInfo(CliStrings.MESSAGE_EMPTY).toAnsi()); | ||
} else { | ||
views.forEach((v) -> terminal.writer().println(v)); |
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.
|
||
executor.validateSession(session); | ||
|
||
assertEquals(session.getViews().size(), 0); |
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.
Use executor to test list views(similar to testListTables
and testListUserDefinedFunctions
). There are 2 views in the default environment. Executor will merge environments.
@hequn8128 thanks for your suggestion, I have refactored this PR, can you review it again? |
@twalthr Would you like to review this PR? thanks~ |
@@ -587,6 +587,18 @@ abstract class TableEnvironment(val config: TableConfig) { | |||
rootSchema.getTableNames.asScala.toArray | |||
} | |||
|
|||
def listViews(): Array[String] = { |
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.
I think we can't add this function in TableEnvironment
. Reasons are:
table.isInstanceOf[RelTable]
is not necessary a View.RelTable
can be registered throughregisterTable()
.TableEnvironment
currently doesn't support view. It is only supported in SQL-Client now.
As a choice, you can list views directly from the session
passed to the listViews()
. Also pay attention to the order.
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 you mean that I use the original implementation directly, just move it to the Executor
? I used to get from the session, I misunderstood what you mean, I thought it was to refer to the implementation of the listTable
method.
|
||
final List<String> actualViews = executor.listViews(session); | ||
|
||
final List<String> expectedViews = Arrays.asList( |
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.
Add some other views and test the order.
@hequn8128 What about this change? |
Hi @yanghua , thanks for your update. The PR looks good. +1 to merge from my side. |
hi @twalthr , hequn helped me to review this PR, does it look good to you? |
hi @fhueske can you review this PR? Thanks. |
hi @twalthr , hequn has reviewed this PR, can you make a deterministic review? |
@yanghua Sorry, for the delay. I will take a look at it soon. I want to think about our general design for views before. |
f878230
to
5d9ba4d
Compare
Have fixed some conflicts and rebased this PR. It has stayed for more than half a year, hope for reviewing. cc @twalthr |
leaving... |
What is the purpose of the change
This pull request support listing of views
Brief change log
SHOW VIEWS
Verifying this change
This change added tests and can be verified as follows:
Does this pull request potentially affect one of the following parts:
@Public(Evolving)
: (yes / no)Documentation