Details

      Description

      There are several projects using custom secondary indexes as an extension point to integrate C* with other systems such as Solr or Lucene. The usual approach is to embed third party indexing queries in CQL clauses.

      For example, DSE Search embeds Solr syntax this way:

      SELECT title FROM solr WHERE solr_query='title:natio*';
      

      Stratio platform embeds custom JSON syntax for searching in Lucene indexes:

      SELECT * FROM tweets WHERE lucene='{
          filter : {
              type: "range",
              field: "time",
              lower: "2014/04/25",
              upper: "2014/04/1"
          },
          query  : {
              type: "phrase", 
              field: "body", 
              values: ["big", "data"]
          },
          sort  : {fields: [ {field:"time", reverse:true} ] }
      }';
      

      Tuplejump Stargate also uses the Stratio's open source JSON syntax:

      SELECT name,company FROM PERSON WHERE stargate ='{
          filter: {
              type: "range",
              field: "company",
              lower: "a",
              upper: "p"
          },
          sort:{
             fields: [{field:"name",reverse:true}]
          }
      }';
      

      These syntaxes are validated by the corresponding 2i implementation. This validation is done behind the StorageProxy command distribution. So, far as I know, there is no way to give rich feedback about syntax errors to CQL users.

      I'm uploading a patch with some changes trying to improve this. I propose adding an empty validation method to SecondaryIndexSearcher that can be overridden by custom 2i implementations:

      public void validate(List<IndexExpression> clause) {}
      

      And call it from SelectStatement#getRangeCommand:

      ColumnFamilyStore cfs = Keyspace.open(keyspace()).getColumnFamilyStore(columnFamily());
              for (SecondaryIndexSearcher searcher : cfs.indexManager.getIndexSearchersForQuery(expressions))
              {
      
                  try
                  {
                      searcher.validate(expressions);
                  }
                  catch (RuntimeException e)
                  {
                      String exceptionMessage = e.getMessage();
                      if (exceptionMessage != null 
                              && !exceptionMessage.trim().isEmpty())
                          throw new InvalidRequestException(
                                  "Invalid index expression: " + e.getMessage());
                      else
                          throw new InvalidRequestException(
                                  "Invalid index expression");
                  }
              }
      

      In this way C* allows custom 2i implementations to give feedback about syntax errors.

      We are currently using these changes in a fork with no problems.

        Attachments

        1. 2i_validation.patch
          3 kB
          Andrés de la Peña
        2. 2i_validation_v2.patch
          5 kB
          Andrés de la Peña
        3. 2i_validation_v3.patch
          5 kB
          Andrés de la Peña
        4. 2i_validation_v4.patch
          12 kB
          Sergio Bossa

          Issue Links

            Activity

              People

              • Assignee:
                adelapena Andrés de la Peña
                Reporter:
                adelapena Andrés de la Peña
                Reviewer:
                Sergio Bossa
              • Votes:
                8 Vote for this issue
                Watchers:
                10 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: