{"record":{"id":"c14d37133963deae","repo":"apache/iceberg","slug":"invalid-value-for-conversion-to-type-s-s-s","errorCode":null,"errorMessage":"Invalid value for conversion to type %s: %s (%s)","messagePattern":"Invalid value for conversion to type (.+?): (.+?) \\((.+?)\\)","errorType":"validation","errorClass":"ValidationException","httpStatus":null,"severity":"error","filePath":"api/src/main/java/org/apache/iceberg/expressions/UnboundPredicate.java","lineNumber":182,"sourceCode":"  }\n\n  private boolean floatingType(Type.TypeID typeID) {\n    return Type.TypeID.DOUBLE.equals(typeID) || Type.TypeID.FLOAT.equals(typeID);\n  }\n\n  private Expression bindLiteralOperation(BoundTerm<T> boundTerm) {\n    if (op() == Operation.STARTS_WITH || op() == Operation.NOT_STARTS_WITH) {\n      ValidationException.check(\n          boundTerm.type().equals(Types.StringType.get()),\n          \"Term for STARTS_WITH or NOT_STARTS_WITH must produce a string: %s: %s\",\n          boundTerm,\n          boundTerm.type());\n    }\n\n    Literal<T> lit = literal().to(boundTerm.type());\n\n    if (lit == null) {\n      throw new ValidationException(\n          \"Invalid value for conversion to type %s: %s (%s)\",\n          boundTerm.type(), literal().value(), literal().value().getClass().getName());\n\n    } else if (lit == Literals.aboveMax()) {\n      switch (op()) {\n        case LT:\n        case LT_EQ:\n        case NOT_EQ:\n          return Expressions.alwaysTrue();\n        case GT:\n        case GT_EQ:\n        case EQ:\n          return Expressions.alwaysFalse();\n      }\n    } else if (lit == Literals.belowMin()) {\n      switch (op()) {\n        case GT:\n        case GT_EQ:","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/api/src/main/java/org/apache/iceberg/expressions/UnboundPredicate.java#L164-L200","documentation":"During bindLiteralOperation, the literal is converted to the bound term's type via literal().to(type). If the conversion returns null — meaning the value cannot be represented in the target type and is not the aboveMax/belowMin sentinel — binding fails with this ValidationException reporting the target type, the value, and its Java class.","triggerScenarios":"Binding a predicate whose literal cannot be converted to the column type: e.g. comparing a long literal that overflows an int column in a way that produces no conversion, a string literal to a numeric column where conversion is undefined, or a decimal literal to an incompatible type.","commonSituations":"Engine-generated filters passing wrong-typed literals (string vs numeric); schema evolution changing column types so old hardcoded filter values no longer convert; user API queries filtering a long column with a value beyond the column's precision.","solutions":["Check the column type (schema.findType(name)) and construct the literal with the matching Java type before filtering","Pre-validate the value fits the target type's range/precision (e.g. value fits int, decimal scale/precision match)","Catch ValidationException around bind/filter and surface a user-friendly type error","Fix the query to use a value compatible with the column type"],"exampleFix":"// before\nExpression e = Expressions.equal(\"int_col\", 99999999999L); // cannot convert to int\n// after\nType t = schema.findType(\"int_col\");\nlong v = 99999999999L;\nExpression e = (t.typeId() == Type.TypeID.INTEGER)\n    ? Expressions.equal(\"int_col\", (int) v) // ensure it fits, or reject earlier\n    : Expressions.equal(\"int_col\", v);","handlingStrategy":"validation","validationCode":"Type t = schema.findType(name);\n// verify the literal's Java value is representable in t before building the predicate","typeGuard":null,"tryCatchPattern":"try { table.filter(expr); } catch (ValidationException e) { /* report incompatible literal for column type to the user */ }","preventionTips":["Match literal Java types to column types (int vs long vs decimal)","Check value ranges/precision against the target type before conversion","Re-validate hardcoded filter values after schema evolution","Catch ValidationException at filter-submission boundaries with clear user messages"],"tags":["expressions","predicate","type-conversion","validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}