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


##########
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(
+                connections,
+                catalogKey,
+                identifier.getDatabaseName(),
+                identifier.getObjectName())) {
+            if (ignoreIfExists) {
+                return;
+            }
+            throw new ViewAlreadyExistException(identifier);
+        }
+
+        // Check if view already exists
+        if (JdbcUtils.viewExists(
+                connections,
+                catalogKey,
+                identifier.getDatabaseName(),
+                identifier.getObjectName())) {
+            if (ignoreIfExists) {
+                return;
+            }
+            throw new ViewAlreadyExistException(identifier);
+        }
+
+        // Serialize view schema to JSON
+        ViewSchema viewSchema =
+                new ViewSchema(
+                        view.rowType().getFields(),
+                        view.query(),
+                        view.dialects(),
+                        view.comment().orElse(null),
+                        view.options());
+        String viewSchemaJson = JsonSerdeUtil.toJson(viewSchema);
+
+        // Insert view
+        try {
+            JdbcUtils.insertView(
+                    connections,
+                    catalogKey,
+                    identifier.getDatabaseName(),
+                    identifier.getObjectName(),
+                    viewSchemaJson);
+        } catch (RuntimeException e) {
+            if (e.getMessage() != null && e.getMessage().contains("View 
already exists")) {
+                throw new ViewAlreadyExistException(identifier, e);
+            }
+            throw new RuntimeException("Failed to create view " + 
identifier.getFullName(), e);
+        }
+    }
+
+    @Override
+    public void dropView(Identifier identifier, boolean ignoreIfNotExists)
+            throws ViewNotExistException {
+        // Check if view exists
+        if (!JdbcUtils.viewExists(
+                connections,
+                catalogKey,
+                identifier.getDatabaseName(),
+                identifier.getObjectName())) {
+            if (ignoreIfNotExists) {
+                return;
+            }
+            throw new ViewNotExistException(identifier);
+        }
+
+        // Delete view
+        int deletedRecords =
+                execute(
+                        connections,
+                        JdbcUtils.DROP_VIEW_SQL,
+                        catalogKey,
+                        identifier.getDatabaseName(),
+                        identifier.getObjectName());
+
+        if (deletedRecords != 1) {
+            throw new RuntimeException(
+                    String.format(
+                            "Failed to drop view %s: affected %d rows",
+                            identifier.getFullName(), deletedRecords));
+        }
+    }
+
+    @Override
+    public List<String> listViews(String databaseName) throws 
DatabaseNotExistException {

Review Comment:
   `listTables` treats the system database as a valid catalog namespace, and 
both HiveCatalog and RESTCatalog return an empty list from 
`listViews(SYSTEM_DATABASE_NAME)`. This implementation goes straight to the 
JDBC metadata tables, so `listViews(Catalog.SYSTEM_DATABASE_NAME)` / the paged 
variants throw `DatabaseNotExistException` instead of returning empty. Please 
add the same system-database fast path here and cover it, since 
`JdbcCatalogTest` currently overrides the inherited system-table test that 
would otherwise catch this inconsistency.



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