You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by Drew Kutcharian <dr...@venarc.com> on 2016/08/18 15:52:49 UTC

How to create a TupleType/TupleValue in a UDF

Hi All,

I have a UDF/UDA that returns a map of date -> TupleValue.

CREATE OR REPLACE FUNCTION min_max_by_timestamps_udf(state map<date, frozen<tuple<timestamp, timestamp>>>, flake blob)
RETURNS NULL ON NULL INPUT
RETURNS map<date, frozen<tuple<timestamp, timestamp>>>
LANGUAGE java

CREATE OR REPLACE AGGREGATE min_max_by_timestamps(blob)
SFUNC min_max_by_timestamps_udf
STYPE map<date, frozen<tuple<timestamp, timestamp>>>
INITCOND {};

I’ve been using the following syntax to build the TupleType/TupleValue in my UDF:

TupleType tupleType = TupleType.of(com.datastax.driver.core.ProtocolVersion.NEWEST_SUPPORTED, CodecRegistry.DEFAULT_INSTANCE, DataType.timestamp(), DataType.timestamp());
tupleType.newValue(new java.util.Date(timestamp), new java.util.Date(timestamp)));

But “randomly" I get errors like the following:
FunctionFailure: code=1400 [User Defined Function failure] message="execution of ’testdb.min_max_by_timestamps_udf[map<date, frozen<tuple<timestamp, timestamp>>>, blob]' failed: java.security.AccessControlException: access denied ("java.io.FilePermission" "/etc/cassandra/logback.xml" "read”)"

Or CodecNotFoundException for Cassandra not being able to find a codec for "map<date, frozen<tuple<timestamp, timestamp>>>”.

Is this a bug or I’m doing something wrong?


Thanks,

Drew

Re: How to create a TupleType/TupleValue in a UDF

Posted by Tyler Hobbs <ty...@datastax.com>.
On Thu, Aug 18, 2016 at 12:57 PM, Drew Kutcharian <dr...@venarc.com> wrote:

> I’m running 3.0.8, so it probably wasn’t fixed? ;)
>

Hmm, would you mind opening a new JIRA ticket about that and linking it to
CASSANDRA-11033?


>
> The CodecNotFoundException is very random, when I get it, if I re-run the
> same exact query then it works! I’ll see if I can reproduce it more
> consistently.
>

Thanks.  If you can reproduce, please go ahead and open a ticket for that
as well.


> BTW, is there a way to get the CodecRegistry and the ProtocolVersion from
> the UDF environment so I don’t have to create them?
>

At least in 3.0.8, I don't think so.  It's worth pointing out
https://issues.apache.org/jira/browse/CASSANDRA-10818, which makes it much
easier to create tuples and UDTs in 3.6+.  Check out the bottom of the UDF
section of the docs for some examples and details:
http://cassandra.apache.org/doc/latest/cql/functions.html#user-defined-functions


-- 
Tyler Hobbs
DataStax <http://datastax.com/>

Re: How to create a TupleType/TupleValue in a UDF

Posted by Drew Kutcharian <dr...@venarc.com>.
I’m running 3.0.8, so it probably wasn’t fixed? ;)
[cqlsh 5.0.1 | Cassandra 3.0.8 | CQL spec 3.4.0 | Native protocol v4]

The CodecNotFoundException is very random, when I get it, if I re-run the same exact query then it works! I’ll see if I can reproduce it more consistently. BTW, is there a way to get the CodecRegistry and the ProtocolVersion from the UDF environment so I don’t have to create them?

- Drew


