alibaba/DataX · error · SQLException

Date type conversion error: [%s]

Error message

Date type conversion error: [%s]

What it means

DatabendWriter throws this SQLException when writing a column whose JDBC type is DATE and column.asDate() raises a DataXException — i.e. the incoming Column cannot be interpreted as a date at all. The failed column object itself is embedded in the message, and the exception propagates out of the PreparedStatement population loop, failing the write batch.

Source

Thrown at databendwriter/src/main/java/com/alibaba/datax/plugin/writer/databendwriter/DatabendWriter.java:112

                            case Types.BIGINT:
                                preparedStatement.setLong(columnIndex + 1, column.asLong());
                                break;
                            case Types.DECIMAL:
                                preparedStatement.setBigDecimal(columnIndex + 1, column.asBigDecimal());
                                break;
                            case Types.FLOAT:
                            case Types.REAL:
                                preparedStatement.setFloat(columnIndex + 1, column.asDouble().floatValue());
                                break;
                            case Types.DOUBLE:
                                preparedStatement.setDouble(columnIndex + 1, column.asDouble());
                                break;
                            case Types.DATE:
                                java.sql.Date sqlDate = null;
                                try {
                                    utilDate = column.asDate();
                                } catch (DataXException e) {
                                    throw new SQLException(String.format(
                                            "Date type conversion error: [%s]", column));
                                }

                                if (null != utilDate) {
                                    sqlDate = new java.sql.Date(utilDate.getTime());
                                }
                                preparedStatement.setDate(columnIndex + 1, sqlDate);
                                break;

                            case Types.TIME:
                                java.sql.Time sqlTime = null;
                                try {
                                    utilDate = column.asDate();
                                } catch (DataXException e) {
                                    throw new SQLException(String.format(
                                            "Date type conversion error: [%s]", column));
                                }

View on GitHub (pinned to 80ec23d5c5)

Solutions

  1. Inspect the failed column in the message (Column.toString includes type and value) to find the offending row.
  2. Fix or transform the source data: use a transformer (dx_replace/dx_substr) or clean the string to a supported date format before it reaches the writer.
  3. Cast the Databend column to a string type if the source genuinely contains non-date values.
  4. Verify the reader's column type mapping so date-like sources arrive as DateColumn rather than StringColumn.

Example fix

// before: reader passes "2021-13-45" into a DATE column -> SQLException
// after: validate/normalize in a transformer or reader query
"transformer": [{ "name": "dx_replace", "parameter": { "columnIndex": 3, "paras": [3, "8", "2", "01"] } }]
// or exclude/clean bad rows at the source query level
Defensive patterns

Strategy: validation

Validate before calling

// reader-side guard: only pass values that asDate() can handle
Object v = record.getColumn(i).getRawValue();
if (v instanceof String && !v.toString().matches("\\d{4}-\\d{2}-\\d{2}.*")) {
    throw new IllegalArgumentException("Row " + record + ": column " + i + " is not a date: " + v);
}

Try / catch

catch (SQLException e) { if (e.getMessage().contains("Date type conversion error")) { log offending batch/row from message-embedded Column; dirty-route the record } else throw e; }

Prevention

When it happens

Trigger: A DATE-typed target column receiving a Column subtype whose asDate() throws — typically a StringColumn holding a non-date string like "N/A" or "2021-13-45", or a numeric column with an out-of-range raw value. Unlike TIMESTAMP, there is no regex fast-path for DATE; conversion goes straight to asDate().

Common situations: Source column typed as string containing free text or a different date format, dirty rows after an upstream schema change, or null handling differences where asString() is null but the column is a type that cannot produce a Date.

Related errors


AI-assisted analysis of alibaba/DataX@80ec23d5c5 (2026-08-14). Data as JSON: /api/errors/4f87fd4ebdee450a. Report an issue: GitHub.