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

Fix CQL3 loose type validation of constants

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Low
    • Resolution: Fixed
    • 1.2.2
    • None
    • None
    • Low

    Description

      This works as it should.

      cqlsh:movies> select * from users where token (username) > token('') ;
      
       username  | created_date | email | firstname | lastname | password
      -----------+--------------+-------+-----------+----------+----------
          bsmith |         null |  null |       bob |    smith |     null
       scapriolo |         null |  null |    stacey | capriolo |     null
       ecapriolo |         null |  null |    edward | capriolo |     null
      
      cqlsh:movies> select * from users where token (username) > token('bsmith') ;
      
       username  | created_date | email | firstname | lastname | password
      -----------+--------------+-------+-----------+----------+----------
       scapriolo |         null |  null |    stacey | capriolo |     null
       ecapriolo |         null |  null |    edward | capriolo |     null
      
      cqlsh:movies> select * from users where token (username) > token('scapriolo') ;
      
       username  | created_date | email | firstname | lastname | password
      -----------+--------------+-------+-----------+----------+----------
       ecapriolo |         null |  null |    edward | capriolo |     null
      
      

      But look what happens when you supply numbers into the token function.

      qlsh:movies> select * from users where token (username) > token(0) ;
       username  | created_date | email | firstname | lastname | password
      -----------+--------------+-------+-----------+----------+----------
       ecapriolo |         null |  null |    edward | capriolo |     null
      cqlsh:movies> select * from users where token (username) > token(1134314) ;
      
       username  | created_date | email | firstname | lastname | password
      -----------+--------------+-------+-----------+----------+----------
          bsmith |         null |  null |       bob |    smith |     null
       scapriolo |         null |  null |    stacey | capriolo |     null
       ecapriolo |         null |  null |    edward | capriolo |     null
      
      cqlsh:movies> select * from users where token (username) > token(113431431) ;
       username  | created_date | email | firstname | lastname | password
      -----------+--------------+-------+-----------+----------+----------
       scapriolo |         null |  null |    stacey | capriolo |     null
       ecapriolo |         null |  null |    edward | capriolo |     null
      
      cqlsh:movies> select * from users where token (username) > token(1134) ;
       username  | created_date | email | firstname | lastname | password
      -----------+--------------+-------+-----------+----------+----------
       ecapriolo |         null |  null |    edward | capriolo |     null
      cqlsh:movies> select * from users where token (username) > token(1134434) ;
       username  | created_date | email | firstname | lastname | password
      -----------+--------------+-------+-----------+----------+----------
       scapriolo |         null |  null |    stacey | capriolo |     null
      

      This does not make sense to me. The token function is apparently converting integers to strings leading to seemingly unpredictable results.

      However I find this syntax odd, I feel like I should be able to say
      'token(username) > 0 and token(username) < 10' because from a thrift side I can page tokens or I can page keys. In this case, I guess, I am only able to page keys because the token is not returned to the user.

      Is token 0 = ''? How do I arrive at the minimal token for and int column.

      Should the token() function at least be smart enough to reject integers for string columns?

      Attachments

        1. 0001-Respect-CQL3-constant-types.txt
          54 kB
          Sylvain Lebresne
        2. 0002-Improve-printing-of-type-in-error-message.txt
          33 kB
          Sylvain Lebresne
        3. 0003-Respect-partitioner-type-for-Token-function.txt
          9 kB
          Sylvain Lebresne

        Activity

          People

            slebresne Sylvain Lebresne
            appodictic Edward Capriolo
            Sylvain Lebresne
            Aleksey Yeschenko
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: