{"record":{"id":"b49e476c4bd97d10","repo":"apache/cassandra","slug":"ambiguous-s-operation-with-args-s-and-s-use","errorCode":null,"errorMessage":"Ambiguous '%s' operation with args %s and %s: use type hint to disambiguate, example '(int) ?'","messagePattern":"Ambiguous '(.+?)' operation with args (.+?) and (.+?): use type hint to disambiguate, example '\\(int\\) \\?'","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/functions/FunctionResolver.java","lineNumber":180,"sourceCode":"\n            throw invalidRequest(\"Invalid call to function %s, none of its type signatures match (known type signatures: %s)\",\n                                 name, format(candidates));\n        }\n\n        if (compatibles.size() > 1)\n        {\n            if (OperationFcts.isOperation(name))\n            {\n                if (receiverType != null && !containsMarkers(providedArgs))\n                {\n                    for (Function toTest : compatibles)\n                    {\n                        List<AbstractType<?>> argTypes = toTest.argTypes();\n                        if (receiverType.equals(argTypes.get(0)) && receiverType.equals(argTypes.get(1)))\n                            return toTest;\n                    }\n                }\n                throw invalidRequest(\"Ambiguous '%s' operation with args %s and %s: use type hint to disambiguate, example '(int) ?'\",\n                                     OperationFcts.getOperator(name), providedArgs.get(0), providedArgs.get(1));\n            }\n\n            if (OperationFcts.isNegation(name))\n                throw invalidRequest(\"Ambiguous negation: use type casts to disambiguate\");\n\n            throw invalidRequest(\"Ambiguous call to function %s (can be matched by following signatures: %s): use type casts to disambiguate\",\n                                 name, format(compatibles));\n        }\n\n        return compatibles.get(0);\n    }\n\n    /**\n     * Checks if at least one of the specified arguments is a marker.\n     *\n     * @param args the arguments to check\n     * @return {@code true} if if at least one of the specified arguments is a marker, {@code false} otherwise","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/functions/FunctionResolver.java#L162-L198","documentation":"When resolving a CQL operator (e.g. +, -) FunctionResolver found multiple compatible signatures. If the receiver (result type hint from surrounding context) doesn't disambiguate, Cassandra refuses to silently pick one and throws this message telling the developer to add an explicit type cast. This exists because operators like '+' are overloaded for int, long, float, decimal, date/duration combinations, and choosing the wrong one changes semantics.","triggerScenarios":"A query like SELECT int_col + float_col FROM t (int and float overloads both applicable via coercion) with no receiver type to narrow it, e.g. no comparison against a typed literal or CAST that pins the result type.","commonSituations":"Arithmetic mixing int and bigint/float/decimal columns; date + duration vs date + time operations; users expecting Java-like numeric promotion which Cassandra deliberately does not auto-apply.","solutions":["Add an explicit cast to one operand: (int) col or (double) col so exactly one signature matches","Wrap the expression in a CAST: SELECT CAST(a + b AS double) FROM t","Compare or assign the result against a typed target (e.g. a double column or literal) so the receiver type disambiguates","Reconsider column types so operands in arithmetic share the same type"],"exampleFix":"// before: ambiguous '+' between int and float\nSELECT a + b FROM t;\n// after\ndatastax session.execute(\"SELECT (double)a + b FROM t\");","handlingStrategy":"validation","validationCode":"function assertSameNumericType(a, b) { if (a !== b) throw new Error(`ambiguous '+' for ${a} and ${b}: add explicit cast`); }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always cast operands of arithmetic operators to a common type","Avoid mixing int/bigint/float/decimal columns in the same expression","Prefer CAST(... AS type) around operator results"],"tags":["cql","operators","ambiguity"],"backgroundTag":"invalid-argument","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}