[
https://issues.apache.org/jira/browse/CASSANDRA-10783?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15030905#comment-15030905
]
Robert Stupp edited comment on CASSANDRA-10783 at 11/29/15 1:45 PM:
--------------------------------------------------------------------
--This is doable for 2.2 without being too intrusive.--
EDIT:
I've implemented a quick hack, which allows *constants* as function arguments.
The crux at the moment is that it (mostly) requires an explicit cast, which
looks awkward:
{code}
SELECT maxOf(val, (int)101) FROM maxValue WHERE id=1;
{code}
At parse time, we only know the _weak_ type of a constant
(TEXT/VARINT/DECIMAL/BOOLEAN/UUID/DATE/TIME/etc.). So your example would be
equivalent to
{code}
SELECT maxOf(val, (varint)101) FROM maxValue WHERE id=1;
{code}
(varint is the "best" type match for an integer and is not compatible with
{{int}} ({{Int32Type.isCompatibleWith()}}).
I'm not very convinced to force users to add an explicit cast.
OTOH making it more "intuitive" would might make the statement ambiguous -
especially if you think of overloading your function with something like
{{maxOf(int, bigint)}} or {{maxOf(int, double)}}.
It would be nicer if we also allow bind variables as function arguments. But
that's more complicated - it's doable, of course, but feels too intrusive for
2.2 & 3.0. The restrictions regarding "explicit" types are the same as for
constants.
Altogether this needs more conceptual work to "do it right" - so, it's doable
for 2.2, but I don't feel comfortable with it at the moment (i.e. for 2.2).
was (Author: snazy):
This is doable for 2.2 without being too intrusive.
> Allow literal value as parameter of UDF & UDA
> ---------------------------------------------
>
> Key: CASSANDRA-10783
> URL: https://issues.apache.org/jira/browse/CASSANDRA-10783
> Project: Cassandra
> Issue Type: Improvement
> Components: CQL
> Reporter: DOAN DuyHai
> Assignee: Robert Stupp
> Priority: Minor
> Fix For: 3.x
>
>
> I have defined the following UDF
> {code:sql}
> CREATE OR REPLACE FUNCTION maxOf(current int, testValue int) RETURNS NULL ON
> NULL INPUT
> RETURNS int
> LANGUAGE java
> AS 'return Math.max(current,testValue);'
> CREATE TABLE maxValue(id int primary key, val int);
> INSERT INTO maxValue(id, val) VALUES(1, 100);
> SELECT maxOf(val, 101) FROM maxValue WHERE id=1;
> {code}
> I got the following error message:
> {code}
> SyntaxException: <ErrorMessage code=2000 [Syntax error in CQL query]
> message="line 1:19 no viable alternative at input '101' (SELECT maxOf(val1,
> [101]...)">
> {code}
> It would be nice to allow literal value as parameter of UDF and UDA too.
> I was thinking about an use-case for an UDA groupBy() function where the end
> user can *inject* at runtime a literal value to select which aggregation he
> want to display, something similar to GROUP BY ... HAVING <filter clause>
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)