use of org.apache.drill.common.expression.LogicalExpression in project drill by apache.
the class ParquetFilterBuilder method visitFunctionHolderExpression.
@Override
public LogicalExpression visitFunctionHolderExpression(FunctionHolderExpression funcHolderExpr, Set<LogicalExpression> value) throws RuntimeException {
FuncHolder holder = funcHolderExpr.getHolder();
if (!(holder instanceof DrillSimpleFuncHolder)) {
return null;
}
if (value.contains(funcHolderExpr)) {
ValueHolder result;
try {
result = InterpreterEvaluator.evaluateConstantExpr(udfUtilities, funcHolderExpr);
} catch (Exception e) {
logger.warn("Error in evaluating function of {}", funcHolderExpr.getName());
return null;
}
logger.debug("Reduce a constant function expression into a value expression");
return getValueExpressionFromConst(result, funcHolderExpr.getMajorType().getMinorType());
}
final String funcName = ((DrillSimpleFuncHolder) holder).getRegisteredNames()[0];
if (isCompareFunction(funcName)) {
return handleCompareFunction(funcHolderExpr, value);
}
if (CastFunctions.isCastFunction(funcName)) {
List<LogicalExpression> newArgs = new ArrayList();
for (LogicalExpression arg : funcHolderExpr.args) {
final LogicalExpression newArg = arg.accept(this, value);
if (newArg == null) {
return null;
}
newArgs.add(newArg);
}
return funcHolderExpr.copy(newArgs);
} else {
return null;
}
}
use of org.apache.drill.common.expression.LogicalExpression in project drill by apache.
the class ExpressionTest method getExpressionCode.
// HELPER METHODS //
private String getExpressionCode(String expression, RecordBatch batch) throws Exception {
final LogicalExpression expr = parseExpr(expression);
final ErrorCollector error = new ErrorCollectorImpl();
final LogicalExpression materializedExpr = ExpressionTreeMaterializer.materialize(expr, batch, error, registry);
if (error.getErrorCount() != 0) {
logger.error("Failure while materializing expression [{}]. Errors: {}", expression, error);
assertEquals(0, error.getErrorCount());
}
FunctionImplementationRegistry funcReg = new FunctionImplementationRegistry(DrillConfig.create());
final ClassGenerator<Projector> cg = CodeGenerator.get(Projector.TEMPLATE_DEFINITION, funcReg, null).getRoot();
cg.addExpr(new ValueVectorWriteExpression(new TypedFieldId(materializedExpr.getMajorType(), -1), materializedExpr));
return cg.getCodeGenerator().generateAndGet();
}
use of org.apache.drill.common.expression.LogicalExpression in project drill by apache.
the class TestParquetFilterPushDown method testParquetRowGroupFilterEval.
private void testParquetRowGroupFilterEval(final ParquetMetadata footer, final String exprStr, boolean canDropExpected) throws Exception {
final LogicalExpression filterExpr = parseExpr(exprStr);
testParquetRowGroupFilterEval(footer, 0, filterExpr, canDropExpected);
}
use of org.apache.drill.common.expression.LogicalExpression in project drill by apache.
the class OperatorCodeGenerator method generateComparisons.
protected void generateComparisons(ClassGenerator<?> g, VectorAccessible batch) {
g.setMappingSet(MAIN_MAPPING);
for (Ordering od : popConfig.getOrderings()) {
// first, we rewrite the evaluation stack for each side of the comparison.
ErrorCollector collector = new ErrorCollectorImpl();
final LogicalExpression expr = ExpressionTreeMaterializer.materialize(od.getExpr(), batch, collector, context.getFunctionRegistry());
if (collector.hasErrors()) {
throw UserException.unsupportedError().message("Failure while materializing expression. " + collector.toErrorString()).build(logger);
}
g.setMappingSet(LEFT_MAPPING);
HoldingContainer left = g.addExpr(expr, ClassGenerator.BlkCreateMode.FALSE);
g.setMappingSet(RIGHT_MAPPING);
HoldingContainer right = g.addExpr(expr, ClassGenerator.BlkCreateMode.FALSE);
g.setMappingSet(MAIN_MAPPING);
// next we wrap the two comparison sides and add the expression block for the comparison.
LogicalExpression fh = FunctionGenerationHelper.getOrderingComparator(od.nullsSortHigh(), left, right, context.getFunctionRegistry());
HoldingContainer out = g.addExpr(fh, ClassGenerator.BlkCreateMode.FALSE);
JConditional jc = g.getEvalBlock()._if(out.getValue().ne(JExpr.lit(0)));
if (od.getDirection() == Direction.ASCENDING) {
jc._then()._return(out.getValue());
} else {
jc._then()._return(out.getValue().minus());
}
g.rotateBlock();
}
g.rotateBlock();
g.getEvalBlock()._return(JExpr.lit(0));
}
use of org.apache.drill.common.expression.LogicalExpression in project drill by apache.
the class OperatorCodeGenerator method createNewMSorter.
private MSorter createNewMSorter(List<Ordering> orderings, VectorAccessible batch, MappingSet mainMapping, MappingSet leftMapping, MappingSet rightMapping) {
CodeGenerator<MSorter> cg = CodeGenerator.get(MSorter.TEMPLATE_DEFINITION, context.getFunctionRegistry(), context.getOptions());
cg.plainJavaCapable(true);
// Uncomment out this line to debug the generated code.
// cg.saveCodeForDebugging(true);
ClassGenerator<MSorter> g = cg.getRoot();
g.setMappingSet(mainMapping);
for (Ordering od : orderings) {
// first, we rewrite the evaluation stack for each side of the comparison.
ErrorCollector collector = new ErrorCollectorImpl();
final LogicalExpression expr = ExpressionTreeMaterializer.materialize(od.getExpr(), batch, collector, context.getFunctionRegistry());
if (collector.hasErrors()) {
throw UserException.unsupportedError().message("Failure while materializing expression. " + collector.toErrorString()).build(logger);
}
g.setMappingSet(leftMapping);
HoldingContainer left = g.addExpr(expr, ClassGenerator.BlkCreateMode.FALSE);
g.setMappingSet(rightMapping);
HoldingContainer right = g.addExpr(expr, ClassGenerator.BlkCreateMode.FALSE);
g.setMappingSet(mainMapping);
// next we wrap the two comparison sides and add the expression block for the comparison.
LogicalExpression fh = FunctionGenerationHelper.getOrderingComparator(od.nullsSortHigh(), left, right, context.getFunctionRegistry());
HoldingContainer out = g.addExpr(fh, ClassGenerator.BlkCreateMode.FALSE);
JConditional jc = g.getEvalBlock()._if(out.getValue().ne(JExpr.lit(0)));
if (od.getDirection() == Direction.ASCENDING) {
jc._then()._return(out.getValue());
} else {
jc._then()._return(out.getValue().minus());
}
g.rotateBlock();
}
g.rotateBlock();
g.getEvalBlock()._return(JExpr.lit(0));
return getInstance(cg);
}
Aggregations