Hi, I already posted an answer for your question on https://community.datastax.com/ but since you asked here as well:
1) When I call the aggregate, I would like to pass sample_size with a > sub-query [..] Is that possible with Cassandra? No. 2) When I try to register the bloomfilter_uda, I get the following error > [...] Can I just pass Cassandra data types as a state (map, list, set)? Yes, but you need to input a valid literal for your UDT by initializing at least one field: CREATE OR REPLACE AGGREGATE bloomfilter_uda ( text, int ) SFUNC bloomfilter_udf STYPE bloomfilter_udt INITCOND { n_as_sample_size : 0 }; This is a subtlety of the CQL parser; if you input just {} the parser would be fooled into thinking that this is a set literal (an empty set) – hence the (rather cryptic) error message. 3) If I assume, all of the above is my bad, how can I access the props of > the state? Inside functions and aggregates, if you need to access or modify a user-defined type, you actually need to use the DataStax Java driver 3.x API for User-defined types <https://docs.datastax.com/en/developer/java-driver/3.9/manual/udts/>: CREATE OR REPLACE FUNCTION bloomfilter_udf ( state bloomfilter_udt, value text, sample_size int ) CALLED ON NULL INPUT RETURNS bloomfilter_udt LANGUAGE java AS $$ state.setInt("n_as_sample_size", 42); state.setInt("m_as_number_of_buckets" 42); state.setLong("p_as_next_prime_above_m", 4242L); List<Long> hashForStringCoefficients = ...; state.setList("hash_for_string_coefficient_a", hashForStringCoefficients, Long.class); // etc. return state; $$ The variable state inside the Java block is of type UDTValue <https://docs.datastax.com/en/drivers/java/3.9/com/datastax/driver/core/UDTValue.html> . Hope that helps. Alex Dutra On Thu, Apr 30, 2020 at 6:36 PM Andreas R. <andreasrimmelspac...@gmail.com> wrote: > Hello > > I am trying to extract sketches (e.g. bloom filter) from some given data. > I came this far, questions below: > > CREATE TYPE bloomfilter_udt( > n_as_sample_size int, > m_as_number_of_buckets int, > p_as_next_prime_above_m bigint, > hash_for_string_coefficient_a list <bigint>, > hash_for_number_coefficients_a list <bigint>, > hash_for_number_coefficients_b list <bigint>, > bloom_filter_as_map map<int, int> > ); > > CREATE OR REPLACE FUNCTION bloomfilter_udf(state bloomfilter_udt, value > text, sample_size int) > CALLED ON NULL INPUT > RETURNS bloomfilter_udt > LANGUAGE java > AS > $$ > //put n_as_sample_size in result > //if(state.getUDTValue("n_as_sample_size") == > null){state.setInt("n_as_sample_size", sample_size);}; > //do some more stuff to the bloomfilter_udt > return state; > $$; > > CREATE OR REPLACE AGGREGATE bloomfilter_uda(text, int) > SFUNC bloomfilter_udf > STYPE bloomfilter_udt > INITCOND {}; > > 1) I would pass the sample_size with a sub-query, e.g. > ==> "SELECT bloomfilter_uda(name, (SELECT count(*) FROM test_table)) FROM > test_table;" <== > Is that possible with Cassandra? > > 2) When I try to register the bloomfilter_uda, I get the following error: > ==> InvalidRequest: Error from server: code=2200 [Invalid query] > message="Invalid set literal for (dummy) of type bloomfilter_udt" <== > Can I just pass Cassandra data types as a state (map, list, set)? > > 3) If I assume, all of the above is my bad, how can I access the props of > the state? Like > ==> state.n_as_sample_size <== > Is this somehow possible? > > I am kind of struggling with Cassandra and I'd appreciate some help. > > Thanks > Andreas > > -- andreasrimmelspac...@gmail.com > >