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

Implement some way to show the sql used to create a view #2529

Closed
alamb opened this issue May 13, 2022 · 4 comments · Fixed by #2830
Closed

Implement some way to show the sql used to create a view #2529

alamb opened this issue May 13, 2022 · 4 comments · Fixed by #2830
Labels
datafusion Changes in the datafusion crate enhancement New feature or request

Comments

@alamb
Copy link
Contributor

alamb commented May 13, 2022

Is your feature request related to a problem or challenge? Please describe what you are trying to do.

As suggested by @Dandandan on #2279 (comment) it would be very nice to be able to see the original SQL used to define a view.

Apparently postgres uses a function: https://stackoverflow.com/questions/14634322/how-to-see-the-create-view-code-for-a-view-in-postgresql

Mysql uses SHOW CREATE VIEW: https://dev.mysql.com/doc/refman/8.0/en/show-create-view.html

mysql> create view f as select * from foo;
Query OK, 0 rows affected (0.00 sec)

mysql> show create view f;
+------+----------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
| View | Create View                                                                                                                                        | character_set_client | collation_connection |
+------+----------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
| f    | CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `f` AS select `foo`.`bar` AS `bar`,`foo`.`baz` AS `baz` from `foo` | utf8mb4              | utf8mb4_0900_ai_ci   |
+------+----------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
1 row in set (0.00 sec)

Describe the solution you'd like
Store the original SQL and make it accessable via SQL

Describe alternatives you've considered

Additional context

#2279

@alamb alamb added enhancement New feature or request datafusion Changes in the datafusion crate labels May 13, 2022
@alamb alamb mentioned this issue May 13, 2022
@comphead
Copy link
Contributor

@alamb when we talk about view metadata, its supposed we dont have a persistent metadata catalog? Like Hive or similar.

So its expected the view is temporary, like in Spark?

@alamb
Copy link
Contributor Author

alamb commented May 18, 2022

@comphead -- I think the idea is that the View definition is stored in whatever implements TableProvider (aka ViewTable in https://github.com/apache/arrow-datafusion/pull/2279/files). In order to show the original SQL somehow that information would have to be passed out (perhaps via TableProvider or some other trait)

@mrob95
Copy link
Contributor

mrob95 commented Jul 1, 2022

I'll have a go at this

@alamb
Copy link
Contributor Author

alamb commented Jul 1, 2022

Thank you very much @mrob95 -- we have appreciated all your other fine work to date as well!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
datafusion Changes in the datafusion crate enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants