alibaba/DataX · error · RuntimeException

Failed to cast %s to Double

Error message

Failed to cast %s to Double

What it means

doubleColumnMapper(Object o) in gdbreader's ValueType accepts Integer, Long, Float, Double, and parseable String; anything else (Boolean, Date, byte[], custom types) falls to the RuntimeException naming the offending class. It is the reader-side conversion of a GDB property to a DataX DoubleColumn.

Source

Thrown at gdbreader/src/main/java/com/alibaba/datax/plugin/reader/gdbreader/mapping/ValueType.java:97

            }

            return new LongColumn(v);
        }

        private static DoubleColumn doubleColumnMapper(Object o) {
            double v;
            if (o instanceof Integer) {
                v = (double) (int) o;
            } else if (o instanceof Long) {
                v = (double) (long) o;
            } else if (o instanceof Float) {
                v = (double) (float) o;
            } else if (o instanceof Double) {
                v = (double) o;
            } else if (o instanceof String) {
                v = Double.valueOf((String) o);
            } else {
                throw new RuntimeException("Failed to cast " + o.getClass() + " to Double");
            }

            return new DoubleColumn(v);
        }

        private static BoolColumn boolColumnMapper(Object o) {
            boolean v;
            if (o instanceof Integer) {
                v = ((int) o != 0);
            } else if (o instanceof Long) {
                v = ((long) o != 0);
            } else if (o instanceof Boolean) {
                v = (boolean) o;
            } else if (o instanceof String) {
                v = Boolean.valueOf((String) o);
            } else {
                throw new RuntimeException("Failed to cast " + o.getClass() + " to Boolean");
            }

View on GitHub (pinned to 80ec23d5c5)

Solutions

  1. Match the mapping type to the real property type: booleans -> 'boolean', dates -> 'string'
  2. Check the class name in the error message; if it is a List/collection, the property is multi-valued — flatten it in GDB or map a single-valued property
  3. Use 'string' mapping to bypass numeric conversion for heterogeneous properties

Example fix

// before
{"columnName": "isActive", "Type": "double"}
// after
{"columnName": "isActive", "Type": "boolean"}
Defensive patterns

Strategy: type-guard

Type guard

static boolean mapsToDouble(Object o) {
    return o instanceof Integer || o instanceof Long || o instanceof Float
        || o instanceof Double
        || (o instanceof String && ((String) o).matches("-?\\d+(\\.\\d+)?"));
}

Try / catch

catch (RuntimeException e) {
    if (e.getMessage() != null && e.getMessage().contains(" to Double")) {
        // offending class name is in the message; adjust column Type or pre-convert the value
    }
    throw e;
}

Prevention

When it happens

Trigger: Column declared 'double' in the gdbreader mapping while the actual property is Boolean or a complex/temporal type the mapper cannot widen. E.g. a boolean flag mapped to double, or a Date property returned by the Gremlin client as java.util.Date.

Common situations: Mapping config copy-paste declaring all numeric-ish columns 'double'; GDB storing dates as java.util.Date on the server side; property cardinality returning a list (List) when multi-value properties exist — a List hits the else branch.

Related errors


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