{"record":{"id":"18c8a1aace13926c","repo":"apache/druid","slug":"not-a-scalar-in-the-dictionary-18c8a1","errorCode":null,"errorMessage":"not a scalar in the dictionary","messagePattern":"not a scalar in the dictionary","errorType":"exception","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/segment/nested/VariantColumn.java","lineNumber":930,"sourceCode":"    if (variantTypes == null) {\n      return lookupScalarValue(id);\n    } else {\n      ExprEval eval = ExprEval.ofType(logicalExpressionType, lookupScalarValue(id));\n      return eval.value();\n    }\n  }\n\n  @Nullable\n  private Object lookupScalarValue(int id)\n  {\n    if (id < adjustLongId) {\n      return StringUtils.fromUtf8Nullable(stringDictionary.get(id));\n    } else if (id < adjustDoubleId) {\n      return longDictionary.get(id - adjustLongId);\n    } else if (id < adjustArrayId) {\n      return doubleDictionary.get(id - adjustDoubleId);\n    }\n    throw new IllegalArgumentException(\"not a scalar in the dictionary\");\n  }\n\n  /**\n   * Make a {@link VectorObjectSelector} for a dictionary encoded column that coerces mixed types to a common type\n   */\n  public abstract static class VariantVectorObjectSelector implements VectorObjectSelector\n  {\n    private final int[] vector;\n    private final Object[] objects;\n    private int offsetId = ReadableVectorInspector.NULL_ID;\n    private final ReadableVectorOffset offset;\n    private final ColumnarInts encodedValueColumn;\n    private final FrontCodedIntArrayIndexed arrayDictionary;\n    private final ExpressionType logicalExpressionType;\n    private final int adjustArrayId;\n\n    protected VariantVectorObjectSelector(\n        ReadableVectorOffset offset,","sourceCodeStart":912,"sourceCodeEnd":948,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/segment/nested/VariantColumn.java#L912-L948","documentation":"This error comes from a dictionary-lookup helper in VariantColumn (the dictionary-encoded variant column variant) that maps an id to a string, long, or double. If the id exceeds all scalar sub-dictionary ranges (including the array adjust bound), it cannot correspond to any scalar dictionary entry, so it throws IllegalArgumentException 'not a scalar in the dictionary'.","triggerScenarios":"Looking up an id beyond the string+long+double dictionary sizes in a dictionary-encoded variant column, typically because the id belongs to an array entry or is stale/corrupt.","commonSituations":"Vectorized or row queries resolving ids for a mixed-type variant column where array ids leaked into a scalar lookup; segments written with a different dictionary layout than the reader expects (version mismatch).","solutions":["Regenerate or re-ingest the segment to rebuild consistent dictionaries","Confirm reader and writer Druid versions match for the segment format (V1 nested columns)","Check for array ids being passed into scalar-only lookup paths and route them to the array dictionary","Validate segment dictionaries for corruption"],"exampleFix":"// before\nObject v = scalarLookup(id); // id >= adjustArrayId\n// after\nif (id < adjustArrayId) { Object v = scalarLookup(id); } else { /* array path */ }","handlingStrategy":"validation","validationCode":"if (id >= adjustArrayId) { /* id refers to array dictionary, not scalars */ }","typeGuard":"static boolean isScalarId(int id, int adjustArrayId) { return id >= 0 && id < adjustArrayId; }","tryCatchPattern":"try { Object v = lookup(id); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"not a scalar\")) { /* route to array dictionary */ } else { throw e; } }","preventionTips":["Keep scalar/array id ranges consistent between writer and reader versions","Route array ids to the array dictionary path","Re-ingest segments after dictionary layout changes"],"tags":["druid","nested-columns","dictionary-encoding"],"backgroundTag":"index-out-of-bounds","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}