{"record":{"id":"27f0c44af2852af9","repo":"apache/beam","slug":"table-reference-s-must-include-at-least-a-dataset-and-a","errorCode":null,"errorMessage":"Table reference [%s] must include at least a dataset and a table.","messagePattern":"Table reference \\[(.+?)\\] must include at least a dataset and a table\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryUtils.java","lineNumber":1289,"sourceCode":"    if (m.matches()) {\n      // The named groups are not optional, so they are non-null whenever the pattern matches.\n      return new TableReference()\n          .setProjectId(Preconditions.checkStateNotNull(m.group(\"PROJECT\")))\n          .setDatasetId(Preconditions.checkStateNotNull(m.group(\"DATASET\")))\n          .setTableId(Preconditions.checkStateNotNull(m.group(\"TABLE\")));\n    }\n    return null;\n  }\n\n  /**\n   * Returns a String representation of the table destination in the form:\n   * `myproject.mydataset.mytable`.\n   *\n   * @param tableReference - a BigQueryTableIdentifier that may or may not include the project.\n   */\n  public static @Nullable String toTableSpec(TableReference tableReference) {\n    if (tableReference.getDatasetId() == null || tableReference.getTableId() == null) {\n      throw new IllegalArgumentException(\n          String.format(\n              \"Table reference [%s] must include at least a dataset and a table.\", tableReference));\n    }\n    String tableSpec =\n        String.format(\"%s.%s\", tableReference.getDatasetId(), tableReference.getTableId());\n    if (!Strings.isNullOrEmpty(tableReference.getProjectId())) {\n      tableSpec = String.format(\"%s.%s\", tableReference.getProjectId(), tableSpec);\n    }\n    return tableSpec;\n  }\n\n  static TableSchema trimSchema(TableSchema schema, @Nullable List<String> selectedFields) {\n    if (selectedFields == null || selectedFields.isEmpty()) {\n      return schema;\n    }\n\n    List<TableFieldSchema> trimmedFields =\n        schema.getFields().stream()","sourceCodeStart":1271,"sourceCodeEnd":1307,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryUtils.java#L1271-L1307","documentation":"BigQueryUtils.toTableSpec builds a table spec string (project.dataset.table or dataset.table) from a TableReference. It requires at least datasetId and tableId; if either is null it throws IllegalArgumentException naming the incomplete reference.","triggerScenarios":"Calling BigQueryUtils.toTableSpec (or Write/Read paths that call it) with a TableReference constructed without setting datasetId or tableId — e.g. a builder that only set the project, or a reference parsed from a malformed table spec.","commonSituations":"Parsing user-supplied table IDs like \"mytable\" or \"myproject.\" that lack dataset parts; building TableReference programmatically and forgetting setDatasetId/setTableId; config values with typos (dataset vs datasetId); dynamic destinations where destination lookup returned an empty table.","solutions":["Set both datasetId and tableId on the TableReference before calling toTableSpec","Validate the source string with BigQueryHelpers.parseTableSpec or TableReference.fromDatasetId instead of manual string building","Log/inspect tableReference in the message to find which field is missing","Add a pre-call guard asserting the fields are non-null"],"exampleFix":"// before\nTableReference ref = TableReference.newBuilder().setProjectId(\"p\").build();\nString spec = BigQueryUtils.toTableSpec(ref);\n// after\nTableReference ref = TableReference.newBuilder()\n    .setProjectId(\"p\").setDatasetId(\"mydataset\").setTableId(\"mytable\").build();\nString spec = BigQueryUtils.toTableSpec(ref);","handlingStrategy":"validation","validationCode":"if (ref.getDatasetId() == null || ref.getTableId() == null) {\n  throw new IllegalArgumentException(\"TableReference needs datasetId and tableId: \" + ref);\n}\nString spec = BigQueryUtils.toTableSpec(ref);","typeGuard":"boolean isCompleteRef(TableReference r) { return r.getDatasetId() != null && r.getTableId() != null; }","tryCatchPattern":"try { spec = BigQueryUtils.toTableSpec(ref); } catch (IllegalArgumentException e) { LOG.error(\"Incomplete table reference: %s\", e.getMessage()); throw e; }","preventionTips":["Build references with TableReference.fromDatasetId/fromTableSpec instead of manual builders","Parse user table IDs with BigQueryHelpers.parseTableSpec","Validate config-derived table specs at pipeline start"],"tags":["bigquery","argument-validation","table-reference"],"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"}