Uploaded image for project: 'Apache Cassandra Java driver'
  1. Apache Cassandra Java driver
  2. CASSJAVA-3

Select Query Builder puts 'Limit' and 'Per Partition Limit' in the wrong order

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Normal
    • Resolution: Fixed
    • 4.19.3
    • None
    • None

    Description

      Using the QueryBuilder to build a statement that uses both Partition Limit and Limit results in an invalid query. The order of the literals in the generated query places Limit before Partition Limit, which is the inverse of what is should be.

      Sample of the invalid query that was generated by the Query Builder and executed in CqlSh:

      cassandra@cqlsh:project> select "token"(organization_id,environment_id,feature),feature,organization_id,environment_id,enabled  from features WHERE token(organization_id,environment_id,feature)>=-9223372036854775808 LIMIT 5 PER PARTITION LIMIT 1;
      SyntaxException: line 1:199 mismatched input 'PER' expecting EOF (...,feature)>=-9223372036854775808 LIMIT 5 [PER]...)

      This is what the query should have been:

      cassandra@cqlsh:project> select "token"(organization_id,environment_id,feature),feature,organization_id,environment_id,enabled  from features WHERE token(organization_id,environment_id,feature)>=-9223372036854775808 PER PARTITION LIMIT 1 LIMIT 1;
      
       system.token(organization_id, environment_id, feature) | feature | organization_id | environment_id | enabled
      --------------------------------------------------------+---------+-----------------+----------------+---------(0 rows)
      

       

       

      As documented for Select - limit should follow per partition limit.

      Syntax:
      <select-stmt> ::= SELECT ( JSON )? <select-clause>
      FROM <tablename>
      ( WHERE <where-clause> )?
      ( GROUP BY <group-by>)?
      ( ORDER BY <order-by> )?
      ( PER PARTITION LIMIT <integer> )?
      ( LIMIT <integer> )?
      ( ALLOW FILTERING )?
       

      It looks to be a very minor fix in the code - attached patch and test to verify the issue:

       

      First discovered the issue in version 4.18.1 - still exists in 4.18.2-SNAPSHOT

       

      Attachments

        1. queryBuilder.patch
          2 kB
          David Stringer

        Issue Links

          Activity

            People

              Unassigned Unassigned
              stringaling David Stringer
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 1h
                  1h