CQL Heuristics Calculator#1620
Conversation
|
|
||
| import java.util.*; | ||
|
|
||
| public class CassandraHeuristicsCalculator { |
|
|
||
| private final CassandraOperationEvaluator evaluator = new CassandraOperationEvaluator(); | ||
|
|
||
| public double computeDistance(String cqlQuery, Iterable<Map<String, Object>> allRows) { |
There was a problem hiding this comment.
add an abstraction for allRows.
|
|
||
| private enum ComparisonType { EQUALS, GT, GTE, LT, LTE } | ||
|
|
||
| public Truthness evaluate(CqlQueryOperation op, Map<String, Object> row) { |
|
|
||
| import static org.evomaster.client.java.controller.cassandra.CassandraHeuristicsCalculator.*; | ||
|
|
||
| public class CassandraOperationEvaluator { |
| return any(op.getValue(), toElementList(rawCol)); | ||
| } | ||
|
|
||
| private Truthness evaluateContainsKey(ContainsKeyOperation<?> op, Map<String, Object> row) { |
|
|
||
| public Truthness evaluate(CqlQueryOperation op, Map<String, Object> row) { | ||
| if (op instanceof AndOperation) | ||
| return evaluateAnd((AndOperation) op, row); |
There was a problem hiding this comment.
add {...} for each if. Avoid one if-liners.
|
|
||
| private static String normalizeColumnName(String name) { | ||
| if (name == null) return null; | ||
| if (name.startsWith("\"") && name.endsWith("\"")) { |
There was a problem hiding this comment.
replace " with constant value
| return Collections.emptyList(); | ||
| } | ||
|
|
||
| private static String normalizeColumnName(String name) { |
There was a problem hiding this comment.
add Javadoc explaining what normalization means for a column name
| this.nanos = nanos; | ||
| } | ||
|
|
||
| public static CqlDurationLiteral parse(String text) { |
There was a problem hiding this comment.
Move this code to a specific parser for this format.
| ); | ||
| } | ||
|
|
||
| public static Truthness getStringEqualityTruthness(String a, String b) { |
There was a problem hiding this comment.
This method seems to be a duplicate of SqlExpressionEvaluator.getEqualityTruthness(). Please check if this is indeed a duplicate. If it is, refactor SqlExpressionEvaluator.getEqualityTruthness() to use this method. Also add a Javadoc to explain what this method does.
There was a problem hiding this comment.
It was indeed a duplicate! Now both evaluators use this method
- Small refactorings to follow dev guidelines - Refactor parsing of Duration literals and reorganise packages - Unify distance calculation for strings - Refactor operation evaluator - Add javadoc for calculator and CassandraRow abstraction
- More refactorings in parser utils - Add missing docs in parser utils
Added CassandraHeuristicsCalculator/CassandraOperationEvaluator to compute a distance heuristic for CQL WHERE clauses
Distance calculation for each operator/data type follows the spec from this document