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

Provide error message for invalid token() parameters

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Low
    • Resolution: Unresolved
    • Fix Version/s: None
    • Component/s: Legacy/CQL, Legacy/Tools
    • Labels:
      None
    • Severity:
      Low

      Description

      Currently, there are few issues with the token() function validation.
      First one:

      It is possible to call the function with a wrong number of arguments, which could lead to a Null Pointer Exception.
      Here is an example:

      > CREATE TABLE test(k1 text, k2 text, PRIMARY KEY((k1, k2)));
      > INSERT INTO test(k1, k2) VALUES('foo', 'bar');
      > SELECT token(k1) FROM test;
      ServerError: java.lang.NullPointerException
      

      The fix is trivial, here is an example: https://github.com/apache/cassandra/compare/trunk...AlexDenisov:token_crash

      However, it uncovers the second issue.
      The token function can be called either without parameters or with N parameters (where N = # of partition keys). The patch would not allow this to happen.
      The same goes for a function call validation as a part of where clause:

      > SELECT * FROM test where token(k1, k2) > token();
      InvalidRequest: Error from server: code=2200 [Invalid query] message="Incorrect number of arguments specified for function system.token : (text, text) -> bigint (expected 2, found 0)"
      

      I do not see any obvious solution here. Since the token() function is special I could only suggest extending the `Function` class with an additional method (e.g. isTokenFunction()), and validate the number of passed parameters accordingly.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              AlexDenisov Alex Denisov
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: