Class CqlParserUtils
java.lang.Object
org.evomaster.client.java.controller.cassandra.parser.CqlParserUtils
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 Summary
Modifier and TypeMethodDescriptionstatic booleancanParseCqlCommand(String cqlCommand) Checks whethercqlCommandcan be parsed into a single, well-formed CQL statement.static CqlTableReferenceExtracts the keyspace/table a CQL SELECT, UPDATE, or DELETE statement targets, straight from the parse tree.static CqlQueryOperationParses the WHERE clause of a CQL SELECT, UPDATE, or DELETE and returns the corresponding operation tree.static CqlParser.WhereSpecContextExtracts the WHERE-clause parse-tree node from a parsed CQL SELECT, UPDATE, or DELETE statement.static booleanstatic booleanstatic booleanstatic CqlParser.RootContextparseCqlCommand(String cqlCommand) Parses a CQL command string into its ANTLR parse tree, with no validity checks performed on the result (assumescanParseCqlCommand(java.lang.String)was used first).
-
Method Details
-
parseCqlCommand
Parses a CQL command string into its ANTLR parse tree, with no validity checks performed on the result (assumescanParseCqlCommand(java.lang.String)was used first).- Parameters:
cqlCommand- the CQL command to parse- Returns:
- the root of the resulting ANTLR parse tree
-
canParseCqlCommand
Checks whethercqlCommandcan be parsed into a single, well-formed CQL statement.- Parameters:
cqlCommand- the CQL command to validate- Returns:
trueif the command parses cleanly (no parser exception, and exactly one statement is present);falseotherwise
-
isSelect
- Parameters:
cqlCommand- the CQL command to inspect- Returns:
trueifcqlCommandis a SELECT statement
-
isUpdate
- Parameters:
cqlCommand- the CQL command to inspect- Returns:
trueifcqlCommandis an UPDATE statement
-
isDelete
- Parameters:
cqlCommand- the CQL command to inspect- Returns:
trueifcqlCommandis a DELETE statement
-
getWhereSpec
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 byparseCqlCommand(java.lang.String)- Returns:
- the WHERE clause's parse-tree node, or
nullif the statement has none (or isn't a SELECT/UPDATE/DELETE)
-
getWhereOperation
Parses the WHERE clause of a CQL SELECT, UPDATE, or DELETE and returns the corresponding operation tree. Multiple AND-joined conditions are wrapped in anAndOperation; a single condition is returned directly; null is returned when no WHERE clause is present. -
getTableReference
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'stable/keyspace/fromSpecElementrules match the quote characters as part of the token text.- Parameters:
root- the root of a parsed CQL command, as returned byparseCqlCommand(java.lang.String)- Returns:
- the referenced keyspace/table;
- Throws:
IllegalArgumentException- if the statement isn't a SELECT/UPDATE/DELETE
-