Zachary Kurey created CASSANDRA-9321:
----------------------------------------

             Summary: Aggregate UDFs allow SFUNC return type to differ from 
STYPE if FFUNC specified
                 Key: CASSANDRA-9321
                 URL: https://issues.apache.org/jira/browse/CASSANDRA-9321
             Project: Cassandra
          Issue Type: Bug
          Components: Core
            Reporter: Zachary Kurey
             Fix For: 3.0


When a final function is specified in an aggregate C* allows the return type of 
the state function to not match the state type.  

Allowing the mismatch if a final function is specified seems to be intentional 
as if you don't provide a final function and you provide a state function with 
a return type that doesn't match the state type, then C* gives you an error 
that states that they must match "unless a final function is specified".  

It seems incorrect regardless of whether or not a final function is present to 
allow the state functions return type to vary from state type.  And indeed if 
you do so it produces an error when you try to use the aggregate.

Here is a simple example that shows the problem:
{code}
CREATE OR REPLACE FUNCTION state_func(state int, p2 int)
RETURNS double LANGUAGE java AS 'return Double.valueOf(1.0);';

CREATE OR REPLACE FUNCTION final_func(state int)
RETURNS int
LANGUAGE java
AS 'return Integer.valueOf(1);';

CREATE OR REPLACE AGGREGATE my_aggregate( int )
SFUNC state_func
STYPE int
FINALFUNC final_func
INITCOND 1;

SELECT my_aggregate(column) FROM table;
{code}

The select produces the error:
{noformat}
Aggregate 'ks.my_aggregate : (int) -> int' exists but hasn't been loaded 
successfully for the following reason: Referenced state function 'ks.state_func 
[double, int]' for aggregate 'ks.my_aggregate' does not exist.
{noformat}

I was reproducing this with 3.0 trunk, though now I just grabbed the latest and 
there is an NPE instead of the error above:
{noformat}
java.lang.NullPointerException: at index 1
        at 
com.google.common.collect.ObjectArrays.checkElementNotNull(ObjectArrays.java:240)
 ~[guava-16.0.jar:na]
        at 
com.google.common.collect.ImmutableSet.construct(ImmutableSet.java:195) 
~[guava-16.0.jar:na]
        at com.google.common.collect.ImmutableSet.of(ImmutableSet.java:116) 
~[guava-16.0.jar:na]
        at 
org.apache.cassandra.cql3.functions.UDAggregate.getFunctions(UDAggregate.java:110)
 ~[main/:na]
        at 
org.apache.cassandra.cql3.selection.AbstractFunctionSelector$1.getFunctions(AbstractFunctionSelector.java:78)
 ~[main/:na]
        at 
org.apache.cassandra.cql3.selection.SelectorFactories.getFunctions(SelectorFactories.java:105)
 ~[main/:na]
{noformat}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to