use of org.apache.drill.common.expression.LogicalExpression in project drill by apache.
the class MongoPushDownFilterForScan method onMatch.
@Override
public void onMatch(RelOptRuleCall call) {
final ScanPrel scan = (ScanPrel) call.rel(1);
final FilterPrel filter = (FilterPrel) call.rel(0);
final RexNode condition = filter.getCondition();
MongoGroupScan groupScan = (MongoGroupScan) scan.getGroupScan();
if (groupScan.isFilterPushedDown()) {
return;
}
LogicalExpression conditionExp = DrillOptiq.toDrill(new DrillParseContext(PrelUtil.getPlannerSettings(call.getPlanner())), scan, condition);
MongoFilterBuilder mongoFilterBuilder = new MongoFilterBuilder(groupScan, conditionExp);
MongoScanSpec newScanSpec = mongoFilterBuilder.parseTree();
if (newScanSpec == null) {
// no filter pushdown so nothing to apply.
return;
}
MongoGroupScan newGroupsScan = null;
try {
newGroupsScan = new MongoGroupScan(groupScan.getUserName(), groupScan.getStoragePlugin(), newScanSpec, groupScan.getColumns());
} catch (IOException e) {
logger.error(e.getMessage(), e);
throw new DrillRuntimeException(e.getMessage(), e);
}
newGroupsScan.setFilterPushedDown(true);
final ScanPrel newScanPrel = ScanPrel.create(scan, filter.getTraitSet(), newGroupsScan, scan.getRowType());
if (mongoFilterBuilder.isAllExpressionsConverted()) {
/*
* Since we could convert the entire filter condition expression into an
* Mongo filter, we can eliminate the filter operator altogether.
*/
call.transformTo(newScanPrel);
} else {
call.transformTo(filter.copy(filter.getTraitSet(), ImmutableList.of((RelNode) newScanPrel)));
}
}
use of org.apache.drill.common.expression.LogicalExpression in project drill by apache.
the class DrillAggregateRel method toDrill.
public static LogicalExpression toDrill(AggregateCall call, List<String> fn, DrillImplementor implementor) {
List<LogicalExpression> args = Lists.newArrayList();
for (Integer i : call.getArgList()) {
args.add(new FieldReference(fn.get(i)));
}
// for count(1).
if (args.isEmpty()) {
args.add(new ValueExpressions.LongExpression(1l));
}
LogicalExpression expr = FunctionCallFactory.createExpression(call.getAggregation().getName().toLowerCase(), ExpressionPosition.UNKNOWN, args);
return expr;
}
use of org.apache.drill.common.expression.LogicalExpression in project drill by apache.
the class CompareFunctionsProcessor method process.
public static CompareFunctionsProcessor process(FunctionCall call, boolean nullComparatorSupported) {
String functionName = call.getName();
LogicalExpression nameArg = call.args.get(0);
LogicalExpression valueArg = call.args.size() >= 2 ? call.args.get(1) : null;
CompareFunctionsProcessor evaluator = new CompareFunctionsProcessor(functionName);
if (valueArg != null) {
// binary function
if (VALUE_EXPRESSION_CLASSES.contains(nameArg.getClass())) {
LogicalExpression swapArg = valueArg;
valueArg = nameArg;
nameArg = swapArg;
evaluator.functionName = COMPARE_FUNCTIONS_TRANSPOSE_MAP.get(functionName);
}
evaluator.success = nameArg.accept(evaluator, valueArg);
} else if (nullComparatorSupported && call.args.get(0) instanceof SchemaPath) {
evaluator.success = true;
evaluator.path = (SchemaPath) nameArg;
}
return evaluator;
}
use of org.apache.drill.common.expression.LogicalExpression in project drill by apache.
the class CompareFunctionsProcessor method process.
public static CompareFunctionsProcessor process(FunctionCall call, boolean nullComparatorSupported) {
String functionName = call.getName();
LogicalExpression nameArg = call.args.get(0);
LogicalExpression valueArg = call.args.size() >= 2 ? call.args.get(1) : null;
CompareFunctionsProcessor evaluator = new CompareFunctionsProcessor(functionName);
if (valueArg != null) {
// binary function
if (VALUE_EXPRESSION_CLASSES.contains(nameArg.getClass())) {
LogicalExpression swapArg = valueArg;
valueArg = nameArg;
nameArg = swapArg;
evaluator.functionName = COMPARE_FUNCTIONS_TRANSPOSE_MAP.get(functionName);
}
evaluator.success = nameArg.accept(evaluator, valueArg);
} else if (nullComparatorSupported && call.args.get(0) instanceof SchemaPath) {
evaluator.success = true;
evaluator.path = (SchemaPath) nameArg;
}
return evaluator;
}
use of org.apache.drill.common.expression.LogicalExpression in project drill by apache.
the class CompareFunctionsProcessor method process.
public static CompareFunctionsProcessor process(FunctionCall call) {
String functionName = call.getName();
LogicalExpression nameArg = call.args.get(0);
LogicalExpression valueArg = call.args.size() >= 2 ? call.args.get(1) : null;
CompareFunctionsProcessor evaluator = new CompareFunctionsProcessor(functionName);
//if (valueArg != null) {
if (VALUE_EXPRESSION_CLASSES.contains(nameArg.getClass())) {
LogicalExpression swapArg = valueArg;
valueArg = nameArg;
nameArg = swapArg;
evaluator.functionName = COMPARE_FUNCTIONS_TRANSPOSE_MAP.get(functionName);
}
evaluator.success = nameArg.accept(evaluator, valueArg);
return evaluator;
}
Aggregations