{"record":{"id":"40a5256d044c0e09","repo":"apache/beam","slug":"table-with-type-text-and-format-lines-must-have-exactly-one","errorCode":null,"errorMessage":"Table with type 'text' and format 'lines' must have exactly one STRING/VARCHAR/CHAR column ","messagePattern":"Table with type 'text' and format 'lines' must have exactly one STRING/VARCHAR/CHAR column ","errorType":"validation","errorClass":"InvalidTableException","httpStatus":null,"severity":"error","filePath":"sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/meta/provider/text/TextTableProvider.java","lineNumber":120,"sourceCode":"\n    switch (format) {\n      case \"csv\":\n        String specifiedCsvFormat = properties.path(\"csvformat\").asText(null);\n        CSVFormat csvFormat =\n            specifiedCsvFormat != null\n                ? CSVFormat.valueOf(specifiedCsvFormat)\n                : (legacyCsvFormat != null\n                    ? CSVFormat.valueOf(legacyCsvFormat)\n                    : CSVFormat.DEFAULT);\n        return new TextTable(\n            schema, filePattern, new CsvToRow(schema, csvFormat), new RowToCsv(csvFormat));\n      case \"json\":\n        return new TextJsonTable(\n            schema, filePattern, JsonToRow.create(schema, deadLetterFile), RowToJson.create());\n      case \"lines\":\n        if (!(schema.getFieldCount() == 1\n            && schema.getField(0).getType().getTypeName().equals(TypeName.STRING))) {\n          throw new InvalidTableException(\n              \"Table with type 'text' and format 'lines' \"\n                  + \"must have exactly one STRING/VARCHAR/CHAR column \");\n        }\n        return new TextTable(\n            schema, filePattern, new LinesReadConverter(), new LinesWriteConverter());\n      default:\n        throw new InvalidTableException(\n            \"Table with type 'text' must have format 'csv' or 'lines' or 'json'\");\n    }\n  }\n\n  /** Write-side converter for for {@link TextTable} with format {@code 'lines'}. */\n  public static class LinesWriteConverter extends PTransform<PCollection<Row>, PCollection<String>>\n      implements Serializable {\n\n    public LinesWriteConverter() {}\n\n    @Override","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/meta/provider/text/TextTableProvider.java#L102-L138","documentation":"TextTableProvider.buildBeamSqlTable enforces that a text table with format 'lines' has exactly one field of type STRING (VARCHAR/CHAR). If the schema has a different field count or a non-STRING type, InvalidTableException is thrown at table creation because each line can only map to one string value.","triggerScenarios":"Declaring a text/lines table with zero, two, or more columns; or with a single column typed as BYTES, INT, etc. — the check 'schema.getFieldCount() == 1 && type == STRING' fails.","commonSituations":"Copying a multi-column schema from a csv/json table to a lines table; using an INT column assuming auto-conversion of each line; forgetting that 'lines' maps each raw line to one VARCHAR.","solutions":["Define exactly one column of type STRING (or VARCHAR/CHAR) for the lines table.","Switch the format to 'csv' or 'json' if multiple/typed columns are needed.","Parse extra fields out of the single STRING column afterwards (e.g. via UDF or subsequent SELECT with string functions)."],"exampleFix":"// before\nCREATE EXTERNAL TABLE t (a INT, b INT) TYPE 'text' LOCATION 'path' TBLPROPERTIES {'format':'lines'}\n// after\nCREATE EXTERNAL TABLE t (line STRING) TYPE 'text' LOCATION 'path' TBLPROPERTIES {'format':'lines'}","handlingStrategy":"validation","validationCode":"boolean validLines = schema.getFieldCount() == 1 && schema.getField(0).getType().getTypeName().equals(TypeName.STRING);\nif (!validLines) throw new IllegalArgumentException(\"text/lines requires exactly one STRING column\");","typeGuard":null,"tryCatchPattern":"try { table = provider.buildBeamSqlTable(table); } catch (InvalidTableException e) { /* use csv/json format or fix schema */ }","preventionTips":["Use 'lines' only for single-STRING schemas","Choose csv/json for multi-column data","Validate schema before CREATE EXTERNAL TABLE"],"tags":["java","apache-beam","sql","text","schema"],"backgroundTag":"schema-validation-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"}