{"record":{"id":"0e975e3f8f71cd54","repo":"apache/beam","slug":"unable-run-pipeline-with-empty-disposition","errorCode":null,"errorMessage":"Unable run pipeline with EMPTY disposition.","messagePattern":"Unable run pipeline with EMPTY disposition\\.","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":182,"sourceCode":"      throws SQLException {\n    String selectQuery = String.format(\"SELECT count(*) FROM %s LIMIT 1;\", tablePath);\n    runConnectionWithStatement(\n        dataSource,\n        selectQuery,\n        resultSet -> {\n          assert resultSet != null;\n          checkIfTableIsEmpty(resultSet);\n        });\n  }\n\n  private static void checkIfTableIsEmpty(ResultSet resultSet) {\n    int columnId = 1;\n    try {\n      if (!resultSet.next() || !checkIfTableIsEmpty(resultSet, columnId)) {\n        throw new RuntimeException(\"Table is not empty. Aborting COPY with disposition EMPTY\");\n      }\n    } catch (SQLException e) {\n      throw new RuntimeException(\"Unable run pipeline with EMPTY disposition.\", e);\n    }\n  }\n\n  private static boolean checkIfTableIsEmpty(ResultSet resultSet, int columnId)\n      throws SQLException {\n    int rowCount = resultSet.getInt(columnId);\n    if (rowCount >= 1) {\n      return false;\n    }\n    return true;\n  }\n\n  private void prepareTableAccordingCreateDisposition(\n      DataSource dataSource,\n      String database,\n      String schema,\n      String table,\n      SnowflakeTableSchema tableSchema,","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/snowflake/src/main/java/org/apache/beam/sdk/io/snowflake/services/SnowflakeBatchServiceImpl.java#L164-L200","documentation":"This wraps a SQLException raised while evaluating whether the target table is empty for the EMPTY create-disposition check in SnowflakeBatchServiceImpl. It means the row-count query itself failed (connection problem, bad query/permissions), not that the table is non-empty.","triggerScenarios":"resultSet.next() or the recursive checkIfTableIsEmpty(resultSet, columnId) throws SQLException — e.g. connectivity loss to Snowflake, invalid result metadata, or a closed result set during the EMPTY-disposition preflight.","commonSituations":"Transient Snowflake connection drops; expired credentials or session timeouts mid-check; warehouse suspend/resume races; driver version issues.","solutions":["Inspect the wrapped SQLException cause for the actual Snowflake error (auth, network, SQL).","Retry the pipeline; Snowflake transient connection errors (codes 390100/250001 style) often resolve on retry.","Verify Snowflake credentials, warehouse, and network egress from the worker (VPC/firewall/proxy).","Update the Snowflake JDBC driver to a current version."],"exampleFix":"// before: unguarded pipeline run\npipeline.run();\n// after: retry on transient failures\n// wrap the pipeline execution in a retry loop for transient Snowflake errors\n// and check e.getCause() instanceof java.sql.SQLException for the root cause","handlingStrategy":"retry","validationCode":"// Pre-flight connectivity check\n// try (Connection c = dataSource.getConnection()) { c.createStatement().execute(\"SELECT 1\"); }","typeGuard":null,"tryCatchPattern":"// catch RuntimeException, inspect cause\ntry { pipeline.run().waitUntilFinish(); }\ncatch (RuntimeException e) {\n  if (e.getCause() instanceof java.sql.SQLException sqlEx && isTransient(sqlEx.getErrorCode())) retry();\n  else throw e;\n}","preventionTips":["Keep the Snowflake warehouse active (AUTO_RESUME=true, sufficient auto-suspend window) during pipeline runs.","Use key-pair auth with long-lived credentials to avoid session expiry.","Pin a recent Snowflake JDBC driver version."],"tags":["snowflake","sql","database","jdbc"],"backgroundTag":"sql-query-failed","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}