use of org.apache.drill.common.expression.LogicalExpression in project drill by axbaretto.
the class ExpressionTreeMaterializer method materializeAndCheckErrors.
public static LogicalExpression materializeAndCheckErrors(LogicalExpression expr, VectorAccessible batch, FunctionLookupContext functionLookupContext) throws SchemaChangeException {
ErrorCollector collector = new ErrorCollectorImpl();
LogicalExpression e = ExpressionTreeMaterializer.materialize(expr, batch, collector, functionLookupContext, false, false);
if (collector.hasErrors()) {
throw new SchemaChangeException(String.format("Failure while trying to materialize incoming schema. Errors:\n %s.", collector.toErrorString()));
}
return e;
}
use of org.apache.drill.common.expression.LogicalExpression in project drill by axbaretto.
the class ExpressionTreeMaterializer method logFunctionResolutionError.
private static void logFunctionResolutionError(ErrorCollector errorCollector, FunctionCall call) {
// add error to collector
StringBuilder sb = new StringBuilder();
sb.append("Missing function implementation: ");
sb.append("[");
sb.append(call.getName());
sb.append("(");
boolean first = true;
for (LogicalExpression e : call.args) {
TypeProtos.MajorType mt = e.getMajorType();
if (first) {
first = false;
} else {
sb.append(", ");
}
sb.append(mt.getMinorType().name());
sb.append("-");
sb.append(mt.getMode().name());
}
sb.append(")");
sb.append("]");
errorCollector.addGeneralError(call.getPosition(), sb.toString());
}
use of org.apache.drill.common.expression.LogicalExpression in project drill by axbaretto.
the class ExpressionTreeMaterializer method convertToNullableType.
public static LogicalExpression convertToNullableType(LogicalExpression fromExpr, MinorType toType, FunctionLookupContext functionLookupContext, ErrorCollector errorCollector) {
String funcName = "convertToNullable" + toType.toString();
List<LogicalExpression> args = Lists.newArrayList();
args.add(fromExpr);
FunctionCall funcCall = new FunctionCall(funcName, args, ExpressionPosition.UNKNOWN);
FunctionResolver resolver = FunctionResolverFactory.getResolver(funcCall);
DrillFuncHolder matchedConvertToNullableFuncHolder = functionLookupContext.findDrillFunction(resolver, funcCall);
if (matchedConvertToNullableFuncHolder == null) {
logFunctionResolutionError(errorCollector, funcCall);
return NullExpression.INSTANCE;
}
return matchedConvertToNullableFuncHolder.getExpr(funcName, args, ExpressionPosition.UNKNOWN);
}
use of org.apache.drill.common.expression.LogicalExpression in project drill by axbaretto.
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 axbaretto.
the class StreamingAggBatch method setupIsSame.
private void setupIsSame(ClassGenerator<StreamingAggregator> cg, LogicalExpression[] keyExprs) {
cg.setMappingSet(IS_SAME_I1);
for (final LogicalExpression expr : keyExprs) {
// first, we rewrite the evaluation stack for each side of the comparison.
cg.setMappingSet(IS_SAME_I1);
final HoldingContainer first = cg.addExpr(expr, ClassGenerator.BlkCreateMode.FALSE);
cg.setMappingSet(IS_SAME_I2);
final HoldingContainer second = cg.addExpr(expr, ClassGenerator.BlkCreateMode.FALSE);
final LogicalExpression fh = FunctionGenerationHelper.getOrderingComparatorNullsHigh(first, second, context.getFunctionRegistry());
final 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);
}
Aggregations