Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinhinterlong committed Jul 19, 2017
1 parent c82014d commit 4c2edb1
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.apache.calcite.util.ReflectUtil;
import org.apache.calcite.util.ReflectiveVisitor;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;
Expand All @@ -31,14 +30,12 @@
*/
public class FilterEvaluator implements ReflectiveVisitor {
private RelBuilder builder;
private final List<String> dimensions;
private final ReflectUtil.MethodDispatcher<RexNode> dispatcher;

/**
* Constructor.
*/
public FilterEvaluator() {
dimensions = new ArrayList<>();
dispatcher = ReflectUtil.createMethodDispatcher(
RexNode.class,
this,
Expand All @@ -47,22 +44,6 @@ public FilterEvaluator() {
);
}

/**
* Finds all the dimension names used in the filter.
*
* @param builder The RelBuilder used to build queries with Calcite.
* @param filter The filter to be evaluated.
*
* @return a list of all the dimension names.
*
* @throws UnsupportedOperationException for filters which couldn't be evaluated.
*/
public List<String> getDimensionNames(RelBuilder builder, Filter filter) {
// todo could use DataApiRequest instead and simplify this class
RexNode rexNode = evaluateFilter(builder, filter);
return dimensions.stream().distinct().collect(Collectors.toList());
}

/**
* Evaluates and builds a filter and finds all the dimension names used in all filters.
*
Expand All @@ -79,7 +60,6 @@ public RexNode evaluateFilter(RelBuilder builder, Filter filter) {
}

this.builder = builder;
dimensions.clear();
return dispatcher.invoke(filter);
}

Expand Down Expand Up @@ -107,7 +87,6 @@ public RexNode evaluate(Filter filter) {
public RexNode evaluate(RegularExpressionFilter regexFilter) {
// todo test this
String apiName = regexFilter.getDimension().getApiName();
dimensions.add(apiName);
return builder.call(
SqlStdOperatorTable.LIKE,
builder.field(apiName),
Expand All @@ -124,7 +103,6 @@ public RexNode evaluate(RegularExpressionFilter regexFilter) {
*/
public RexNode evaluate(SelectorFilter selectorFilter) {
String apiName = selectorFilter.getDimension().getApiName();
dimensions.add(apiName);
return builder.call(
SqlStdOperatorTable.EQUALS,
builder.field(apiName),
Expand All @@ -148,7 +126,6 @@ public RexNode evaluate(SearchFilter searchFilter) {
SearchFilter.QueryType queryType = SearchFilter.QueryType.fromType(searchType);

String columnName = searchFilter.getDimension().getApiName();
dimensions.add(columnName);
String valueToFind = searchFilter.getQuery().get(valueKey);

switch (queryType) {
Expand Down Expand Up @@ -185,7 +162,6 @@ public RexNode evaluate(SearchFilter searchFilter) {
*/
public RexNode evaluate(InFilter inFilter) {
Dimension dimension = inFilter.getDimension();
dimensions.add(dimension.getApiName());

OrFilter orFilterOfSelectors = new OrFilter(
inFilter.getValues()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class DefaultSqlBackedClientSpec extends Specification {
private static final String TRUE = "TRUE"
private static final String FALSE = "FALSE"
private static final String FIRST_COMMENT = "added project"
//this is the first result in the database
// FIRST_COMMENT is the first result in the database
private static final String UNIQUE_COMMENT = "took out (then), added quotation marks"
private static final DruidResponseParser RESPONSE_PARSER = new DruidResponseParser()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,13 @@ class FilterEvaluatorSpec extends Specification {
def "GetDimensionNames expecting #dimensions"() {
setup:
RelBuilder builder = CalciteHelper.getBuilder(Database.getDataSource())
FilterEvaluator filterEvaluator = new FilterEvaluator()
builder.scan(WIKITICKER)
def rexNodes = dimensions.stream()
.map { builder.field(it) }
.collect(Collectors.toList())

expect:
builder.project(rexNodes)
List<String> foundDimensions = filterEvaluator.getDimensionNames(builder, filter)
dimensions.stream().forEach { foundDimensions.contains(it) }
foundDimensions.stream().forEach { dimensions.contains(it) }
String sql = new RelToSqlConverter(SqlDialect.create(CONNECTION.getMetaData())).visitChild(0, builder.build()).
asSelect().
toString();
Expand Down

0 comments on commit 4c2edb1

Please sign in to comment.