use of org.apache.drill.exec.expr.ClassGenerator.HoldingContainer in project drill by apache.
the class FunctionGenerationHelper method getTypeComparisonFunction.
/**
* Wraps the comparison function in an If-statement which compares the types first, evaluating the comaprison function only
* if the types are equivialent
*
* @param comparisonFunction
* @param args
* @return
*/
private static LogicalExpression getTypeComparisonFunction(LogicalExpression comparisonFunction, HoldingContainer... args) {
List<LogicalExpression> argExpressions = Lists.newArrayList();
List<MajorType> argTypes = Lists.newArrayList();
for (HoldingContainer c : args) {
argTypes.add(c.getMajorType());
argExpressions.add(new HoldingContainerExpression(c));
}
FunctionCall call = new FunctionCall("compareType", argExpressions, ExpressionPosition.UNKNOWN);
List<LogicalExpression> newArgs = Lists.newArrayList();
newArgs.add(call);
newArgs.add(new IntExpression(0, ExpressionPosition.UNKNOWN));
FunctionCall notEqual = new FunctionCall(FunctionNames.NE, newArgs, ExpressionPosition.UNKNOWN);
IfExpression.IfCondition ifCondition = new IfCondition(notEqual, call);
IfExpression ifExpression = IfExpression.newBuilder().setIfCondition(ifCondition).setElse(comparisonFunction).build();
return ifExpression;
}
use of org.apache.drill.exec.expr.ClassGenerator.HoldingContainer in project drill by apache.
the class StreamingAggBatch method outputRecordKeysPrev.
protected void outputRecordKeysPrev(ClassGenerator<StreamingAggregator> cg, TypedFieldId[] keyOutputIds, LogicalExpression[] keyExprs) {
cg.setMappingSet(RECORD_KEYS_PREV);
for (int i = 0; i < keyExprs.length; i++) {
// IMPORTANT: there is an implicit assertion here that the TypedFieldIds
// for the previous batch and the current batch are the same. This is
// possible because InternalBatch guarantees this.
logger.debug("Writing out expr {}", keyExprs[i]);
cg.rotateBlock();
cg.setMappingSet(RECORD_KEYS_PREV);
HoldingContainer innerExpression = cg.addExpr(keyExprs[i], ClassGenerator.BlkCreateMode.FALSE);
cg.setMappingSet(RECORD_KEYS_PREV_OUT);
cg.addExpr(new ValueVectorWriteExpression(keyOutputIds[i], new HoldingContainerExpression(innerExpression), true), ClassGenerator.BlkCreateMode.FALSE);
}
}
use of org.apache.drill.exec.expr.ClassGenerator.HoldingContainer in project drill by apache.
the class ChainedHashTable method setupGetHash.
private void setupGetHash(ClassGenerator<HashTable> cg, MappingSet incomingMapping, VectorAccessible batch, LogicalExpression[] keyExprs) throws SchemaChangeException {
cg.setMappingSet(incomingMapping);
if (keyExprs == null || keyExprs.length == 0) {
cg.getEvalBlock()._return(JExpr.lit(0));
return;
}
/*
* We use the same logic to generate run time code for the hash function both for hash join and hash
* aggregate. For join we need to hash everything as double (both for distribution and for comparison) but
* for aggregation we can avoid the penalty of casting to double
*/
/*
Generate logical expression for each key so expression can be split into blocks if number of expressions in method exceeds upper limit.
`seedValue` is used as holder to pass generated seed value for the new methods.
*/
String seedValue = "seedValue";
LogicalExpression seed = ValueExpressions.getParameterExpression(seedValue, Types.required(TypeProtos.MinorType.INT));
for (LogicalExpression expr : keyExprs) {
LogicalExpression hashExpression = HashPrelUtil.getHashExpression(expr, seed, incomingProbe != null);
LogicalExpression materializedExpr = ExpressionTreeMaterializer.materializeAndCheckErrors(hashExpression, batch, context.getFunctionRegistry());
HoldingContainer hash = cg.addExpr(materializedExpr, ClassGenerator.BlkCreateMode.TRUE_IF_BOUND);
cg.getEvalBlock().assign(JExpr.ref(seedValue), hash.getValue());
}
cg.getEvalBlock()._return(JExpr.ref(seedValue));
}
Aggregations