You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by "DOAN DuyHai (JIRA)" <ji...@apache.org> on 2015/12/01 17:06:11 UTC

[jira] [Comment Edited] (CASSANDRA-10783) Allow literal value as parameter of UDF & UDA

    [ https://issues.apache.org/jira/browse/CASSANDRA-10783?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15033604#comment-15033604 ] 

DOAN DuyHai edited comment on CASSANDRA-10783 at 12/1/15 4:05 PM:
------------------------------------------------------------------

Ok, I understand the issue now, some ideas:

1. Either we just forbid overloading for UDF/UDA and the issue is solved naturally. After all method overloading is not absolutely necessary (Scala can live without it). At worst, users can give a different name to their UDF/UDA.

2. If we want to keep method overloading, what's about this syntax ?

{code:sql}
SELECT maxOf(val, 101 as varyint) FROM ...
{code}

 The *as varyint* is optional to allow disambiguation. In the presence of overloaded UDF/UDA, if the user does not specify the type with the *AS* syntax, we can throw an exception.


was (Author: doanduyhai):
Ok, I understand the issue now, some ideas:

1. Either we just forbid overloading for UDF/UDA and the issue is solved naturally. After all method overloading is not absolutely necessary (Scala can live without it). At worst, users can give a different name to their UDF/UDA.

2. If we want to keep method overloading, what's about this syntax ?

{code:sql}
SELECT maxOf(val, 101 as varyint) FROM ...
{code}

 The *as varyint* is optional to allow disambiguation. In the presence of overloaded UDF/UDA, if the user does specify the type with the *AS* syntax, we can throw an exception.

> 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)