[
https://issues.apache.org/jira/browse/CASSANDRA-10840?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15138641#comment-15138641
]
Benjamin Lerer commented on CASSANDRA-10840:
--------------------------------------------
{quote}I propose to just patch 2.2 and leave 3.0+ alone but add the unit test.
WDYT?{quote}
The result of the SELECT query for the INITCOND, within the unit tests, seems
different between 2.2 and 3.0+ ( ByteBuffer.allocate(4) in 2.2 and "[]" in
3.0+).
Otherwise, I think we can simplify the test to something like that:
{code}
@Test
public void testOrReplaceOptionals() throws Throwable
{
String fState = createFunction(KEYSPACE,
"list, int",
"CREATE FUNCTION %s(s list<text>, i int)
" +
"CALLED ON NULL INPUT " +
"RETURNS list<text> " +
"LANGUAGE java " +
"AS 'if (i != null)
s.add(String.valueOf(i)); return s;'");
String fFinal = shortFunctionName(createFunction(KEYSPACE,
"list, int",
"CREATE FUNCTION %s(s
list<text>) " +
"CALLED ON NULL INPUT
" +
"RETURNS list<text> " +
"LANGUAGE java " +
"AS 'return s;'"));
String a = createAggregate(KEYSPACE,
"int",
"CREATE AGGREGATE %s(int) " +
"SFUNC " + shortFunctionName(fState) + ' ' +
"STYPE list<text> ");
checkOptionals(a, null, null);
String ddlPrefix = "CREATE OR REPLACE AGGREGATE " + a + "(int) " +
"SFUNC " + shortFunctionName(fState) + ' ' +
"STYPE list<text> ";
// Test replacing INITCOND
for (String condition : new String[]{"", "INITCOND null"})
{
execute(ddlPrefix + "INITCOND [ ] ");
checkOptionals(a, null, ByteBuffer.allocate(4));
execute(ddlPrefix + condition);
checkOptionals(a, null, null);
}
// Test replacing FINALFUNC
execute(ddlPrefix + "FINALFUNC " + shortFunctionName(fFinal) + " ");
checkOptionals(a, shortFunctionName(fFinal), null);
execute(ddlPrefix);
checkOptionals(a, null, null);
}
private void checkOptionals(String aggregateName, String finalFunc,
ByteBuffer initCond) throws Throwable
{
assertRows(execute("SELECT final_func, initcond FROM
system.schema_aggregates WHERE keyspace_name=? AND aggregate_name=?", KEYSPACE,
shortFunctionName(aggregateName)),
row(finalFunc, initCond));
}
{code}
As there are no interactions between INITCOND and final Function, I do not
think that we need to test all the combinations. It will makes the test run
faster and simpler to understand. What do you think?
> Replacing an aggregate with a new version doesn't reset INITCOND
> ----------------------------------------------------------------
>
> Key: CASSANDRA-10840
> URL: https://issues.apache.org/jira/browse/CASSANDRA-10840
> Project: Cassandra
> Issue Type: Bug
> Components: CQL
> Environment: Observed in Cassandra 2.2.4, though it might be an issue
> in 3.0 as well
> Reporter: Sandeep Tamhankar
> Assignee: Robert Stupp
> Fix For: 2.2.x, 3.0.x, 3.x
>
>
> {code}
> use simplex;
> CREATE FUNCTION state_group_and_sum(state map<int, int>, star_rating
> int)
> CALLED ON NULL INPUT
> RETURNS map<int, int>
> LANGUAGE java
> AS 'if (state.get(star_rating) == null)
> state.put(star_rating, 1); else state.put(star_rating, ((Integer)
> state.get(star_rating)) + 1); return state;';
> CREATE FUNCTION percent_stars(state map<int,int>)
> RETURNS NULL ON NULL INPUT
> RETURNS map<int, int>
> LANGUAGE java AS $$
> Integer sum = 0;
> for(Object k : state.keySet()) {
> sum = sum + (Integer) state.get((Integer) k);
> }
> java.util.Map<Integer, Integer> results = new java.util.HashMap<Integer,
> Integer>();
> for(Object k : state.keySet()) {
> results.put((Integer) k, ((Integer) state.get((Integer) k))*100 / sum);
> }
> return results;
> $$;
> {code}
> {code}
> CREATE OR REPLACE AGGREGATE group_and_sum(int)
> SFUNC state_group_and_sum
> STYPE map<int, int>
> FINALFUNC percent_stars
> INITCOND {}
> {code}
> 1. View the aggregates
> {{select * from system.schema_aggregates;}}
> 2. Now update
> {code}
> CREATE OR REPLACE AGGREGATE group_and_sum(int)
> SFUNC state_group_and_sum
> STYPE map<int, int>
> FINALFUNC percent_stars
> INITCOND NULL
> {code}
> 3. View the aggregates
> {{select * from system.schema_aggregates;}}
> Expected result:
> * The update should have made initcond null
> Actual result:
> * The update did not touch INITCOND.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)