{"record":{"id":"9695483da2e9d494","repo":"apache/beam","slug":"query-and-table-are-mutually-exclusive-configurations","errorCode":null,"errorMessage":"Query and Table are mutually exclusive configurations","messagePattern":"Query and Table are mutually exclusive configurations","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":432,"sourceCode":"            \"If JDBC type is not specified, then Driver Class Name and Driver Jars must be specified.\");\n      }\n      if (!driverClassNamePresent && !jdbcTypePresent) {\n        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","sourceCodeStart":414,"sourceCodeEnd":450,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/jdbc/src/main/java/org/apache/beam/sdk/io/jdbc/JdbcReadSchemaTransformProvider.java#L414-L450","documentation":"The JdbcReadSchemaTransformConfiguration treats readQuery and location (table) as alternatives: a query replaces the table source. If both readQuery and location are set, validate() throws this IllegalArgumentException because the intent is ambiguous.","triggerScenarios":"Building the transform with both setReadQuery(...) and setLocation(...) (table) non-empty and then calling from()/validate().","commonSituations":"Merging default config templates that each populate one field, or UIs that persist the last-selected option without clearing the other.","solutions":["Remove setLocation() if you want to read with a custom SQL query.","Remove setReadQuery() if you want to read a whole table (required for partitioned reads).","Centralize config assembly so only one of the two fields is ever populated."],"exampleFix":"// before\nbuilder().setJdbcUrl(url).setLocation(\"t1\").setReadQuery(\"SELECT * FROM t1\")\n// after\nbuilder().setJdbcUrl(url).setReadQuery(\"SELECT * FROM t1\") // drop the table","handlingStrategy":"validation","validationCode":"if (hasText(config.getReadQuery()) && hasText(config.getLocation())) {\n  throw new IllegalArgumentException(\"Set either readQuery or location (table), not both\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  config.validate();\n} catch (IllegalArgumentException e) {\n  if (\"Query and Table are mutually exclusive configurations\".equals(e.getMessage())) {\n    throw new IllegalStateException(\"Config contains both readQuery and table; keep only one\", e);\n  }\n  throw e;\n}","preventionTips":["Use a builder wrapper that clears location when readQuery is set (and vice versa).","Audit merged config templates for both keys.","Default UIs to a single source selector."],"tags":["jdbc","java","validation","configuration"],"backgroundTag":"mutually-exclusive-options","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"}