use of org.apache.drill.common.expression.LogicalExpression in project drill by apache.
the class StreamingAggBatch method setupIsSame.
protected void setupIsSame(ClassGenerator<StreamingAggregator> cg, LogicalExpression[] keyExprs) {
cg.setMappingSet(IS_SAME_I1);
for (LogicalExpression expr : keyExprs) {
// first, we rewrite the evaluation stack for each side of the comparison.
cg.setMappingSet(IS_SAME_I1);
HoldingContainer first = cg.addExpr(expr, ClassGenerator.BlkCreateMode.FALSE);
cg.setMappingSet(IS_SAME_I2);
HoldingContainer second = cg.addExpr(expr, ClassGenerator.BlkCreateMode.FALSE);
LogicalExpression fh = FunctionGenerationHelper.getOrderingComparatorNullsHigh(first, second, context.getFunctionRegistry());
HoldingContainer out = cg.addExpr(fh, ClassGenerator.BlkCreateMode.FALSE);
cg.getEvalBlock()._if(out.getValue().ne(JExpr.lit(0)))._then()._return(JExpr.FALSE);
}
cg.getEvalBlock()._return(JExpr.TRUE);
}
use of org.apache.drill.common.expression.LogicalExpression in project drill by apache.
the class StreamingAggBatch method setupIsSameApart.
protected void setupIsSameApart(ClassGenerator<StreamingAggregator> cg, LogicalExpression[] keyExprs) {
cg.setMappingSet(ISA_B1);
for (LogicalExpression expr : keyExprs) {
// first, we rewrite the evaluation stack for each side of the comparison.
cg.setMappingSet(ISA_B1);
HoldingContainer first = cg.addExpr(expr, ClassGenerator.BlkCreateMode.FALSE);
cg.setMappingSet(ISA_B2);
HoldingContainer second = cg.addExpr(expr, ClassGenerator.BlkCreateMode.FALSE);
LogicalExpression fh = FunctionGenerationHelper.getOrderingComparatorNullsHigh(first, second, context.getFunctionRegistry());
HoldingContainer out = cg.addExpr(fh, ClassGenerator.BlkCreateMode.FALSE);
cg.getEvalBlock()._if(out.getValue().ne(JExpr.lit(0)))._then()._return(JExpr.FALSE);
}
cg.getEvalBlock()._return(JExpr.TRUE);
}
use of org.apache.drill.common.expression.LogicalExpression in project drill by apache.
the class StreamingAggBatch method createAggregatorInternal.
protected StreamingAggregator createAggregatorInternal() {
ClassGenerator<StreamingAggregator> cg = CodeGenerator.getRoot(StreamingAggTemplate.TEMPLATE_DEFINITION, context.getOptions());
// Streaming agg no longer plain Java capable. Stats generates code
// that fails when compiled normally.
// cannot override resetValues() in org.apache.drill.exec.physical.impl.aggregate.StreamingAggTemplate
// public boolean resetValues()
// ^
// overridden method does not throw org.apache.drill.exec.exception.SchemaChangeException (compiler.err.override.meth.doesnt.throw)
// cg.getCodeGenerator().plainJavaCapable(true);
// Uncomment out this line to debug the generated code.
// cg.getCodeGenerator().saveCodeForDebugging(true);
container.clear();
LogicalExpression[] keyExprs = new LogicalExpression[getKeyExpressions().size()];
LogicalExpression[] valueExprs = new LogicalExpression[getValueExpressions().size()];
TypedFieldId[] keyOutputIds = new TypedFieldId[getKeyExpressions().size()];
ErrorCollector collector = new ErrorCollectorImpl();
for (int i = 0; i < keyExprs.length; i++) {
NamedExpression ne = getKeyExpressions().get(i);
LogicalExpression expr = ExpressionTreeMaterializer.materialize(ne.getExpr(), incoming, collector, context.getFunctionRegistry());
if (expr == null) {
continue;
}
keyExprs[i] = expr;
MaterializedField outputField = MaterializedField.create(ne.getRef().getLastSegment().getNameSegment().getPath(), expr.getMajorType());
container.addOrGet(outputField);
keyOutputIds[i] = container.getValueVectorId(ne.getRef());
}
for (int i = 0; i < valueExprs.length; i++) {
NamedExpression ne = getValueExpressions().get(i);
LogicalExpression expr = ExpressionTreeMaterializer.materialize(ne.getExpr(), incoming, collector, context.getFunctionRegistry(), true, false);
if (expr instanceof IfExpression) {
throw UserException.unsupportedError(new UnsupportedOperationException("Union type not supported in aggregate functions")).build(logger);
}
if (expr == null) {
continue;
}
// Populate the complex writers for complex exprs
if (expr instanceof DrillFuncHolderExpr && ((DrillFuncHolderExpr) expr).getHolder().isComplexWriterFuncHolder()) {
// Lazy initialization of the list of complex writers, if not done yet.
if (complexWriters == null) {
complexWriters = Lists.newArrayList();
} else {
complexWriters.clear();
}
// The reference name will be passed to ComplexWriter, used as the name of the output vector from the writer.
((DrillFuncHolderExpr) expr).setFieldReference(ne.getRef());
MaterializedField field = MaterializedField.create(ne.getRef().getAsNamePart().getName(), UntypedNullHolder.TYPE);
container.add(new UntypedNullVector(field, container.getAllocator()));
valueExprs[i] = expr;
} else {
MaterializedField outputField = MaterializedField.create(ne.getRef().getLastSegment().getNameSegment().getPath(), expr.getMajorType());
container.addOrGet(outputField);
TypedFieldId id = container.getValueVectorId(ne.getRef());
valueExprs[i] = new ValueVectorWriteExpression(id, expr, true);
}
}
collector.reportErrors(logger);
setupIsSame(cg, keyExprs);
setupIsSameApart(cg, keyExprs);
addRecordValues(cg, valueExprs);
outputRecordKeys(cg, keyOutputIds, keyExprs);
outputRecordKeysPrev(cg, keyOutputIds, keyExprs);
cg.getBlock("resetValues")._return(JExpr.TRUE);
getIndex(cg);
container.buildSchema(SelectionVectorMode.NONE);
StreamingAggregator agg = context.getImplementationClass(cg);
try {
agg.setup(oContext, incoming, this, maxOutputRowCount);
} catch (SchemaChangeException e) {
throw schemaChangeException(e, logger);
}
allocateComplexWriters();
return agg;
}
use of org.apache.drill.common.expression.LogicalExpression in project drill by apache.
the class DruidCompareFunctionProcessor method process.
public static DruidCompareFunctionProcessor process(FunctionCall call) {
String functionName = call.getName();
LogicalExpression nameArg = call.args().get(0);
LogicalExpression valueArg = call.args().size() == 2 ? call.args().get(1) : null;
DruidCompareFunctionProcessor evaluator = new DruidCompareFunctionProcessor(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 (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 DruidFilterBuilderTest method visitBooleanOperatorWithAndOperator.
@Test
public void visitBooleanOperatorWithAndOperator() {
LogicalExpression logicalExpression2 = mock(LogicalExpression.class);
try {
when(logicalExpression.accept(any(), any())).thenReturn(druidScanSpecLeft);
when(logicalExpression2.accept(any(), any())).thenReturn(druidScanSpecRight);
} catch (Exception ignored) {
}
BooleanOperator booleanOperator = new BooleanOperator(FunctionNames.AND, Stream.of(logicalExpression, logicalExpression2).collect(Collectors.toList()), null);
DruidScanSpec druidScanSpec = druidFilterBuilder.visitBooleanOperator(booleanOperator, null);
String expectedFilterJson = "{\"type\":\"and\",\"fields\":[{\"type\":\"selector\",\"dimension\":\"some dimension\",\"value\":\"some value\"},{\"type\":\"selector\",\"dimension\":\"some other dimension\",\"value\":\"some other value\"}]}";
String actual = druidScanSpec.getFilter().toJson();
assertThat(actual).isEqualTo(expectedFilterJson);
}
Aggregations