You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by "Robert Stupp (JIRA)" <ji...@apache.org> on 2016/08/20 13:51:22 UTC

[jira] [Updated] (CASSANDRA-11052) Cannot use Java 8 lambda expression inside UDF code body

     [ https://issues.apache.org/jira/browse/CASSANDRA-11052?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Robert Stupp updated CASSANDRA-11052:
-------------------------------------
    Reviewer:   (was: Robert Stupp)

> Cannot use Java 8 lambda expression inside UDF code body
> --------------------------------------------------------
>
>                 Key: CASSANDRA-11052
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-11052
>             Project: Cassandra
>          Issue Type: Improvement
>          Components: CQL
>            Reporter: DOAN DuyHai
>            Assignee: Robert Stupp
>             Fix For: 3.x
>
>         Attachments: 11052-2.patch, 11052.patch
>
>
> When creating the following **UDF** using Java 8 lambda syntax
> {code:sql}
>  CREATE FUNCTION IF NOT EXISTS music.udf(state map<text,bigint>, styles list<text>)
>  RETURNS NULL ON NULL INPUT
>  RETURNS map<text,bigint>
>  LANGUAGE java
>  AS $$
>    styles.forEach((Object o) -> {
>        String style = (String)o;
>        if(state.containsKey(style)) {
>             state.put(style, (Long)state.get(style)+1);
>        } else {
>             state.put(style, 1L);   
>        }
>    });
>    
>    return state;
>  $$;
> {code}
>  I got the following exception:
> {code:java}
> Caused by: com.datastax.driver.core.exceptions.InvalidQueryException: Could not compile function 'music.udf' from Java source: org.apache.cassandra.exceptions.InvalidRequestException: Java source compilation failed:
> Line 2: The type java.util.function.Consumer cannot be resolved. It is indirectly referenced from required .class files
> Line 2: The method forEach(Consumer) from the type Iterable refers to the missing type Consumer
> Line 2: The target type of this expression must be a functional interface
> 	at com.datastax.driver.core.Responses$Error.asException(Responses.java:136)
> 	at com.datastax.driver.core.DefaultResultSetFuture.onSet(DefaultResultSetFuture.java:179)
> 	at com.datastax.driver.core.RequestHandler.setFinalResult(RequestHandler.java:184)
> 	at com.datastax.driver.core.RequestHandler.access$2500(RequestHandler.java:43)
> 	at com.datastax.driver.core.RequestHandler$SpeculativeExecution.setFinalResult(RequestHandler.java:798)
> 	at com.datastax.driver.core.RequestHandler$SpeculativeExecution.onSet(RequestHandler.java:617)
> 	at com.datastax.driver.core.Connection$Dispatcher.channelRead0(Connection.java:1005)
> 	at com.datastax.driver.core.Connection$Dispatcher.channelRead0(Connection.java:928)
> 	at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)
> 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:318)
> 	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:304)
> 	at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:266)
> 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:318)
> 	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:304)
> 	at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
> 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:318)
> 	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:304)
> 	at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:276)
> 	at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:263)
> 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:318)
> 	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:304)
> 	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:846)
> 	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)
> 	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511)
> 	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468)
> 	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382)
> 	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354)
> 	at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:112)
> 	... 1 more
> {code}
>  It looks like the compiler requires importing java.util.Consumer but I have checked the source code and compiler options already support Java 8 source code so I'm pretty puzzled here ...
> /cc [~snazy]



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