Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started

 

question

bobdoe avatar image
bobdoe asked ·

How do I define operators for columns with UDT?

We are trying to create a few custom data types. Based on our findings, we see that Cassandra supports creating User-Defined Types (UDT) using CQL. However, we do not see any support for creating operators like +,-,*,<,>,= on top custom data types for table columns.

We have the following queries regarding extending the Cassandra database:

How to define operators like +,-,*,<,> for columns with UDT?

Is it possible to define indexes for UDT columns using a custom comparison function?

[UPDATE] Our goal is to create User-Defined Functions using custom JAVA classes.

Here is an example of what I intend to do:

Step 1: Create a UDT called "Point"

CREATE TYPE Point (
    X int,
    Y int
);

Step 2: Create a table with columns of datatype "Point"

CREATE TABLE lineCoordinate (
    start Point,
    end Point
)

Step 3: Create support for queries "SELECT end-start from lineCoordinate"I have the following queries:

a) Is it possible to Create a UDF using custom JAVA class

Example:

public class LineCoordinate {
    public static int getDifference(Point p1,Point p2) {
        return p2.X - p1.X;
    }
}

Compile this code into MyTest.jar

b) How to install MyTest.jar into Cassandra and create a UDF using CQL? What versions of Cassandra support using an external jar file.

c) How to create custom operator " - " for UDT (point) ?

user-defined typeuser-defined function
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

Erick Ramirez avatar image
Erick Ramirez answered ·

It isn't readily obvious to me what you're trying to achieve. It would really help if you provide examples of what you are doing or what it should look like.

Sample records/data would also be really helpful for us to be able to make a meaningful response.

If I may just add, I would recommend that you try to stick to native CQL data types stored in standard tables where possible if you are new to Cassandra since UDT is an advanced topic. Of course, there are use cases more suited to UDTs but using native types where applicable is a safer approach that custom implementations. Cheers!

[UPDATE] Yes, you can define a function that executes a custom Java class. This has been available since Cassandra 2.2 (CASSANDRA-7395, CASSANDRA-7562). We recommend that you only develop on C* 3.11 since all earlier major versions will be marked as end-of-life when C* 4.0 is eventually released in the coming months.

For details of where to install the JAR as well as sample implementations, see:

2 comments Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

[Posted update in original question]

[Post converted to a comment since it's not an "answer"]

0 Likes 0 · ·

Request you to kindly check the update to the question

0 Likes 0 · ·