{"record":{"id":"aa3eea1035a3153e","repo":"apache/beam","slug":"unable-to-create-table","errorCode":null,"errorMessage":"Unable to create table.","messagePattern":"Unable to create table\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/snowflake/src/main/java/org/apache/beam/sdk/io/snowflake/services/SnowflakeBatchServiceImpl.java","lineNumber":248,"sourceCode":"      String schema,\n      String table,\n      SnowflakeTableSchema tableSchema)\n      throws SQLException {\n    String query =\n        String.format(\n            \"SELECT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_catalog = '%s' AND table_schema = '%s' AND table_name = '%s');\",\n            database.toUpperCase(), schema.toUpperCase(), table.toUpperCase());\n\n    runConnectionWithStatement(\n        dataSource,\n        query,\n        resultSet -> {\n          assert resultSet != null;\n          if (!checkResultIfTableExists(resultSet)) {\n            try {\n              createTable(dataSource, table, tableSchema);\n            } catch (SQLException e) {\n              throw new RuntimeException(\"Unable to create table.\", e);\n            }\n          }\n        });\n  }\n\n  private static boolean checkResultIfTableExists(ResultSet resultSet) {\n    try {\n      if (resultSet.next()) {\n        return checkIfResultIsTrue(resultSet);\n      } else {\n        throw new RuntimeException(\"Unable run pipeline with CREATE IF NEEDED - no response.\");\n      }\n    } catch (SQLException e) {\n      throw new RuntimeException(\"Unable run pipeline with CREATE IF NEEDED disposition.\", e);\n    }\n  }\n\n  private void createTable(DataSource dataSource, String table, SnowflakeTableSchema tableSchema)","sourceCodeStart":230,"sourceCodeEnd":266,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/snowflake/src/main/java/org/apache/beam/sdk/io/snowflake/services/SnowflakeBatchServiceImpl.java#L230-L266","documentation":"SnowflakeBatchServiceImpl's createTableIfNotExists found the table missing (checkResultIfTableExists returned false) and attempted CREATE TABLE, but the CREATE statement threw a SQLException. The RuntimeException wraps that driver error.","triggerScenarios":"createDisposition=CREATE_IF_NEEDED with a tableSchema, the table does not exist, and Snowflake rejects the CREATE TABLE statement — syntax generated from SnowflakeTableSchema, insufficient privileges, or connection failure.","commonSituations":"Role lacks CREATE TABLE privilege on the schema; malformed SnowflakeTableSchema entries (bad column types); schema/database names wrong or not in the search path.","solutions":["Read the wrapped SQLException cause for Snowflake's exact error message/code.","Grant CREATE TABLE on the target schema to the connecting role: GRANT CREATE TABLE ON SCHEMA <db>.<schema> TO ROLE <role>.","Verify every column name/type in your SnowflakeTableSchema is valid Snowflake DDL.","Confirm the database/schema in the SnowflakeServiceConfig exists and the session is using it."],"exampleFix":"// before\nnew SnowflakeTableSchema().addVarCharColumn(\"ts\").addIntColumn(\"count\") // ok\n// after (fix privilege, then rerun)\n// GRANT CREATE TABLE ON SCHEMA mydb.public TO ROLE beam_role;","handlingStrategy":"try-catch","validationCode":"// Grant check before run\n// SHOW GRANTS ON SCHEMA <db>.<schema>; -- confirm CREATE TABLE privilege for your role","typeGuard":null,"tryCatchPattern":"try { pipeline.run(); }\ncatch (RuntimeException e) {\n  if (\"Unable to create table.\".equals(e.getMessage())) {\n    java.sql.SQLException cause = (java.sql.SQLException) e.getCause(); // log Snowflake error code/message\n  }\n}","preventionTips":["Verify SnowflakeTableSchema column types against supported Snowflake DDL types.","Ensure the connecting role has CREATE TABLE on the target schema.","Test the generated CREATE TABLE statement manually in Snowflake first."],"tags":["snowflake","ddl","database","permissions"],"backgroundTag":"database-write-failed","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}