0

I have a Cassandra table whose one column looks like this

 "ArticlesViewed" frozen<map<int, frozen<list<int>>>>

   and it contains data like 

       ArticlesViewed
       -----------------------------------------------
       {400: [9, 19, 11, 12], 545: [183, 44, 25, 16, 97]}
       {812: [2, 44, 41, 22], 376: [123, 14, 15, 16, 47]}
       {134: [9, 10, 11, 92], 111: [533, 14, 15, 16, 27]}

i want to create index on this column ,to (not allow filtering) on this column but its not allowing me to do so

 cqlsh>CREATE INDEX ON user_profile("ArticlesViewed");

 [Invalid query] message="Cannot create values() index on frozen column ArticlesViewed.
 Frozen collections only support full() indexes"

  Also,i want to query on the <value>  {400: [9, 19, 11, 12],of the column like

 select "ArticlesViewed" from  user_profile where "ArticlesViewed" =19;

please suggest me some ways to do this..any help would be appreciated

s.s
  • 93
  • 2
  • 14

1 Answers1

1

You can't create index on frozen collection element

You have to create full index on frozen collection

Create an index on a full FROZEN collection. An FULL index can be created on a set, list, or map column of a table that doesn't have an existing index.

To index collection entries, you use the FULL keyword and collection name in nested parentheses

For Example :

CREATE INDEX on user_profile(full(articlesviewed));

Using the full index, if you want to query with articlesviewed you have to specified the full collection value. Since it's frozen.

If you have the data :

 userid | articlesviewed
--------+----------------------------------
      1 | {1: [1, 2, 3], 10: [10, 20, 30]}

Your query should contains the full value of articlesviewed

SELECT * FROM user_profile WHERE articlesviewed = {1: [1, 2, 3], 10: [10, 20, 30]};
Community
  • 1
  • 1
Ashraful Islam
  • 12,470
  • 3
  • 32
  • 53
  • thankyou , create full index on frozen collection worked ,how do i query this >> select "ArticlesViewed" from user_profile where "ArticlesViewed" =19; – s.s Oct 30 '17 at 07:48
  • @s.s you can't query like this, you have to change your data model – Ashraful Islam Oct 30 '17 at 08:52
  • If you find the answer helpful, you can accept the answer so that other user may find it useful – Ashraful Islam Oct 31 '17 at 08:23
  • thankyou @Ashraful Islam i changed the data model..can you help me in solving this question -> https://stackoverflow.com/questions/47030798/read-data-from-cassandra-using-java – s.s Oct 31 '17 at 08:25