Hello - I am experimenting with User Defined Functions in Cassandra (3.3) and I am a bit puzzled by a problem I am having when testing them with cqlsh. I have tried to find the answers online, but have not had any luck so far.
According to http://cassandra.apache.org/doc/cql3/CQL.html it looks like a UDF (User Defined Function) should be useable in an update: UPDATE atable SET col = some_function(?) ...; Current test environment: cassandra@cqlsh:test_space> show version; [cqlsh 5.0.1 | Cassandra 3.3 | CQL spec 3.4.0 | Native protocol v4] However, using a value from the row in question as an argument to the UDF does not seem to work. Here is how I am testing: CREATE KEYSPACE test_space WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'}; USE test_space; CREATE TABLE test_table (idx text, data int, PRIMARY KEY( idx )); INSERT INTO test_table(idx,data) VALUES( 'abc', 1 ); CREATE FUNCTION max_int( a int, b int ) CALLED ON NULL INPUT RETURNS int LANGUAGE java AS 'return (a == null || b == null) ? 0 : ( a > b ? a : b);'; SELECT * FROM test_table; UPDATE test_table SET data=max_int(3,4) WHERE idx='abc’; ---- This works SELECT * FROM test_table; UPDATE test_table SET data=max_int(data,5) WHERE idx='abc’; ---- This does not work Results: SyntaxException: <ErrorMessage code=2000 [Syntax error in CQL query] message="line 1:39 no viable alternative at input ',' (UPDATE test_table SET data=max_int([data],...)"> So I am wondering if I am missing something here - or if this is just a problem with testing with cqlsh. If a UDF is not allowed to be passed a value from the row that is being updated, then what exactly is the use case for having a UDF in an UPDATE? If all arguments to the UDF have to be supplied by the client, then the client might as well perform the function. Using a UDF in an UPDATE would seem to make the most sense only if the row data could be accessed, since it could be used to bypass the need for a SELECT by a client to read the values and perform the operation on them before doing the UPDATE. Thank you, Kim Liu -------- Kim Liu Sr. Software Engineer k...@edgewaternetworks.com _______ “Nothing in the world is more dangerous than sincere ignorance and conscientious stupidity.” -- Martin Luther King Jr.