Skip to content

CQL Heuristics Calculator#1620

Open
gonzalotguerrero wants to merge 14 commits into
masterfrom
feature/cql-heuristics-calculator
Open

CQL Heuristics Calculator#1620
gonzalotguerrero wants to merge 14 commits into
masterfrom
feature/cql-heuristics-calculator

Conversation

@gonzalotguerrero

Copy link
Copy Markdown
Collaborator

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


import java.util.*;

public class CassandraHeuristicsCalculator {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add Javadoc


private final CassandraOperationEvaluator evaluator = new CassandraOperationEvaluator();

public double computeDistance(String cqlQuery, Iterable<Map<String, Object>> allRows) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add an abstraction for allRows.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add Javadoc


private enum ComparisonType { EQUALS, GT, GTE, LT, LTE }

public Truthness evaluate(CqlQueryOperation op, Map<String, Object> row) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add Javadoc for method


import static org.evomaster.client.java.controller.cassandra.CassandraHeuristicsCalculator.*;

public class CassandraOperationEvaluator {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add Javadoc for class

return any(op.getValue(), toElementList(rawCol));
}

private Truthness evaluateContainsKey(ContainsKeyOperation<?> op, Map<String, Object> row) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use abstraction for Row


public Truthness evaluate(CqlQueryOperation op, Map<String, Object> row) {
if (op instanceof AndOperation)
return evaluateAnd((AndOperation) op, row);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add {...} for each if. Avoid one if-liners.


private static String normalizeColumnName(String name) {
if (name == null) return null;
if (name.startsWith("\"") && name.endsWith("\"")) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace " with constant value

return Collections.emptyList();
}

private static String normalizeColumnName(String name) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add Javadoc explaining what normalization means for a column name

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

this.nanos = nanos;
}

public static CqlDurationLiteral parse(String text) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this code to a specific parser for this format.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

);
}

public static Truthness getStringEqualityTruthness(String a, String b) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants