Create Index on UDT

96 views
Skip to first unread message

SathishKumar Alwar

unread,
Aug 12, 2016, 6:47:38 PM8/12/16
to DataStax Java Driver for Apache Cassandra User Mailing List
Hi,

I am new to C*, i am unable to create index on the fields in UDT (User Defined Type). While googling i came across it is not possible to create index on UDT fields individually and there were suggestions to create Materialized Views for these UDT individually. 

Table Schema

Employee
name text,
age int
Project project


UDT Schema
Project
code text,
name text,
startDate timestamp,
endDate timestamp

I want to create index on Project.code to retrieve employees based on Project code.

I tried creating Materialized Views and had no success. Could you please help me in achieving it.

create materialized view emp_view as select name,age,project.code,project.name  from employee primary key(name,project.code);

Thanks and Regards
A.SathishKumar

Kevin Gallardo

unread,
Aug 15, 2016, 8:45:47 AM8/15/16
to java-dri...@lists.datastax.com
Hi, 

Indeed indexing on a UDT's single field is not supported in C* yet, please see https://issues.apache.org/jira/browse/CASSANDRA-6382 for more information.

Concerning MVs I just tried this : 

CREATE TYPE mytype (
    id int,
    value text
)

CREATE TABLE mytable (
    key int PRIMARY KEY,
    mytype frozen<mytype>,
    val text
)


And then creating a materialized view with the UDT (similar to what you've tried) : 

CREATE MATERIALIZED VIEW mv AS SELECT key, val, mytype.id, mytype.value FROM mytable WHERE key IS NOT NULL AND mytype IS NOT NULL PRIMARY KEY (key, mytype);

The error I get is the following :

[Invalid query] message="Cannot select out a part of type when defining a materialized view"

To me it seems that it is explicitly not supported as well in C*. Then it might be worth, if you prefer using a MV, to open a ticket on the Cassandra JIRA and check with the Cassandra team if that is possible.

Cheers.

--
You received this message because you are subscribed to the Google Groups "DataStax Java Driver for Apache Cassandra User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to java-driver-user+unsubscribe@lists.datastax.com.



--
Kévin Gallardo.
Software Engineer in Drivers and Tools Team at DataStax.
 

SathishKumar Alwar

unread,
Aug 15, 2016, 1:33:32 PM8/15/16
to DataStax Java Driver for Apache Cassandra User Mailing List
Hi Kevin,

Thanks for the prompt response. I have created


Thanks and Regards
A.SathishKumar
Reply all
Reply to author
Forward
0 new messages