{"record":{"id":"25619e2bf4cbe570","repo":"apache/flink","slug":"field-expression-must-be-equal-to-or-for-a","errorCode":null,"errorMessage":"Field expression must be equal to '*' or '_' for atomic types.","messagePattern":"Field expression must be equal to '\\*' or '_' for atomic types\\.","errorType":"exception","errorClass":"InvalidProgramException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/common/operators/Keys.java","lineNumber":472,"sourceCode":"                throw new IndexOutOfBoundsException(\"Tuple position is out of range: \" + fieldPos);\n            }\n\n            TypeInformation<?> sortKeyType = ((CompositeType<?>) type).getTypeAt(fieldPos);\n            return sortKeyType.isSortKeyType();\n        }\n\n        public static boolean isSortKey(String fieldExpr, TypeInformation<?> type) {\n\n            TypeInformation<?> sortKeyType;\n\n            fieldExpr = fieldExpr.trim();\n            if (SELECT_ALL_CHAR.equals(fieldExpr) || SELECT_ALL_CHAR_SCALA.equals(fieldExpr)) {\n                sortKeyType = type;\n            } else {\n                if (type instanceof CompositeType) {\n                    sortKeyType = ((CompositeType<?>) type).getTypeAt(fieldExpr);\n                } else {\n                    throw new InvalidProgramException(\n                            \"Field expression must be equal to '\"\n                                    + SELECT_ALL_CHAR\n                                    + \"' or '\"\n                                    + SELECT_ALL_CHAR_SCALA\n                                    + \"' for atomic types.\");\n                }\n            }\n\n            return sortKeyType.isSortKeyType();\n        }\n    }\n\n    // --------------------------------------------------------------------------------------------\n\n    // --------------------------------------------------------------------------------------------\n    //  Utilities\n    // --------------------------------------------------------------------------------------------\n","sourceCodeStart":454,"sourceCodeEnd":490,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/common/operators/Keys.java#L454-L490","documentation":"Thrown by Keys.ExpressionKeys.isSortKey(String, TypeInformation) when the type is not composite and the expression is not the select-all wildcard. Atomic types (String, Integer, etc.) have no addressable sub-fields, so the only valid sort expression is '*' (Java) or '_' (Scala). Any named-field expression on an atomic type is meaningless.","triggerScenarios":"Calling isSortKey(\"myField\", stringTypeInfo) where the type is a String or primitive wrapper. Higher-level sort APIs that call this with a user-provided field name on a non-composite stream.","commonSituations":"Reusing a field-name string meant for a POJO on a stream that turned out to be a primitive. Forgetting that scalar streams require wildcard expressions.","solutions":["Use isSortKey(\"*\", type) or isSortKey(\"_\", type) for atomic types.","If a sub-field was intended, first convert the stream to a composite type.","Branch on type instanceof CompositeType to choose expression vs wildcard."],"exampleFix":"// before\nKeys.ExpressionKeys.isSortKey(\"value\", BasicTypeInfo.STRING_TYPE_INFO);\n\n// after\nKeys.ExpressionKeys.isSortKey(\"*\", BasicTypeInfo.STRING_TYPE_INFO);","handlingStrategy":"type-guard","validationCode":"if (!(type instanceof CompositeType)\n        && !(\"*\".equals(fieldExpr.trim()) || \"_\".equals(fieldExpr.trim()))) {\n    throw new IllegalArgumentException(\n        \"Atomic type requires '*' or '_' as sort expression.\");\n}","typeGuard":"static boolean isValidSortExprForAtomic(String expr) {\n    String t = expr.trim();\n    return \"*\".equals(t) || \"_\".equals(t);\n}","tryCatchPattern":null,"preventionTips":["Use '*' or '_' for atomic-type sort expressions.","Branch on type instanceof CompositeType before choosing expression style.","Do not reuse POJO field names on scalar streams."],"tags":["keys","sorting","type-system","flink-core"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}