{"record":{"id":"97ce0ff3ba9bebe3","repo":"alibaba/DataX","slug":"failed-to-cast-s-to-long","errorCode":null,"errorMessage":"Failed to cast %s to Long","messagePattern":"Failed to cast (.+?) to Long","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"gdbreader/src/main/java/com/alibaba/datax/plugin/reader/gdbreader/mapping/ValueType.java","lineNumber":78,"sourceCode":"        if (value == null) {\n            return null;\n        }\n        return columnFunc.apply(value);\n    }\n\n    private static class ValueTypeHolder {\n        private static Map<String, ValueType> shortName2type = new HashMap<>();\n\n        private static LongColumn longColumnMapper(Object o) {\n            long v;\n            if (o instanceof Integer) {\n                v = (int) o;\n            } else if (o instanceof Long) {\n                v = (long) o;\n            } else if (o instanceof String) {\n                v = Long.valueOf((String) o);\n            } else {\n                throw new RuntimeException(\"Failed to cast \" + o.getClass() + \" to Long\");\n            }\n\n            return new LongColumn(v);\n        }\n\n        private static DoubleColumn doubleColumnMapper(Object o) {\n            double v;\n            if (o instanceof Integer) {\n                v = (double) (int) o;\n            } else if (o instanceof Long) {\n                v = (double) (long) o;\n            } else if (o instanceof Float) {\n                v = (double) (float) o;\n            } else if (o instanceof Double) {\n                v = (double) o;\n            } else if (o instanceof String) {\n                v = Double.valueOf((String) o);\n            } else {","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/alibaba/DataX/blob/80ec23d5c5328eb90ca364d2749e92dfaf44541e/gdbreader/src/main/java/com/alibaba/datax/plugin/reader/gdbreader/mapping/ValueType.java#L60-L96","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Change the column's mapping type in the reader config from 'long' to 'double' for properties that are floating-point in GDB","Re-store the GDB property as an integer type if the schema demands Long","If necessary, map as 'string' to pass the raw value through and convert downstream","Check the error text for the concrete class name to confirm what the server actually sent"],"exampleFix":"// before (reader column config)\n{\"columnName\": \"score\", \"Type\": \"long\"}\n// after\n{\"columnName\": \"score\", \"Type\": \"double\"}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"static boolean mapsToLong(Object o) {\n    return o instanceof Integer || o instanceof Long\n        || (o instanceof String && ((String) o).matches(\"-?\\\\d+\"));\n}","tryCatchPattern":"catch (RuntimeException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Failed to cast \")) {\n        String cls = e.getMessage().substring(\"Failed to cast \".length(), e.getMessage().indexOf(\" to \"));\n        log.warn(\"property of type {} not long-mappable; change column Type in gdbreader mapping\", cls);\n    }\n    throw e;\n}","preventionTips":["Audit GDB property types (g.admin() property keys) and align each reader column 'Type' with the server-side type","Prefer 'string' mapping for heterogeneous/unknown properties","Remember Gremlin/GDB commonly returns Double for numerics — declare double unless proven integral"],"tags":["gdb","gremlin","type-mapping","datax"],"backgroundTag":null,"analyzedSha":"80ec23d5c5328eb90ca364d2749e92dfaf44541e","analyzedAt":"2026-08-14T15:33:51.187Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}