aokolnychyi commented on code in PR #43677:
URL: https://github.com/apache/spark/pull/43677#discussion_r1401440744


##########
sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/ViewCatalog.java:
##########
@@ -140,6 +140,87 @@ 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)) {
+      throw new NoSuchViewException(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);
+    }
+  }
+
+  /**
+   * 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(
+          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)) {

Review Comment:
   Minor: I think it is easier to read conditions that don't have negation. I'd 
flip the branches.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to