apache/cassandra · error · InvalidRequestException
Ambiguous negation: use type casts to disambiguate
Error message
Ambiguous negation: use type casts to disambiguate
What it means
Specific to the unary negation operator (-). FunctionResolver found multiple compatible signatures for negating a value (e.g. the operand's type can coerce to both int and float negation overloads) and no type hint exists, so it throws a targeted message instead of the generic ambiguous-call error, instructing the developer to use explicit type casts.
Source
Thrown at src/java/org/apache/cassandra/cql3/functions/FunctionResolver.java:185
if (compatibles.size() > 1)
{
if (OperationFcts.isOperation(name))
{
if (receiverType != null && !containsMarkers(providedArgs))
{
for (Function toTest : compatibles)
{
List<AbstractType<?>> argTypes = toTest.argTypes();
if (receiverType.equals(argTypes.get(0)) && receiverType.equals(argTypes.get(1)))
return toTest;
}
}
throw invalidRequest("Ambiguous '%s' operation with args %s and %s: use type hint to disambiguate, example '(int) ?'",
OperationFcts.getOperator(name), providedArgs.get(0), providedArgs.get(1));
}
if (OperationFcts.isNegation(name))
throw invalidRequest("Ambiguous negation: use type casts to disambiguate");
throw invalidRequest("Ambiguous call to function %s (can be matched by following signatures: %s): use type casts to disambiguate",
name, format(compatibles));
}
return compatibles.get(0);
}
/**
* Checks if at least one of the specified arguments is a marker.
*
* @param args the arguments to check
* @return {@code true} if if at least one of the specified arguments is a marker, {@code false} otherwise
*/
private static boolean containsMarkers(List<? extends AssignmentTestable> args)
{
return args.stream().anyMatch(Marker.Raw.class::isInstance);
}View on GitHub (pinned to 88fd0f6a0e)
Solutions
- Cast the operand explicitly: SELECT -(int) col FROM t or -(double) col FROM t
- Pin the result with CAST: SELECT CAST(-col AS double) FROM t
- Use the expression where a typed receiver exists (e.g. compare to a typed literal)
Example fix
// before
SELECT -amount FROM orders; // amount is decimal, ambiguous
// after
datastax session.execute("SELECT -(double)amount FROM orders"); Defensive patterns
Strategy: validation
Validate before calling
function checkNegation(colType) { if (['decimal','varint','float'].includes(colType)) console.warn('negation ambiguous: cast explicitly, e.g. -(double)col'); } Prevention
- Never write bare -col on non-int columns; cast first
- Pin expression types with CAST when column types can coerce multiple ways
When it happens
Trigger: A CQL query like SELECT -some_varint_or_decimal_col FROM t where the operand type is compatible with more than one negation signature and the surrounding context gives no receiver type.
Common situations: Negating decimal/varint/float columns where numeric literals or comparisons nearby don't pin a type; users writing -col in a SELECT list with no other typing context.
Understand the failure class
Background: "must be a positive integer", "cannot be empty", "invalid argument": how invalid-argument errors work across open-source libraries — this error's family across 33 libraries.
Related errors
- Ambiguous '%s' operation with args %s and %s: use type hint
- Ambiguous call to function %s (can be matched by following s
- category %s not found in %s
- GRANT operation is not supported by AllowAllAuthorizer
- REVOKE operation is not supported by AllowAllAuthorizer
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/3e93f7828b631d7b.
Report an issue: GitHub.