-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-45807][SQL] Add createOrReplaceView(..) / replaceView(..) to ViewCatalog #43677
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -140,6 +140,92 @@ View createView( | |
| String[] columnComments, | ||
| Map<String, String> properties) throws ViewAlreadyExistsException, NoSuchNamespaceException; | ||
|
|
||
| /** | ||
| * Replace a view in the catalog. | ||
| * <p> | ||
| * The default implementation has a race condition. | ||
| * Catalogs are encouraged to implement this operation atomically. | ||
| * | ||
| * @param ident a view identifier | ||
| * @param sql the SQL text that defines the view | ||
| * @param currentCatalog the current catalog | ||
| * @param currentNamespace the current namespace | ||
| * @param schema the view query output schema | ||
| * @param queryColumnNames the query column names | ||
| * @param columnAliases the column aliases | ||
| * @param columnComments the column comments | ||
| * @param properties the view properties | ||
| * @throws NoSuchViewException If the view doesn't exist or is a table | ||
| * @throws NoSuchNamespaceException If the identifier namespace does not exist (optional) | ||
| */ | ||
| default void replaceView( | ||
| Identifier ident, | ||
| String sql, | ||
| String currentCatalog, | ||
| String[] currentNamespace, | ||
| StructType schema, | ||
| String[] queryColumnNames, | ||
| String[] columnAliases, | ||
| String[] columnComments, | ||
| Map<String, String> properties) throws NoSuchViewException, NoSuchNamespaceException { | ||
| if (viewExists(ident)) { | ||
| dropView(ident); | ||
| try { | ||
| createView(ident, sql, currentCatalog, currentNamespace, schema, | ||
| queryColumnNames, columnAliases, columnComments, properties); | ||
| } | ||
| catch (ViewAlreadyExistsException e) { | ||
| throw new RuntimeException("Race condition when dropping and creating view", e); | ||
| } | ||
| } else { | ||
| throw new NoSuchViewException(ident); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Create or replace a view in the catalog. | ||
| * <p> | ||
| * The default implementation has race conditions. | ||
| * Catalogs are encouraged to implement this operation atomically. | ||
| * | ||
| * @param ident a view identifier | ||
| * @param sql the SQL text that defines the view | ||
| * @param currentCatalog the current catalog | ||
| * @param currentNamespace the current namespace | ||
| * @param schema the view query output schema | ||
| * @param queryColumnNames the query column names | ||
| * @param columnAliases the column aliases | ||
| * @param columnComments the column comments | ||
| * @param properties the view properties | ||
| * @throws NoSuchNamespaceException If the identifier namespace does not exist (optional) | ||
| */ | ||
| default void createOrReplaceView( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 3 APIs might be too much. How about we follow the create/replace table logical plan? We have a So we can have just two methods here
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks for the feedback @cloud-fan. I'll follow up with your suggestions and will ping you for a review
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cloud-fan I have made the suggested improvements in #44330 but I'm not sure about having
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense. A simpler API is better. The caller side (Spark) can just ignore the error if |
||
| Identifier ident, | ||
| String sql, | ||
| String currentCatalog, | ||
| String[] currentNamespace, | ||
| StructType schema, | ||
| String[] queryColumnNames, | ||
| String[] columnAliases, | ||
| String[] columnComments, | ||
| Map<String, String> properties) throws NoSuchNamespaceException { | ||
| if (viewExists(ident)) { | ||
| try { | ||
| replaceView(ident, sql, currentCatalog, currentNamespace, schema, | ||
| queryColumnNames, columnAliases, columnComments, properties); | ||
| } catch (NoSuchViewException e) { | ||
| throw new RuntimeException("Race condition when checking and replacing view", e); | ||
| } | ||
| } else { | ||
| try { | ||
| createView(ident, sql, currentCatalog, currentNamespace, schema, | ||
| queryColumnNames, columnAliases, columnComments, properties); | ||
| } catch (ViewAlreadyExistsException e) { | ||
| throw new RuntimeException("Race condition when checking and creating view", e); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Apply {@link ViewChange changes} to a view in the catalog. | ||
| * <p> | ||
|
|
||
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.
shall we have a class
ViewInfoto wrap these fields? It looks verbose to make so many parameters in 3 methods.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.
Agree, it is verbose.