Lapo Luchini created CASSANDRA-14923:
----------------------------------------
Summary: Java8 forEach cannot be used in UDF
Key: CASSANDRA-14923
URL: https://issues.apache.org/jira/browse/CASSANDRA-14923
Project: Cassandra
Issue Type: Bug
Environment: FreeBSD 11.2
Cassandra 3.11.3
OpenJDK 8.181.13
Reporter: Lapo Luchini
I get the following error:
{noformat}
cqlsh:test> CREATE OR REPLACE FUNCTION sumMap (state map<text, int>, val
map<text, int>)
... RETURNS NULL ON NULL INPUT
... RETURNS map<text, int>
... LANGUAGE java AS
... $$
... val.forEach((k, v) -> {
... Integer cur = state.get(k);
... state.put(k, (cur == null) ? v : cur + v);
... });
... return state;
... $$;
InvalidRequest: Error from server: code=2200 [Invalid query] message="Java
source compilation failed:
Line 2: The type java.util.function.BiConsumer cannot be resolved. It is
indirectly referenced from required .class files
Line 2: The method forEach(BiConsumer<? super String,? super Integer>) from the
type Map<String,Integer> refers to the missing type BiConsumer
Line 2: The target type of this expression must be a functional interface
"
{noformat}
on the other hand, this compiles correctly:
{noformat}
CREATE OR REPLACE FUNCTION sumMap (state map<text, int>, val map<text, int>)
RETURNS NULL ON NULL INPUT
RETURNS map<text, int>
LANGUAGE java AS
$$
for (Map.Entry<String, Integer> e : val.entrySet()) {
String k = e.getKey();
Integer v = e.getValue();
Integer cur = state.get(k);
state.put(k, (cur == null) ? v : cur + v);
};
return state;
$$;
{noformat}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]