{"record":{"id":"4aeff951db679b67","repo":"pentaho/pentaho-kettle","slug":"some-exception-while-writing-avro","errorCode":null,"errorMessage":"some exception while writing avro","messagePattern":"some exception while writing avro","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"plugins/avro-format/core/src/main/java/org/pentaho/di/trans/steps/avro/output/PentahoAvroRecordWriter.java","lineNumber":227,"sourceCode":"              if ( defaultValue != null && !defaultValue.isEmpty() ) {\n                String conversionMask =\n                  ( vmi.getConversionMask() == null ) ? ValueMetaBase.DEFAULT_TIMESTAMP_PARSE_MASK\n                    : vmi.getConversionMask();\n                DateTimeFormatter fmt = DateTimeFormatter.ofPattern( conversionMask );\n                LocalDateTime ldt = LocalDateTime.parse( defaultValue, fmt );\n                defaultTimestamp = Timestamp.valueOf( ldt );\n              }\n              Timestamp timeStamp = (Timestamp) row.getDate( fieldMetaIndex, defaultTimestamp );\n              outputRecord.put( avroFieldName, AvroTimestampHandler.fromTimestamp( timeStamp, avroType ) );\n              break;\n          }\n\n        }\n      }\n    } catch ( ArithmeticException e ) {\n      throw new IllegalArgumentException( \"The date has too much day from epoch day!\", e );\n    } catch ( KettleValueException e ) {\n      throw new IllegalArgumentException( \"some exception while writing avro\", e );\n    }\n    return outputRecord;\n  }\n\n  private double applyScale( double number, IAvroOutputField outputField ) {\n    if ( outputField.getScale() > 0 ) {\n      BigDecimal bd = new BigDecimal( number );\n      bd = bd.setScale( outputField.getScale(), BigDecimal.ROUND_HALF_UP );\n      number = bd.doubleValue();\n    }\n    return number;\n  }\n\n  private float applyScale( float number, IAvroOutputField outputField ) {\n    if ( outputField.getScale() > 0 ) {\n      BigDecimal bd = new BigDecimal( number );\n      bd = bd.setScale( outputField.getScale(), BigDecimal.ROUND_HALF_UP );\n      number = bd.floatValue();","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/plugins/avro-format/core/src/main/java/org/pentaho/di/trans/steps/avro/output/PentahoAvroRecordWriter.java#L209-L245","documentation":"createAvroRecord catches KettleValueException raised while converting a field value for the Avro record and rewraps it as IllegalArgumentException('some exception while writing avro'). It is a generic wrapper for any field value conversion failure (type conversion, formatting, scaling) during Avro write.","triggerScenarios":"A KettleValueException thrown by value conversion code inside the field loop of createAvroRecord — e.g. converting a non-numeric string to a number, incompatible field type vs declared Avro schema type, or applyScale failures.","commonSituations":"Avro output field declared as integer/double while the row holds a string; null handling differences; decimal fields whose scale/precision can't be applied; schema changed but data did not.","solutions":["Read the wrapped KettleValueException cause to identify the exact field and conversion that failed","Align the Avro output field types with the actual row value types in the step mapping","Pre-convert problem columns (e.g. via Select values / Calculator steps) before Avro output","Catch the exception in write() and route the row to an error stream"],"exampleFix":"// before\n// field 'amount' declared int in Avro schema, row value is String '12.50'\n// after\n// convert first in the transformation or set the field type to double/string in the Avro output mapping\nfield.setAvroType( AvroType.DOUBLE ); // matching the actual data","handlingStrategy":"try-catch","validationCode":"// verify each mapped field's Kettle type matches the declared Avro type\nfor ( IAvroOutputField f : fields ) {\n  int valueType = rowMeta.indexOfValue( f.getName() ) >= 0\n    ? rowMeta.getValueMeta( rowMeta.indexOfValue( f.getName() ) ).getType() : -1;\n  if ( !typeCompatible( valueType, f.getAvroType() ) ) {\n    throw new ValidationException( \"Field \" + f.getName() + \" type mismatch\" );\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  writer.write( row );\n} catch ( IllegalArgumentException e ) {\n  Throwable cause = e.getCause(); // KettleValueException names the failing field/conversion\n  logError( \"Avro field conversion failed: \" + cause.getMessage(), cause );\n}","preventionTips":["Inspect the wrapped cause to find the failing field","Keep Avro output field types aligned with row metadata","Pre-convert strings/decimals in the transformation before output","Test mappings on sample rows before full runs"],"tags":["avro","type-conversion","data-quality"],"backgroundTag":"type-mismatch","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}