{"record":{"id":"5cba9acf30349dc2","repo":"apache/beam","slug":"either-query-or-table-must-be-specified","errorCode":null,"errorMessage":"Either Query or Table must be specified.","messagePattern":"Either Query or Table must be specified\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/jdbc/src/main/java/org/apache/beam/sdk/io/jdbc/JdbcReadSchemaTransformProvider.java","lineNumber":435,"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(\"JDBC type must be one of \" + JDBC_DRIVER_MAP.keySet());\n      }\n\n      boolean readQueryPresent = (getReadQuery() != null && !\"\".equals(getReadQuery()));\n      boolean locationPresent = (getLocation() != null && !\"\".equals(getLocation()));\n      boolean partitionColumnPresent =\n          (getPartitionColumn() != null && !\"\".equals(getPartitionColumn()));\n\n      // If you specify a readQuery, it is to be used instead of a table.\n      if (readQueryPresent && locationPresent) {\n        throw new IllegalArgumentException(\"Query and Table are mutually exclusive configurations\");\n      }\n      if (!readQueryPresent && !locationPresent) {\n        throw new IllegalArgumentException(\"Either Query or Table must be specified.\");\n      }\n      // Reading with partitions only supports table argument.\n      if (partitionColumnPresent && !locationPresent) {\n        throw new IllegalArgumentException(\"Table must be specified to read with partitions.\");\n      }\n    }\n\n    public static Builder builder() {\n      return new AutoValue_JdbcReadSchemaTransformProvider_JdbcReadSchemaTransformConfiguration\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","sourceCodeStart":417,"sourceCodeEnd":453,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/jdbc/src/main/java/org/apache/beam/sdk/io/jdbc/JdbcReadSchemaTransformProvider.java#L417-L453","documentation":"Validation guard in JdbcReadSchemaTransformProvider (and related transforms): a JDBC read requires exactly one source specification — either a read query or a table name. When neither (or both are empty/null) is supplied, validate() throws IllegalArgumentException before building the transform.","triggerScenarios":"Calling from()/validate() on a configuration where both getReadQuery() is null/empty and getLocation() is null/empty.","commonSituations":"Programmatically built configs where the query is interpolated from user input that turned out empty; CLI/templated pipelines where neither --query nor --table was passed.","solutions":["Set readQuery with a SELECT statement, e.g. setReadQuery(\"SELECT * FROM my_table\").","Or set location to the table name.","Add a config pre-check that fails with a clear message when both fields are empty."],"exampleFix":"// before\nbuilder().setJdbcUrl(url).setJdbcType(\"mysql\") // nothing to read\n// after\nbuilder().setJdbcUrl(url).setJdbcType(\"mysql\").setReadQuery(\"SELECT * FROM users\")","handlingStrategy":"validation","validationCode":"if (!hasText(config.getReadQuery()) && !hasText(config.getLocation())) {\n  throw new IllegalArgumentException(\"Provide either readQuery or location (table)\");\n}\nstatic boolean hasText(String s) { return s != null && !s.isBlank(); }","typeGuard":null,"tryCatchPattern":"try {\n  config.validate();\n} catch (IllegalArgumentException e) {\n  if (\"Either Query or Table must be specified.\".equals(e.getMessage())) {\n    throw new IllegalStateException(\"No read source configured: pass --query or --table\", e);\n  }\n  throw e;\n}","preventionTips":["Require one of --query/--table at the CLI/argument-parsing layer.","Check interpolated query variables are non-empty before building the config.","Add a unit test asserting a valid minimal configuration."],"tags":["jdbc","java","validation","configuration"],"backgroundTag":"missing-required-argument","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"}