alibaba/DataX · error · RuntimeException

Failed to cast %s to Long

Error message

Failed to cast %s to Long

What it means

In gdbreader's ValueType mapping, longColumnMapper(Object o) accepts Integer, Long, and numeric String only; any other runtime type (Double, Float, Boolean, Date, null-typed, etc.) hits the else-branch RuntimeException. The message interpolates the offending class name, telling you exactly which Java type came back from the GDB vertex/edge property.

Source

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

        if (value == null) {
            return null;
        }
        return columnFunc.apply(value);
    }

    private static class ValueTypeHolder {
        private static Map<String, ValueType> shortName2type = new HashMap<>();

        private static LongColumn longColumnMapper(Object o) {
            long v;
            if (o instanceof Integer) {
                v = (int) o;
            } else if (o instanceof Long) {
                v = (long) o;
            } else if (o instanceof String) {
                v = Long.valueOf((String) o);
            } else {
                throw new RuntimeException("Failed to cast " + o.getClass() + " to Long");
            }

            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 {

View on GitHub (pinned to 80ec23d5c5)

Solutions

  1. Change the column's mapping type in the reader config from 'long' to 'double' for properties that are floating-point in GDB
  2. Re-store the GDB property as an integer type if the schema demands Long
  3. If necessary, map as 'string' to pass the raw value through and convert downstream
  4. Check the error text for the concrete class name to confirm what the server actually sent

Example fix

// before (reader column config)
{"columnName": "score", "Type": "long"}
// after
{"columnName": "score", "Type": "double"}
Defensive patterns

Strategy: type-guard

Type guard

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

Try / catch

catch (RuntimeException e) {
    if (e.getMessage() != null && e.getMessage().startsWith("Failed to cast ")) {
        String cls = e.getMessage().substring("Failed to cast ".length(), e.getMessage().indexOf(" to "));
        log.warn("property of type {} not long-mappable; change column Type in gdbreader mapping", cls);
    }
    throw e;
}

Prevention

When it happens

Trigger: A GDB property mapped to LongColumn (column type 'long' in the reader config) whose value arrives as e.g. Double (TinkerPop returns Double for many numeric literals) or Float, since the instanceof chain has no Double->Long branch. Also String values that would be caught by Long.valueOf but a non-numeric String instead throws NumberFormatException before this branch only for String; other types land here.

Common situations: Gremlin server returning Float/Double for numbers stored without explicit type suffix; GDB property set of type int32 read as Integer is fine but int64 read through a path yielding Double; mapping configuration mismatch — declaring a float/double property as 'long' in the columns section.

Related errors


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