Uploaded image for project: 'Apache Cassandra'
  1. Apache Cassandra
  2. CASSANDRA-8473

Secondary index support for key-value pairs in CQL3 maps

Agile BoardAttach filesAttach ScreenshotBulk Copy AttachmentsBulk Move AttachmentsVotersWatch issueWatchersCreate sub-taskConvert to sub-taskMoveLinkCloneLabelsUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Normal
    • Resolution: Fixed
    • 2.2.0 beta 1
    • Feature/2i Index
    • None
    • Docs

    Description

      CASSANDRA-4511 and CASSANDRA-6383 made substantial progress on secondary indexes on CQL3 maps, but support for a natural use case is still missing: queries to find rows with map columns containing some key-value pair. For example (from a comment on CASSANDRA-4511):

      SELECT * FROM main.users WHERE notify['email'] = true;
      

      Cassandra should add support for this kind of index. One option is to expose a CQL interface like the following:

      • Creating an index:
        cqlsh:mykeyspace> CREATE TABLE mytable (key TEXT PRIMARY KEY, value MAP<TEXT, TEXT>);
        cqlsh:mykeyspace> CREATE INDEX ON mytable(ENTRIES(value));
        
      • Querying the index:
        cqlsh:mykeyspace> INSERT INTO mytable (key, value) VALUES ('foo', {'a': '1', 'b': '2', 'c': '3'});
        cqlsh:mykeyspace> INSERT INTO mytable (key, value) VALUES ('bar', {'a': '1', 'b': '4'});
        cqlsh:mykeyspace> INSERT INTO mytable (key, value) VALUES ('baz', {'b': '4', 'c': '3'});
        cqlsh:mykeyspace> SELECT * FROM mytable WHERE value['a'] = '1';
        
         key | value
        -----+--------------------------------
         bar |           {'a': '1', 'b': '4'}
         foo | {'a': '1', 'b': '2', 'c': '3'}
        
        (2 rows)
        cqlsh:mykeyspace> SELECT * FROM mytable WHERE value['a'] = '1' AND value['b'] = '2' ALLOW FILTERING;
        
         key | value
        -----+--------------------------------
         foo | {'a': '1', 'b': '2', 'c': '3'}
        
        (1 rows)
        cqlsh:mykeyspace> SELECT * FROM mytable WHERE value['b'] = '2' ALLOW FILTERING;
        
         key | value                         
        -----+--------------------------------
         foo | {'a': '1', 'b': '2', 'c': '3'}
        
        (1 rows)                             
        cqlsh:mykeyspace> SELECT * FROM mytable WHERE value['b'] = '4';
        
         key | value
        -----+----------------------
         bar | {'a': '1', 'b': '4'}
         baz | {'b': '4', 'c': '3'}
        
        (2 rows)
        

      A patch against the Cassandra-2.1 branch that implements this interface will be attached to this issue shortly.

      Attachments

        1. cassandra-2.1-8473.txt
          50 kB
          Samuel Klock
        2. cassandra-2.1-8473-actual-v1.txt
          49 kB
          Samuel Klock
        3. cassandra-2.1-8473-v2.txt
          50 kB
          Samuel Klock
        4. cassandra-2.1-8473-v3.txt
          61 kB
          Samuel Klock
        5. trunk-8473-v2.txt
          51 kB
          Samuel Klock
        6. trunk-8473-v3.txt
          62 kB
          Samuel Klock

        Issue Links

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            sklock Samuel Klock Assign to me
            sklock Samuel Klock
            Samuel Klock
            Tom Hobbs
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment