laserninja commented on code in PR #10757:
URL: https://github.com/apache/gravitino/pull/10757#discussion_r3228511964


##########
trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/GravitinoMetadata.java:
##########
@@ -230,12 +230,19 @@ public ConnectorOutputTableHandle beginCreateTable(
       ConnectorTableMetadata tableMetadata,
       Optional<ConnectorTableLayout> layout,
       RetryMode retryMode,
-      boolean noExistingData) {
-    // First, create the table in the Gravitino catalog
+      boolean replace) {
+    SchemaTableName tableName = tableMetadata.getTable();
+
+    // CREATE OR REPLACE TABLE AS SELECT: drop the existing table first if 
present.
+    if (replace
+        && catalogConnectorMetadata.tableExists(
+            tableName.getSchemaName(), tableName.getTableName())) {
+      catalogConnectorMetadata.dropTable(tableName);

Review Comment:
   Thanks for catching this. Added an explicit `CREATE OR REPLACE TABLE AS 
SELECT` scenario to the Iceberg CTAS integration test in 662241502 
(`trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/lakehouse-iceberg/00013_ctas.sql`,
 Test 6). It creates a table, runs `CREATE OR REPLACE TABLE ... AS SELECT` 
against the existing table with a different column set and row count, and 
asserts the post-replace `SELECT` reflects the new schema/data — exercising the 
`replace && tableExists` drop+recreate branch in 
`GravitinoMetadata#beginCreateTable`.



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