> On Aug 18, 2016, at 10:10 AM, Tyler Hobbs <ty...@datastax.com> wrote:
> 
> The logback-related error is due to https://issues.apache.org/jira/browse/CASSANDRA-11033 <https://issues.apache.org/jira/browse/CASSANDRA-11033>, which is fixed in 3.0.4 and 3.4.
> 
> I'm not sure about the CodecNotFoundException, can you reproduce that one reliably?
> 
> On Thu, Aug 18, 2016 at 10:52 AM, Drew Kutcharian <drew@venarc.com <ma...@venarc.com>> wrote:
> Hi All,
> 
> I have a UDF/UDA that returns a map of date -> TupleValue.
> 
> CREATE OR REPLACE FUNCTION min_max_by_timestamps_udf(state map<date, frozen<tuple<timestamp, timestamp>>>, flake blob)
> RETURNS NULL ON NULL INPUT
> RETURNS map<date, frozen<tuple<timestamp, timestamp>>>
> LANGUAGE java
> 
> CREATE OR REPLACE AGGREGATE min_max_by_timestamps(blob)
> SFUNC min_max_by_timestamps_udf
> STYPE map<date, frozen<tuple<timestamp, timestamp>>>
> INITCOND {};
> 
> I’ve been using the following syntax to build the TupleType/TupleValue in my UDF:
> 
> TupleType tupleType = TupleType.of(com.datastax.driver.core.ProtocolVersion.NEWEST_SUPPORTED, CodecRegistry.DEFAULT_INSTANCE, DataType.timestamp(), DataType.timestamp());
> tupleType.newValue(new java.util.Date(timestamp), new java.util.Date(timestamp)));
> 
> But “randomly" I get errors like the following:
> FunctionFailure: code=1400 [User Defined Function failure] message="execution of ’testdb.min_max_by_timestamps_udf[map<date, frozen<tuple<timestamp, timestamp>>>, blob]' failed: java.security.AccessControlException: access denied ("java.io.FilePermission" "/etc/cassandra/logback.xml" "read”)"
> 
> Or CodecNotFoundException for Cassandra not being able to find a codec for "map<date, frozen<tuple<timestamp, timestamp>>>”.
> 
> Is this a bug or I’m doing something wrong?
> 
> 
> Thanks,
> 
> Drew
> 
> 
> 
> -- 
> Tyler Hobbs
> DataStax <http://datastax.com/>


Re: How to create a TupleType/TupleValue in a UDF

Posted by Tyler Hobbs <ty...@datastax.com>.
The logback-related error is due to
https://issues.apache.org/jira/browse/CASSANDRA-11033, which is fixed in
3.0.4 and 3.4.

I'm not sure about the CodecNotFoundException, can you reproduce that one
reliably?

On Thu, Aug 18, 2016 at 10:52 AM, Drew Kutcharian <dr...@venarc.com> wrote:

> Hi All,
>
> I have a UDF/UDA that returns a map of date -> TupleValue.
>
> CREATE OR REPLACE FUNCTION min_max_by_timestamps_udf(state map<date,
> frozen<tuple<timestamp, timestamp>>>, flake blob)
> RETURNS NULL ON NULL INPUT
> RETURNS map<date, frozen<tuple<timestamp, timestamp>>>
> LANGUAGE java
>
> CREATE OR REPLACE AGGREGATE min_max_by_timestamps(blob)
> SFUNC min_max_by_timestamps_udf
> STYPE map<date, frozen<tuple<timestamp, timestamp>>>
> INITCOND {};
>
> I’ve been using the following syntax to build the TupleType/TupleValue in
> my UDF:
>
> TupleType tupleType = TupleType.of(com.datastax.
> driver.core.ProtocolVersion.NEWEST_SUPPORTED, CodecRegistry.DEFAULT_INSTANCE,
> DataType.timestamp(), DataType.timestamp());
> tupleType.newValue(new java.util.Date(timestamp), new
> java.util.Date(timestamp)));
>
> But “randomly" I get errors like the following:
> FunctionFailure: code=1400 [User Defined Function failure]
> message="execution of ’testdb.min_max_by_timestamps_udf[map<date,
> frozen<tuple<timestamp, timestamp>>>, blob]' failed: java.security.AccessControlException:
> access denied ("java.io.FilePermission" "/etc/cassandra/logback.xml"
> "read”)"
>
> Or CodecNotFoundException for Cassandra not being able to find a codec for
> "map<date, frozen<tuple<timestamp, timestamp>>>”.
>
> Is this a bug or I’m doing something wrong?
>
>
> Thanks,
>
> Drew
>



-- 
Tyler Hobbs
DataStax <http://datastax.com/>