JingsongLi commented on code in PR #8208:
URL: https://github.com/apache/paimon/pull/8208#discussion_r3457748264


##########
paimon-core/src/main/java/org/apache/paimon/jdbc/JdbcCatalog.java:
##########
@@ -646,4 +800,287 @@ private <R> List<R> fetch(RowProducer<R> toRow, String 
sql, String... args) {
             throw new RuntimeException("Interrupted in SQL query", e);
         }
     }
+
+    // ======================= view methods ===============================
+
+    @Override
+    public View getView(Identifier identifier) throws ViewNotExistException {
+        try {
+            String viewSchemaJson =
+                    JdbcUtils.getViewSchema(
+                            connections,
+                            catalogKey,
+                            identifier.getDatabaseName(),
+                            identifier.getObjectName());
+            if (viewSchemaJson == null) {
+                throw new ViewNotExistException(identifier);
+            }
+
+            ViewSchema viewSchema = JsonSerdeUtil.fromJson(viewSchemaJson, 
ViewSchema.class);
+            return new ViewImpl(
+                    identifier,
+                    viewSchema.fields(),
+                    viewSchema.query(),
+                    viewSchema.dialects(),
+                    viewSchema.comment(),
+                    viewSchema.options());
+        } catch (SQLException | InterruptedException e) {
+            throw new RuntimeException("Failed to get view " + 
identifier.getFullName(), e);
+        }
+    }
+
+    @Override
+    public void createView(Identifier identifier, View view, boolean 
ignoreIfExists)
+            throws ViewAlreadyExistException, DatabaseNotExistException {
+        // Check if database exists
+        try {
+            getDatabase(identifier.getDatabaseName());
+        } catch (DatabaseNotExistException e) {
+            throw e;
+        }
+
+        if (JdbcUtils.tableExists(

Review Comment:
   This check is not atomic with the later insert into `paimon_views`, and 
`createTable` performs the symmetric check against `paimon_views` before 
inserting into `paimon_tables`. Because the two object types live in separate 
JDBC tables with separate primary keys, a concurrent `createTable(db, name)` 
and `createView(db, name)` can both pass their existence checks and then both 
insert successfully, leaving the catalog with a table and a view sharing the 
same identifier. Please protect the whole table/view existence check plus 
metadata insert with the same catalog lock/transaction, or store object names 
behind a shared unique constraint, and add a regression test for concurrent 
table-vs-view creation.



-- 
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]

Reply via email to