{"record":{"id":"f5f5c224bcc5854b","repo":"apache/cassandra","slug":"function-argument-is-not-a-tuple-type-but-a-data","errorCode":null,"errorMessage":"Function argument is not a tuple type but a ${dataType.getName()}","messagePattern":"Function argument is not a tuple type but a (.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/functions/UDFContextImpl.java","lineNumber":128,"sourceCode":"    public TupleValue newTupleValue(String cqlDefinition)\n    {\n        AbstractType<?> abstractType = CQLTypeParser.parse(keyspace, cqlDefinition, metadata.get().types);\n        DataType dataType = JavaDriverUtils.driverType(abstractType);\n        return newTupleValue(dataType);\n    }\n\n    private static UDTValue newUDTValue(DataType dataType)\n    {\n        if (!(dataType instanceof UserType))\n            throw new IllegalStateException(\"Function argument is not a UDT but a \" + dataType.getName());\n        UserType userType = (UserType) dataType;\n        return userType.newValue();\n    }\n\n    private static TupleValue newTupleValue(DataType dataType)\n    {\n        if (!(dataType instanceof TupleType))\n            throw new IllegalStateException(\"Function argument is not a tuple type but a \" + dataType.getName());\n        TupleType tupleType = (TupleType) dataType;\n        return tupleType.newValue();\n    }\n\n    private UDFDataType getArgumentTypeByIndex(int index)\n    {\n        if (index < 0 || index >= argTypes.size())\n            throw new IllegalArgumentException(\"Function does not declare an argument with index \" + index);\n        return argTypes.get(index);\n    }\n\n    private UDFDataType getArgumentTypeByName(String argName)\n    {\n        UDFDataType arg = byName.get(argName);\n        if (arg == null)\n            throw new IllegalArgumentException(\"Function does not declare an argument named '\" + argName + '\\'');\n        return arg;\n    }","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/functions/UDFContextImpl.java#L110-L146","documentation":"IllegalStateException guard in UDFContextImpl: a UDF argument declared as a tuple/UDT value is actually of a different CQL type kind, so the requested value object cannot be created. Note the message is a template bug — it prints the literal '${dataType.getName()}' instead of interpolating — and the shown guard actually lives in newUDTValue checking for UserType; treat it as a generic type-kind mismatch sentinel.","triggerScenarios":"Calling udfContext.newTupleValue() or newArgTupleValue(index/name) where the argument's type is not a CQL tuple — e.g. a UDT, collection, or scalar.","commonSituations":"UDF code written for tuple arguments being reused on UDT arguments (both are composite, easy to confuse); argument index off-by-one after editing the function signature.","solutions":["Use newTupleValue/newArgTupleValue only for arguments declared as tuple<...> in CREATE FUNCTION","For UDT arguments use newUDTValue/newArgUDTValue instead","Double-check the argument index or name against the function's declared argument list"],"exampleFix":"// before\nTupleValue tv = context.newArgTupleValue(\"udt_arg\");\n// after\nUDTValue uv = context.newArgUDTValue(\"udt_arg\");","handlingStrategy":"type-guard","validationCode":"// Only request tuple values for tuple-typed arguments:\nif (!(argType instanceof TupleType)) throw new IllegalArgumentException(\"arg is not a tuple: \" + argType);","typeGuard":"boolean isTuple(DataType t) { return t instanceof TupleType; }","tryCatchPattern":"try { TupleValue tv = ctx.newArgTupleValue(i); }\ncatch (IllegalStateException e) {\n  if (e.getMessage().contains(\"not a tuple\")) { /* use UDT/collection accessor as appropriate */ }\n  else throw e;\n}","preventionTips":["Distinguish tuple<...> from UDTs in the function signature before choosing an accessor","Validate argument names/indices against the declared CREATE FUNCTION list"],"tags":["udf","tuple","type-mismatch","state"],"backgroundTag":"type-mismatch","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}