{"record":{"id":"768f0f732f0c44f6","repo":"pentaho/pentaho-kettle","slug":"the-date-has-too-much-day-from-epoch-day","errorCode":null,"errorMessage":"The date has too much day from epoch day!","messagePattern":"The date has too much day from epoch day!","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":225,"sourceCode":"            case TIMESTAMP_MILLIS, TIMESTAMP_MICROS, TIMESTAMP_NANOS:\n              Timestamp defaultTimestamp = null;\n              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 );","sourceCodeStart":207,"sourceCodeEnd":243,"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#L207-L243","documentation":"During Avro record creation, converting a Kettle date/timestamp field to an Avro epoch-day value triggers an ArithmeticException (integer overflow in day computation), which createAvroRecord wraps as IllegalArgumentException('The date has too much day from epoch day!'). It signals a date value too extreme to represent as an Avro date.","triggerScenarios":"Writing a row whose date/timestamp field, when converted to epoch days (long/days conversion in the field-mapping switch), overflows — e.g. a year like 999999999 or a null-parsed garbage value producing a huge millisecond count.","commonSituations":"Bad input data in a date column (typo'd year, sentinel dates like 0001-01-01 mishandled, epoch in wrong unit — seconds passed as milliseconds); inconsistent source-type mapping between timestamp and date fields.","solutions":["Inspect the offending row's date value and fix it upstream (correct year/epoch unit)","Verify the field's Avro logical type mapping (date vs timestamp-millis) matches the Kettle value type","Add a filter/invalid-rows handling step before the Avro output to divert rows with out-of-range dates","Catch IllegalArgumentException from write() and log the row for correction"],"exampleFix":"// before\nrow.getDate( \"event_date\" ) // contains year 999999999 -> ArithmeticException on toEpochDay()\n// after\n// sanitize/validate before writing\nLocalDate d = row.getDate( \"event_date\" ).toInstant().atZone( ZoneOffset.UTC ).toLocalDate();\nif ( d.getYear() < 1 || d.getYear() > 9999 ) { d = LocalDate.of( 9999, 12, 31 ); }","handlingStrategy":"validation","validationCode":"Date d = row.getDate( fieldName );\nlong year = d == null ? 0 : d.toInstant().atZone( ZoneOffset.UTC ).getYear();\nif ( year < 1 || year > 9999 ) {\n  throw new ValidationException( fieldName + \" year out of representable range: \" + year );\n}","typeGuard":null,"tryCatchPattern":"try {\n  writer.write( row );\n} catch ( IllegalArgumentException e ) {\n  logError( \"Unwritable date row: \" + e.getMessage(), e );\n  // route row to error stream\n}","preventionTips":["Validate date ranges in input data before Avro output","Keep epoch units consistent (seconds vs milliseconds)","Match Avro logical types (date/timestamp-millis) to Kettle value types","Use a filter step to divert rows with implausible dates"],"tags":["avro","date","overflow","data-quality"],"backgroundTag":"value-out-of-range","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"}