manisin commented on code in PR #6674:
URL: https://github.com/apache/iceberg/pull/6674#discussion_r1089412845


##########
snowflake/src/main/java/org/apache/iceberg/snowflake/JdbcSnowflakeClient.java:
##########
@@ -203,31 +176,26 @@ public boolean schemaExists(SnowflakeIdentifier schema) {
       return false;
     }
 
-    // Due to current limitations in PreparedStatement parameters for the LIKE 
clause in
-    // SHOW SCHEMAS queries, we'll use a fairly limited allowlist for 
identifier characters,
-    // using wildcards for non-allowed characters, and post-filter for 
matching.
-    final String finalQuery =
-        String.format(
-            "SHOW SCHEMAS LIKE '%s' IN DATABASE IDENTIFIER(?)",
-            sanitizeIdentifierWithWildcardForLikeClause(schema.schemaName()));
+    final String finalQuery = "SHOW TABLES IN SCHEMA IDENTIFIER(?) LIMIT 1";
+
     List<SnowflakeIdentifier> schemas;
     try {
       schemas =
           connectionPool.run(
               conn ->
                   queryHarness.query(
-                      conn, finalQuery, SCHEMA_RESULT_SET_HANDLER, 
schema.databaseName()));
+                      conn, finalQuery, TABLE_RESULT_SET_HANDLER, 
schema.toIdentifierString()));
     } catch (SQLException e) {
+      if (e.getErrorCode() == 2003 && e.getMessage().contains("does not 
exist")) {
+        return false;
+      }
       throw new UncheckedSQLException(e, "Failed to check if schema '%s' 
exists", schema);
     } catch (InterruptedException e) {
       throw new UncheckedInterruptedException(
           e, "Interrupted while checking if schema '%s' exists", schema);
     }
 
-    // Filter to handle the edge case of '_' appearing as a wildcard that 
can't be remapped the way
-    // it can for predicates in SELECT statements.
-    schemas.removeIf(sc -> 
!schema.schemaName().equalsIgnoreCase(sc.schemaName()));
-    return !schemas.isEmpty();
+    return true;

Review Comment:
   It could be possible that the schema exists without any tables being created 
yet.



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