java.lang.Object
org.evomaster.client.java.controller.cassandra.parser.CqlParserUtils

public class CqlParserUtils extends Object
Utility methods to parse CQL (Cassandra Query Language) commands with the ANTLR-generated CqlParser, and to extract the information needed for heuristics computation (e.g. the WHERE-clause condition tree) from the resulting parse tree.
  • Method Details

    • parseCqlCommand

      public static CqlParser.RootContext parseCqlCommand(String cqlCommand)
      Parses a CQL command string into its ANTLR parse tree, with no validity checks performed on the result (assumes canParseCqlCommand(java.lang.String) was used first).
      Parameters:
      cqlCommand - the CQL command to parse
      Returns:
      the root of the resulting ANTLR parse tree
    • canParseCqlCommand

      public static boolean canParseCqlCommand(String cqlCommand)
      Checks whether cqlCommand can be parsed into a single, well-formed CQL statement.
      Parameters:
      cqlCommand - the CQL command to validate
      Returns:
      true if the command parses cleanly (no parser exception, and exactly one statement is present); false otherwise
    • isSelect

      public static boolean isSelect(String cqlCommand)
      Parameters:
      cqlCommand - the CQL command to inspect
      Returns:
      true if cqlCommand is a SELECT statement
    • isUpdate

      public static boolean isUpdate(String cqlCommand)
      Parameters:
      cqlCommand - the CQL command to inspect
      Returns:
      true if cqlCommand is an UPDATE statement
    • isDelete

      public static boolean isDelete(String cqlCommand)
      Parameters:
      cqlCommand - the CQL command to inspect
      Returns:
      true if cqlCommand is a DELETE statement
    • getWhereSpec

      public static CqlParser.WhereSpecContext getWhereSpec(CqlParser.RootContext root)
      Extracts the WHERE-clause parse-tree node from a parsed CQL SELECT, UPDATE, or DELETE statement.
      Parameters:
      root - the root of a parsed CQL command, as returned by parseCqlCommand(java.lang.String)
      Returns:
      the WHERE clause's parse-tree node, or null if the statement has none (or isn't a SELECT/UPDATE/DELETE)
    • getWhereOperation

      public static CqlQueryOperation getWhereOperation(CqlParser.RootContext root)
      Parses the WHERE clause of a CQL SELECT, UPDATE, or DELETE and returns the corresponding operation tree. Multiple AND-joined conditions are wrapped in an AndOperation; a single condition is returned directly; null is returned when no WHERE clause is present.
    • getTableReference

      public static CqlTableReference getTableReference(CqlParser.RootContext root)
      Extracts the keyspace/table a CQL SELECT, UPDATE, or DELETE statement targets, straight from the parse tree. Unlike a regex over the raw CQL text, this preserves whether an identifier was quoted (and therefore case-sensitive) or not, since the grammar's table/keyspace/fromSpecElement rules match the quote characters as part of the token text.
      Parameters:
      root - the root of a parsed CQL command, as returned by parseCqlCommand(java.lang.String)
      Returns:
      the referenced keyspace/table;
      Throws:
      IllegalArgumentException - if the statement isn't a SELECT/UPDATE/DELETE