5

I was trying

cqlsh:my_keyspace>  CREATE FUNCTION IF NOT EXISTS len(input blob) 

CALLED ON NULL INPUT

RETURNS int LANGUAGE java AS '

return input.length();';

Error:

InvalidRequest: Error from server: code=2200 [Invalid query] message="Java source compilation failed:
Line 2: The method length() is undefined for the type ByteBuffer

if I change input to text it is working..is there anything defined for bytebuffer type ? I need to find length of blob column from table..

is there any way to find out it either in cassandra spark or by any tool ?
I am new to cassandra world please help me out for this..

Alex Ott
  • 80,552
  • 8
  • 87
  • 132
Abhishek A
  • 93
  • 1
  • 5

1 Answers1

3

Under the hood, Cassandra uses the ByteBuffer Java type for its blob data type. This type that doesn't have the length method, so you need to use either position, or remaining to determine how much data in the buffer (depending on what you're doing with it).

This function works fine:

CREATE OR REPLACE FUNCTION blen (b blob) 
   CALLED ON NULL INPUT 
   RETURNS int 
   LANGUAGE java AS 'if (b == null) return 0; else return b.remaining();';
Alex Ott
  • 80,552
  • 8
  • 87
  • 132