use of org.apache.drill.common.expression.LogicalExpression in project drill by apache.
the class StringCastReturnTypeInference method getType.
/**
* Defines function return type and sets cast length as type precision
* if cast length is simple long expression.
*
* @param logicalExpressions logical expressions
* @param attributes function attributes
* @return return type
*/
@Override
public TypeProtos.MajorType getType(List<LogicalExpression> logicalExpressions, FunctionAttributes attributes) {
TypeProtos.MajorType.Builder builder = TypeProtos.MajorType.newBuilder().setMinorType(attributes.getReturnValue().getType().getMinorType()).setMode(FunctionUtils.getReturnTypeDataMode(logicalExpressions, attributes));
LogicalExpression logicalExpression = logicalExpressions.get(1);
if (logicalExpressions.get(1) instanceof ValueExpressions.LongExpression) {
long precision = ((ValueExpressions.LongExpression) logicalExpression).getLong();
builder.setPrecision(Ints.checkedCast(precision));
}
return builder.build();
}
use of org.apache.drill.common.expression.LogicalExpression in project drill by apache.
the class FunctionGenerationHelper method getOrderingComparator.
/**
* Finds ordering comparator ("compare_to...") FunctionHolderExpression with
* a specified ordering for NULL (and considering NULLS <i>equal</i>).
* @param null_high whether NULL should compare as the lowest value (if
* {@code false}) or the highest value (if {@code true})
* @param left ...
* @param right ...
* @param registry ...
* @return
* FunctionHolderExpression containing the found function implementation
*/
public static LogicalExpression getOrderingComparator(boolean null_high, HoldingContainer left, HoldingContainer right, FunctionImplementationRegistry registry) {
final String comparator_name = null_high ? COMPARE_TO_NULLS_HIGH : COMPARE_TO_NULLS_LOW;
if (!isComparableType(left.getMajorType()) || !isComparableType(right.getMajorType())) {
throw new UnsupportedOperationException(formatCanNotCompareMsg(left.getMajorType(), right.getMajorType()));
}
LogicalExpression comparisonFunctionExpression = getFunctionExpression(comparator_name, Types.required(MinorType.INT), registry, left, right);
ErrorCollector collector = new ErrorCollectorImpl();
if (!isUnionType(left.getMajorType()) && !isUnionType(right.getMajorType())) {
return ExpressionTreeMaterializer.materialize(comparisonFunctionExpression, null, collector, registry);
} else {
LogicalExpression typeComparisonFunctionExpression = getTypeComparisonFunction(comparisonFunctionExpression, left, right);
return ExpressionTreeMaterializer.materialize(typeComparisonFunctionExpression, null, collector, registry);
}
}
use of org.apache.drill.common.expression.LogicalExpression in project drill by apache.
the class DrillWindowRel method toDrill.
protected LogicalExpression toDrill(AggregateCall call, List<String> fn) {
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 = new FunctionCall(call.getAggregation().getName().toLowerCase(), args, ExpressionPosition.UNKNOWN);
return expr;
}
use of org.apache.drill.common.expression.LogicalExpression in project drill by apache.
the class AggPrelBase method createKeysAndExprs.
protected void createKeysAndExprs() {
final List<String> childFields = getInput().getRowType().getFieldNames();
final List<String> fields = getRowType().getFieldNames();
for (int group : BitSets.toIter(groupSet)) {
FieldReference fr = FieldReference.getWithQuotedRef(childFields.get(group));
keys.add(new NamedExpression(fr, fr));
}
for (Ord<AggregateCall> aggCall : Ord.zip(aggCalls)) {
int aggExprOrdinal = groupSet.cardinality() + aggCall.i;
FieldReference ref = FieldReference.getWithQuotedRef(fields.get(aggExprOrdinal));
LogicalExpression expr = toDrill(aggCall.e, childFields);
NamedExpression ne = new NamedExpression(expr, ref);
aggExprs.add(ne);
if (getOperatorPhase() == OperatorPhase.PHASE_1of2) {
if (aggCall.e.getAggregation().getName().equals("COUNT")) {
// If we are doing a COUNT aggregate in Phase1of2, then in Phase2of2 we should SUM the COUNTs,
SqlAggFunction sumAggFun = new SqlSumCountAggFunction(aggCall.e.getType());
AggregateCall newAggCall = new AggregateCall(sumAggFun, aggCall.e.isDistinct(), Collections.singletonList(aggExprOrdinal), aggCall.e.getType(), aggCall.e.getName());
phase2AggCallList.add(newAggCall);
} else {
AggregateCall newAggCall = new AggregateCall(aggCall.e.getAggregation(), aggCall.e.isDistinct(), Collections.singletonList(aggExprOrdinal), aggCall.e.getType(), aggCall.e.getName());
phase2AggCallList.add(newAggCall);
}
}
}
}
use of org.apache.drill.common.expression.LogicalExpression in project drill by apache.
the class AggPrelBase method toDrill.
protected LogicalExpression toDrill(AggregateCall call, List<String> fn) {
List<LogicalExpression> args = Lists.newArrayList();
for (Integer i : call.getArgList()) {
args.add(FieldReference.getWithQuotedRef(fn.get(i)));
}
// for count(1).
if (args.isEmpty()) {
args.add(new ValueExpressions.LongExpression(1l));
}
LogicalExpression expr = new FunctionCall(call.getAggregation().getName().toLowerCase(), args, ExpressionPosition.UNKNOWN);
return expr;
}
Aggregations