{"record":{"id":"dc23908a04edc186","repo":"apache/beam","slug":"either-write-statement-or-table-must-be-set","errorCode":null,"errorMessage":"Either Write Statement or Table must be set.","messagePattern":"Either Write Statement or Table must be set\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/jdbc/src/main/java/org/apache/beam/sdk/io/jdbc/JdbcWriteSchemaTransformProvider.java","lineNumber":420,"sourceCode":"        throw new IllegalArgumentException(\n            \"One of JDBC Driver class name or JDBC type must be specified.\");\n      }\n      if (jdbcTypePresent\n          && !JDBC_DRIVER_MAP.containsKey(Objects.requireNonNull(jdbcType).toLowerCase())) {\n        throw new IllegalArgumentException(\n            \"JDBC type must be one of \" + JDBC_DRIVER_MAP.keySet() + \" but was \" + jdbcType);\n      }\n\n      boolean writeStatementPresent =\n          (getWriteStatement() != null && !\"\".equals(getWriteStatement()));\n      boolean locationPresent = (getLocation() != null && !\"\".equals(getLocation()));\n\n      if (writeStatementPresent && locationPresent) {\n        throw new IllegalArgumentException(\n            \"Write Statement and Table are mutually exclusive configurations\");\n      }\n      if (!writeStatementPresent && !locationPresent) {\n        throw new IllegalArgumentException(\"Either Write Statement or Table must be set.\");\n      }\n    }\n\n    public static Builder builder() {\n      return new AutoValue_JdbcWriteSchemaTransformProvider_JdbcWriteSchemaTransformConfiguration\n          .Builder();\n    }\n\n    public abstract Builder toBuilder();\n\n    @AutoValue.Builder\n    public abstract static class Builder {\n      public abstract Builder setDriverClassName(String value);\n\n      public abstract Builder setJdbcType(String value);\n\n      public abstract Builder setJdbcUrl(String value);\n","sourceCodeStart":402,"sourceCodeEnd":438,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/jdbc/src/main/java/org/apache/beam/sdk/io/jdbc/JdbcWriteSchemaTransformProvider.java#L402-L438","documentation":"The inverse of the mutual-exclusion check: the provider requires at least one write target. If neither a write statement nor a table location is set, validate() throws this IllegalArgumentException because it has nothing to write to.","triggerScenarios":"Building JdbcWriteSchemaTransformConfiguration with jdbcUrl/driver info only and calling validate() — no setWriteStatement and no setLocation.","commonSituations":"Incomplete config assembly where the target table is derived from a variable that was empty; template configs where the table placeholder never got substituted.","solutions":["Set setLocation(\"table_name\") for a straightforward table write","Or set setWriteStatement(\"INSERT INTO ... VALUES(?)\") for custom SQL","If the target comes from parameters, validate it is non-empty before building the config"],"exampleFix":"// before\nbuilder().setJdbcUrl(url).setJdbcType(\"postgres\").build();\n// after\nbuilder().setJdbcUrl(url).setJdbcType(\"postgres\").setLocation(\"my_table\").build();","handlingStrategy":"validation","validationCode":"boolean stmt = cfg.getWriteStatement() != null && !cfg.getWriteStatement().isEmpty();\nboolean loc = cfg.getLocation() != null && !cfg.getLocation().isEmpty();\nif (!stmt && !loc) {\n  throw new IllegalArgumentException(\"Set writeStatement or location (table)\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  config.validate();\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().contains(\"Either Write Statement or Table must be set\")) {\n    LOG.error(\"Configure a write target: table (location) or custom write statement\");\n  }\n  throw e;\n}","preventionTips":["Always set location(table) as the default write target","Check that templated table names actually substituted (no empty strings)","Validate the config right after construction"],"tags":["jdbc","beam","config","validation"],"backgroundTag":"missing-required-config-field","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"}