{"record":{"id":"b0073a00884d6cf7","repo":"apache/beam","slug":"snowflake-row-contains-d-values-but-the-configured-schema","errorCode":null,"errorMessage":"Snowflake row contains %d values, but the configured schema contains %d fields.","messagePattern":"Snowflake row contains (.+?) values, but the configured schema contains (.+?) fields\\.","errorType":"validation","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/snowflake/src/main/java/org/apache/beam/sdk/io/snowflake/SnowflakeSchemaTransformUtils.java","lineNumber":175,"sourceCode":"\n  public static SnowflakeTableSchema toSnowflakeTableSchema(Schema schema) {\n    SnowflakeColumn[] columns =\n        schema.getFields().stream()\n            .map(SnowflakeSchemaTransformUtils::toSnowflakeColumn)\n            .toArray(SnowflakeColumn[]::new);\n\n    return SnowflakeTableSchema.of(columns);\n  }\n\n  public static SnowflakeColumn toSnowflakeColumn(Schema.Field field) {\n    SnowflakeDataType snowflakeType = toSnowflakeDataType(field);\n\n    return SnowflakeColumn.of(field.getName(), snowflakeType, field.getType().getNullable());\n  }\n\n  public static Row toRow(String[] parts, Schema schema) {\n    if (parts.length != schema.getFieldCount()) {\n      throw new IllegalArgumentException(\n          String.format(\n              \"Snowflake row contains %d values, but the configured schema contains %d fields.\",\n              parts.length, schema.getFieldCount()));\n    }\n\n    Row.Builder builder = Row.withSchema(schema);\n\n    for (int i = 0; i < schema.getFieldCount(); i++) {\n      Schema.Field field = schema.getField(i);\n      builder.addValue(toBeamValue(parts[i], field));\n    }\n\n    return builder.build();\n  }\n\n  public static @Nullable Object toBeamValue(String value, Schema.Field field) {\n    if (value == null || value.isEmpty()) {\n      if (field.getType().getNullable()) {","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/snowflake/src/main/java/org/apache/beam/sdk/io/snowflake/SnowflakeSchemaTransformUtils.java#L157-L193","documentation":"toRow converts a raw Snowflake result row (String[] parts) into a Beam Row using the configured Schema. It first enforces arity: the number of values must equal the schema's field count. A mismatch means the query result shape diverges from the declared schema, so row construction is aborted with a format-level IllegalArgumentException.","triggerScenarios":"Running a query whose SELECT column count differs from the schema passed to the transform (added/dropped/renamed columns); a view or table altered after the schema was defined; streaming export producing extra trailing delimiter columns.","commonSituations":"Table schema changed upstream after pipeline config was frozen; user updated the query but not the withSchema()/row-descriptor config; wrong table selected for an existing schema.","solutions":["Align the query's SELECT list with the configured schema (same columns, same order and count).","Regenerate/update the Schema (or TableSchema/Row coders) after any table change.","Validate schema against a sample row (parts.length vs schema.getFieldCount()) before running the pipeline."],"exampleFix":"// before\nSchema schema = Schema.of(Field.of(\"id\", FieldType.STRING)); // row has 2 columns\nRow row = SnowflakeSchemaTransformUtils.toRow(parts, schema);\n// after\nSchema schema = Schema.of(Field.of(\"id\", FieldType.STRING), Field.of(\"name\", FieldType.STRING));\nRow row = SnowflakeSchemaTransformUtils.toRow(parts, schema);","handlingStrategy":"validation","validationCode":"if (parts.length != schema.getFieldCount()) {\n  throw new IllegalArgumentException(\"row arity mismatch: \" + parts.length + \" vs \" + schema.getFieldCount());\n}","typeGuard":null,"tryCatchPattern":"try { Row r = SnowflakeSchemaTransformUtils.toRow(parts, schema); }\ncatch (IllegalArgumentException e) { deadLetter(rows, e); }","preventionTips":["Pin the query's SELECT column list to the schema; avoid SELECT *.","Re-derive the schema whenever the table/view changes.","Add a startup check comparing a sample row's length to schema.getFieldCount()."],"tags":["java","snowflake","schema","apache-beam"],"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"}