@Override public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env, IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException { AbstractFunctionCallExpression fce = (AbstractFunctionCallExpression) expression; String funcName = fce.getFunctionIdentifier().getName(); int argNumber = fce.getArguments().size(); if (argNumber < 3) { throw new CompilationException(ErrorCode.COMPILATION_INVALID_PARAMETER_NUMBER, fce.getSourceLocation(), funcName, argNumber); } int argSize = fce.getArguments().size(); List<IAType> types = new ArrayList<>(); // Collects different branches' return types. // The last return expression is from the ELSE branch and it is optional. for (int argIndex = 2; argIndex < argSize; argIndex += (argIndex + 2 == argSize) ? 1 : 2) { IAType type = (IAType) env.getType(fce.getArguments().get(argIndex).getValue()); types.add(type); } return TypeResolverUtil.resolve(types); } }
public boolean convertFunctionToAlgebricksExpression(Mutable<ILogicalExpression> searchM, AbstractFunctionCallExpression functionCall, IOptimizationContext context, Map<FunctionIdentifier, FunctionIdentifier> map) { if (map.containsKey(functionCall.getFunctionIdentifier())) { IExpressionAnnotation annotate = new ExpressionAnnotationNoCopyImpl(); annotate.setObject(functionCall.getFunctionIdentifier()); FunctionIdentifier algebricksFid = map.get(functionCall.getFunctionIdentifier()); IFunctionInfo algebricksFunction = context.getMetadataProvider().lookupFunction(algebricksFid); functionCall.setFunctionInfo(algebricksFunction); functionCall.getAnnotations().put(ALGEBRICKS_CONVERSION_ANNOTATION, annotate); searchM.setValue(functionCall); return true; } return false; }
private static boolean containsNonpureCall(ILogicalExpression expr) { if (expr.getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL) { AbstractFunctionCallExpression fExpr = (AbstractFunctionCallExpression) expr; if (!fExpr.getFunctionInfo().isFunctional()) { return true; } for (Mutable<ILogicalExpression> subExpr : fExpr.getArguments()) { if (containsNonpureCall(subExpr.getValue())) { return true; } } } return false; }
private void deepCopyOpaqueParameters(AbstractFunctionCallExpression src, AbstractFunctionCallExpression dest) { Object[] srcOpaqueParameters = src.getOpaqueParameters(); Object[] newOpaqueParameters = null; if (srcOpaqueParameters != null) { newOpaqueParameters = new Object[srcOpaqueParameters.length]; for (int i = 0; i < srcOpaqueParameters.length; i++) { newOpaqueParameters[i] = srcOpaqueParameters[i]; } } dest.setOpaqueParameters(newOpaqueParameters); }
/** * Replace the original aggregate functions with their corresponding global aggregate function. */ protected void replaceOriginalAggFuncs(Set<SimilarAggregatesInfo> toReplaceSet) { for (SimilarAggregatesInfo sai : toReplaceSet) { for (AggregateExprInfo aei : sai.simAggs) { AbstractFunctionCallExpression afce = (AbstractFunctionCallExpression) aei.aggExprRef.getValue(); afce.setFunctionInfo(aei.newFunInfo); afce.getArguments().clear(); afce.getArguments().add(new MutableObject<>(sai.stepOneResult)); } } }
private boolean transformFunctionCallExpression(AbstractFunctionCallExpression fce) throws AlgebricksException { boolean modified = false; FunctionIdentifier fi = fce.getFunctionIdentifier(); if (fi != BuiltinFunctions.FULLTEXT_CONTAINS && fi != BuiltinFunctions.FULLTEXT_CONTAINS_WO_OPTION) { for (Mutable<ILogicalExpression> arg : fce.getArguments()) { if (transform(arg)) { modified = true; } } } else { modified = checkParameterForFuncExpr(fce, fi); } return modified; }
private boolean transformFunctionCallExpression(AbstractFunctionCallExpression fce) throws AlgebricksException { boolean modified = false; for (Mutable<ILogicalExpression> arg : fce.getArguments()) { if (transform(arg)) { modified = true; } } return modified; }
private void computeTypeFromNonConstantExpression(String funcName, ILogicalExpression expression, Set<String> fieldNameSet, List<List<String>> pathList) throws AlgebricksException { AbstractFunctionCallExpression funcExp = (AbstractFunctionCallExpression) expression; List<Mutable<ILogicalExpression>> args = funcExp.getArguments(); for (Mutable<ILogicalExpression> arg : args) { ILogicalExpression le = arg.getValue(); switch (le.getExpressionTag()) { case CONSTANT: getPathFromConstantExpression(funcName, le, fieldNameSet, pathList, funcExp.getSourceLocation()); break; case FUNCTION_CALL: getPathFromFunctionExpression(funcName, le, fieldNameSet, pathList, funcExp.getSourceLocation()); break; default: throw new InvalidExpressionException(funcExp.getSourceLocation(), funcName, 1, le, LogicalExpressionTag.CONSTANT, LogicalExpressionTag.FUNCTION_CALL); } } }
if (funcExpr.getFunctionIdentifier() != AlgebricksBuiltinFunctions.AND) { throw new CompilationException(ErrorCode.COMPILATION_FUNC_EXPRESSION_CANNOT_UTILIZE_INDEX, funcExpr.getSourceLocation(), LogRedactionUtil.userData(funcExpr.toString())); for (Mutable<ILogicalExpression> arg : funcExpr.getArguments()) { ILogicalExpression argExpr = arg.getValue(); if (argExpr.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
FunctionIdentifier fi = funcExp.getFunctionIdentifier(); if (fi.equals(BuiltinFunctions.FUZZY_EQ)) { SourceLocation sourceLoc = funcExp.getSourceLocation(); List<Mutable<ILogicalExpression>> inputExps = funcExp.getArguments(); similarityExp.setSourceLocation(sourceLoc); similarityExp.getAnnotations().putAll(funcExp.getAnnotations()); ArrayList<Mutable<ILogicalExpression>> cmpArgs = new ArrayList<Mutable<ILogicalExpression>>(); cmpArgs.add(new MutableObject<ILogicalExpression>(similarityExp)); } else if (fi.equals(AlgebricksBuiltinFunctions.AND) || fi.equals(AlgebricksBuiltinFunctions.OR)) { for (int i = 0; i < 2; i++) { if (expandFuzzyEq(funcExp.getArguments().get(i), context, env, metadataProvider)) { expanded = true;
private boolean hasTranslatableInterval(AbstractFunctionCallExpression funcExpr) { if (TRANSLATABLE_INTERVALS.contains(funcExpr.getFunctionIdentifier())) { return true; } return false; }
Function functionInfo2 = (Function) functionCall2.getFunctionInfo(); if (!functionInfo2.hasScalarEvaluatorFactory()) { return false; if (functionCall2.getFunctionIdentifier().equals(BuiltinOperators.DESCENDANT.getFunctionIdentifier()) || functionCall2.getFunctionIdentifier().equals( BuiltinOperators.DESCENDANT_OR_SELF.getFunctionIdentifier())) { return false; functionCall2.getArguments()); unnest1Arg.setValue(child);
FunctionIdentifier fi = fexp.getFunctionIdentifier(); if (fi.equals(AlgebricksBuiltinFunctions.AND)) { BroadcastSide fBcastSide = null; for (Mutable<ILogicalExpression> a : fexp.getArguments()) { BroadcastSide aBcastSide = getBroadcastJoinSide(a.getValue(), varsLeft, varsRight); if (fBcastSide == null) { } else { IExpressionAnnotation ann = fexp.getAnnotations().get(BroadcastExpressionAnnotation.BROADCAST_ANNOTATION_KEY); if (ann == null) { return null; fexp.getArguments().get(i).getValue().getUsedVariables(vars); if (varsLeft.containsAll(vars)) { return BroadcastSide.LEFT;
List<Mutable<ILogicalExpression>> list = (List<Mutable<ILogicalExpression>>) childFnCall.getArguments(); Mutable<ILogicalExpression> mle = (Mutable<ILogicalExpression>) (list).get(0); ILogicalExpression le = mle.getValue(); if (!(afce.getFunctionIdentifier().equals(BuiltinOperators.DESCENDANT_OR_SELF.getFunctionIdentifier()))) { return false; childFnCall.setFunctionInfo(BuiltinOperators.DESCENDANT_OR_SELF); childFnCall.getArguments().get(0).setValue(afce.getArguments().get(0).getValue()); ILogicalOperator lo1 = opRef.getValue(); Mutable<ILogicalOperator> mlistOfLo = lo1.getInputs().get(0).getValue().getInputs().get(0);
for (Mutable<ILogicalExpression> functionArgRef : funcCallExpr.getArguments()) { if (rewriteFunctionArgs(op, functionArgRef, context)) { changed = true; if (BuiltinFunctions.getBuiltinFunctionIdentifier(funcCallExpr.getFunctionIdentifier()) != null) { return changed; for (int iter1 = 0; iter1 < funcCallExpr.getArguments().size(); iter1++) { Mutable<ILogicalExpression> argExpr = funcCallExpr.getArguments().get(iter1); inputRecordType = (IAType) op.computeOutputTypeEnvironment(context).getType(argExpr.getValue()); if (!(((ExternalScalarFunctionInfo) funcCallExpr.getFunctionInfo()).getArgumenTypes() .get(iter1) instanceof ARecordType)) { continue; requiredRecordType = (ARecordType) ((ExternalScalarFunctionInfo) funcCallExpr.getFunctionInfo()) .getArgumenTypes().get(iter1); AbstractFunctionCallExpression castFunc = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.CAST_TYPE)); castFunc.setSourceLocation(argExpr.getValue().getSourceLocation()); castFunc.getArguments().add(argExpr); TypeCastUtils.setRequiredAndInputTypes(castFunc, requiredRecordType, inputRecordType); funcCallExpr.getArguments().set(iter1, new MutableObject<>(castFunc)); changed = true;
public static boolean setRequiredAndInputTypes(AbstractFunctionCallExpression expr, IAType requiredType, IAType inputType) throws CompilationException { boolean changed = false; Object[] opaqueParameters = expr.getOpaqueParameters(); if (opaqueParameters == null) { opaqueParameters = new Object[2]; opaqueParameters[0] = requiredType; opaqueParameters[1] = inputType; ATypeTag requiredTypeTag = requiredType.getTypeTag(); ATypeTag actualTypeTag = TypeComputeUtils.getActualType(inputType).getTypeTag(); if (!ATypeHierarchy.isCompatible(requiredTypeTag, actualTypeTag)) { String funcName = expr.getFunctionIdentifier().getName(); throw new IncompatibleTypeException(expr.getSourceLocation(), funcName, actualTypeTag, requiredTypeTag); } expr.setOpaqueParameters(opaqueParameters); changed = true; } return changed; }
protected StringBuilder appendFunction(StringBuilder sb, AbstractFunctionCallExpression expr, Integer indent) throws AlgebricksException { assert expr.getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL; FunctionIdentifier fi = expr.getFunctionIdentifier(); List<Mutable<ILogicalExpression>> args = expr.getArguments(); if ((identifiesTypeOperator(fi) || identifiesPathStep(fi)) && args.size() > 1) { final ILogicalExpression typeEx = args.get(1).getValue(); assert typeEx.getExpressionTag() == LogicalExpressionTag.CONSTANT; SequenceType type = getSequenceType((ConstantExpression) typeEx); sb.append(fi + " <" + type + ">, Args:"); appendArgument(sb, args.get(0), indent + 2); } else { sb.append("function-call: " + fi + ", Args:"); appendArguments(sb, args, indent + 2); } return sb; }
private static AbstractFunctionCallExpression createRectangleExpression( AbstractFunctionCallExpression createPointExpr1, AbstractFunctionCallExpression createPointExpr2) { List<Mutable<ILogicalExpression>> expressions = new ArrayList<>(); AbstractFunctionCallExpression createRectangleExpr = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.CREATE_RECTANGLE)); createRectangleExpr.setSourceLocation(createPointExpr1.getSourceLocation()); expressions.add(new MutableObject<ILogicalExpression>(createPointExpr1)); expressions.add(new MutableObject<ILogicalExpression>(createPointExpr2)); createRectangleExpr.getArguments().addAll(expressions); return createRectangleExpr; }
private boolean listifyUnnestingFunction(ILogicalOperator op, Mutable<ILogicalExpression> exprRef, AbstractFunctionCallExpression func, IOptimizationContext context) throws AlgebricksException { IFunctionInfo functionInfo = func.getFunctionInfo(); SourceLocation sourceLoc = func.getSourceLocation(); new UnnestingFunctionCallExpression(functionInfo, func.getArguments()); unnestExpr.setSourceLocation(sourceLoc); UnnestOperator unnestOperator = new UnnestOperator(unnestVar, new MutableObject<>(unnestExpr));
@Override public boolean exprIsOptimizable(Index index, IOptimizableFuncExpr optFuncExpr) throws AlgebricksException { if (optFuncExpr.getFuncExpr().getAnnotations() .containsKey(SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE)) { return false; } if (optFuncExpr.getFuncExpr().getFunctionIdentifier() == BuiltinFunctions.EDIT_DISTANCE_CHECK || optFuncExpr.getFuncExpr().getFunctionIdentifier() == BuiltinFunctions.EDIT_DISTANCE_CONTAINS) { return isEditDistanceFuncOptimizable(index, optFuncExpr); } if (optFuncExpr.getFuncExpr().getFunctionIdentifier() == BuiltinFunctions.SIMILARITY_JACCARD_CHECK) { return isJaccardFuncOptimizable(index, optFuncExpr); } if (optFuncExpr.getFuncExpr().getFunctionIdentifier() == BuiltinFunctions.STRING_CONTAINS) { return isContainsFuncOptimizable(index, optFuncExpr); } if (optFuncExpr.getFuncExpr().getFunctionIdentifier() == BuiltinFunctions.FULLTEXT_CONTAINS || optFuncExpr.getFuncExpr().getFunctionIdentifier() == BuiltinFunctions.FULLTEXT_CONTAINS_WO_OPTION) { return isFullTextContainsFuncOptimizable(index, optFuncExpr); } return false; }