{"record":{"id":"97fa3551bf542a85","repo":"apache/beam","slug":"received-an-empty-value-for-non-nullable-snowflake-field-s","errorCode":null,"errorMessage":"Received an empty value for non-nullable Snowflake field '%s'.","messagePattern":"Received an empty value for non-nullable Snowflake field '(.+?)'\\.","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":207,"sourceCode":"  }\n\n  public static @Nullable Object toBeamValue(String value, Schema.Field field) {\n    if (value == null || value.isEmpty()) {\n      if (field.getType().getNullable()) {\n        return null;\n      }\n\n      /*\n       * Snowflake COPY encodes NULL as an empty CSV value. Therefore an empty\n       * value cannot be represented for a required non-string type.\n       *\n       * For STRING, preserve the empty string.\n       */\n      if (field.getType().getTypeName() == Schema.TypeName.STRING) {\n        return \"\";\n      }\n\n      throw new IllegalArgumentException(\n          String.format(\n              \"Received an empty value for non-nullable Snowflake field '%s'.\", field.getName()));\n    }\n\n    try {\n      switch (field.getType().getTypeName()) {\n        case BYTE:\n          return Byte.valueOf(value);\n\n        case INT16:\n          return Short.valueOf(value);\n\n        case INT32:\n          return Integer.valueOf(value);\n\n        case INT64:\n          return Long.valueOf(value);\n","sourceCodeStart":189,"sourceCodeEnd":225,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/snowflake/src/main/java/org/apache/beam/sdk/io/snowflake/SnowflakeSchemaTransformUtils.java#L189-L225","documentation":"toBeamValue rejects empty strings for Snowflake fields whose Beam schema type is not nullable (except STRING, where an empty string is preserved). A non-nullable field receiving an empty value from Snowflake would produce an invalid Beam Row, so it throws an IllegalArgumentException identifying the field.","triggerScenarios":"A Snowflake column containing NULL or empty string mapped to a Beam Field declared non-nullable (getFieldNullable() false) of any non-STRING type (INTEGER, BOOLEAN, TIMESTAMP, BYTES, etc.) processed via toRow.","commonSituations":"Sparse columns with NULLs but schema marked required; COALESCE-less joins producing NULLs; CSV-ish exports where missing values become empty strings.","solutions":["Mark the field nullable in the Beam schema: Field.of(name, FieldType.X).withNullable(true).","Filter out or transform NULL/empty values in the query (COALESCE(col, default)).","Use a STRING field type if empty strings should be preserved as-is."],"exampleFix":"// before\nField.of(\"age\", FieldType.INT64) // non-nullable, column can be NULL\n// after\nField.of(\"age\", FieldType.INT64).withNullable(true)","handlingStrategy":"validation","validationCode":"for (int i = 0; i < schema.getFieldCount(); i++) {\n  Field f = schema.getField(i);\n  if ((parts[i] == null || parts[i].isEmpty()) && !f.getType().getNullable()\n      && f.getType().getTypeName() != Schema.TypeName.STRING) {\n    throw new IllegalArgumentException(\"empty value for non-nullable field \" + f.getName());\n  }\n}","typeGuard":null,"tryCatchPattern":"try { Row r = SnowflakeSchemaTransformUtils.toRow(parts, schema); }\ncatch (IllegalArgumentException e) { log.error(e.getMessage()); routeToDeadLetter(parts); }","preventionTips":["Mark fields nullable in the Beam schema when the Snowflake column allows NULL.","Use COALESCE in queries to substitute defaults for NULLs.","Audit Snowflake columns for NULLs before declaring them non-nullable."],"tags":["java","snowflake","schema","nullability"],"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-20T03:17:13.778Z"}