public static LogicalExpression createExpression(String functionName, ExpressionPosition ep, List<LogicalExpression> args){ String name = replaceOpWithFuncName(functionName); if (isBooleanOperator(name)) { return new BooleanOperator(name, args, ep); } else { return new FunctionCall(name, args, ep); } }
@Override public LogicalExpression createCall(String funcName, List<LogicalExpression> inputFiled) { return new FunctionCall(funcName, inputFiled, ExpressionPosition.UNKNOWN); } };
private static LogicalExpression getFunctionExpression(String name, HoldingContainer... args) { List<MajorType> argTypes = new ArrayList<MajorType>(args.length); List<LogicalExpression> argExpressions = new ArrayList<LogicalExpression>(args.length); for(HoldingContainer c : args) { argTypes.add(c.getMajorType()); argExpressions.add(new HoldingContainerExpression(c)); } return new FunctionCall(name, argExpressions, ExpressionPosition.UNKNOWN); }
/** * Get the function that tests whether a union type is a specific type * @param type * @param arg * @return */ private LogicalExpression getIsTypeExpressionForType(MinorType type, LogicalExpression arg) { String isFuncName = String.format("is_%s", type.toString()); List<LogicalExpression> args = Lists.newArrayList(); args.add(arg); return new FunctionCall(isFuncName, args, ExpressionPosition.UNKNOWN); }
/** * Returns the function call whose purpose is to throw an Exception if that code is hit during execution * @param message the exception message * @return */ private LogicalExpression getExceptionFunction(String message) { QuotedString msg = new QuotedString(message, message.length(), ExpressionPosition.UNKNOWN); List<LogicalExpression> args = Lists.newArrayList(); args.add(msg); return new FunctionCall(ExceptionFunction.EXCEPTION_FUNCTION_NAME, args, ExpressionPosition.UNKNOWN); }
/** * Returns the function which asserts that the current subtype of a union type is a specific type, and allows the materializer * to bind to that specific type when doing function resolution * @param type * @param arg * @return */ private LogicalExpression getUnionAssertFunctionForType(MinorType type, LogicalExpression arg) { if (type == MinorType.UNION) { return arg; } if (type == MinorType.LIST || type == MinorType.MAP) { return getExceptionFunction("Unable to cast union to " + type); } String castFuncName = String.format("assert_%s", type.toString()); return new FunctionCall(castFuncName, Collections.singletonList(arg), ExpressionPosition.UNKNOWN); }
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; } }
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)); } return new FunctionCall(call.getAggregation().getName().toLowerCase(), args, ExpressionPosition.UNKNOWN); }
@Override public HoldingContainer visitAnyValueExpression(AnyValueExpression e, ClassGenerator<?> value) throws RuntimeException { List<LogicalExpression> newArgs = Lists.newArrayList(); newArgs.add(e.getInput()); // input_expr FunctionCall fc = new FunctionCall(AnyValueExpression.ANY_VALUE, newArgs, e.getPosition()); return fc.accept(this, value); }
@Override public LogicalExpression visitFunctionCall(FunctionCall call, Void value) throws RuntimeException { List<LogicalExpression> args = Lists.newArrayList(); for (LogicalExpression arg : call.args) { args.add(arg.accept(this, null)); } return new FunctionCall(call.getName(), args, call.getPosition()); }
public static LogicalExpression createExpression(String functionName, ExpressionPosition ep, List<LogicalExpression> args){ String name = replaceOpWithFuncName(functionName); if (isBooleanOperator(name)) { return new BooleanOperator(name, args, ep); } else { return new FunctionCall(name, args, ep); } }
protected LogicalExpression toDrill(AggregateCall call, List<String> fn) { DrillParseContext context = new DrillParseContext(PrelUtil.getSettings(getCluster())); List<LogicalExpression> args = Lists.newArrayList(); for (Integer i : call.getArgList()) { final int indexInConstants = i - fn.size(); if (i < fn.size()) { args.add(new FieldReference(fn.get(i))); } else { final RexLiteral constant = constants.get(indexInConstants); LogicalExpression expr = DrillOptiq.toDrill(context, getInput(), constant); args.add(expr); } } // for count(1). if (args.isEmpty()) { args.add(new ValueExpressions.LongExpression(1l)); } return new FunctionCall(call.getAggregation().getName().toLowerCase(), args, ExpressionPosition.UNKNOWN); }
@Override public LogicalExpression visitConvertExpression(ConvertExpression e, FunctionLookupContext functionLookupContext) { String convertFunctionName = e.getConvertFunction() + e.getEncodingType(); List<LogicalExpression> newArgs = Lists.newArrayList(); newArgs.add(e.getInput()); //input_expr FunctionCall fc = new FunctionCall(convertFunctionName, newArgs, e.getPosition()); return fc.accept(this, functionLookupContext); }
private LogicalExpression getConvertToNullableExpr(List<LogicalExpression> args, MinorType minorType, FunctionLookupContext functionLookupContext) { String funcName = "convertToNullable" + minorType.toString(); 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); }
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); }
/** * 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("not_equal", newArgs, ExpressionPosition.UNKNOWN); IfExpression.IfCondition ifCondition = new IfCondition(notEqual, call); IfExpression ifExpression = IfExpression.newBuilder().setIfCondition(ifCondition).setElse(comparisonFunction).build(); return ifExpression; }
@Override public HoldingContainer visitConvertExpression(ConvertExpression e, ClassGenerator<?> value) throws RuntimeException { String convertFunctionName = e.getConvertFunction() + e.getEncodingType(); List<LogicalExpression> newArgs = Lists.newArrayList(); newArgs.add(e.getInput()); // input_expr FunctionCall fc = new FunctionCall(convertFunctionName, newArgs, e.getPosition()); return fc.accept(this, value); }
private List<NamedExpression> getExpressionList() { if (popConfig.getExprs() != null) { return popConfig.getExprs(); } final List<NamedExpression> exprs = Lists.newArrayList(); for (final MaterializedField field : incoming.getSchema()) { String fieldName = field.getName(); if (Types.isComplex(field.getType()) || Types.isRepeated(field.getType())) { final LogicalExpression convertToJson = FunctionCallFactory.createConvert(ConvertExpression.CONVERT_TO, "JSON", SchemaPath.getSimplePath(fieldName), ExpressionPosition.UNKNOWN); final String castFuncName = FunctionReplacementUtils.getCastFunc(MinorType.VARCHAR); final List<LogicalExpression> castArgs = Lists.newArrayList(); castArgs.add(convertToJson); //input_expr // implicitly casting to varchar, since we don't know actual source length, cast to undefined length, which will preserve source length castArgs.add(new ValueExpressions.LongExpression(Types.MAX_VARCHAR_LENGTH, null)); final FunctionCall castCall = new FunctionCall(castFuncName, castArgs, ExpressionPosition.UNKNOWN); exprs.add(new NamedExpression(castCall, new FieldReference(fieldName))); } else { exprs.add(new NamedExpression(SchemaPath.getSimplePath(fieldName), new FieldReference(fieldName))); } } return exprs; }
FunctionCall castCall = new FunctionCall(castFuncName, castArgs, ExpressionPosition.UNKNOWN); FunctionResolver resolver; if (exactResolver) {
FunctionCall fc = new FunctionCall(castFuncWithType, newArgs, e.getPosition()); return fc.accept(this, functionLookupContext);