protected static AbstractFunctionCallExpression createFunctionCallExpression(FunctionIdentifier fid, SourceLocation sourceLoc) { ScalarFunctionCallExpression callExpr = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(fid)); callExpr.setSourceLocation(sourceLoc); return callExpr; }
private ILogicalExpression translateConstantValue(IAObject value, SourceLocation sourceLoc) throws CompilationException { ConstantExpression constExpr = new ConstantExpression(new AsterixConstantValue(value)); constExpr.setSourceLocation(sourceLoc); IAType valueType = value.getType(); if (valueType.getTypeTag().isDerivedType()) { ScalarFunctionCallExpression castExpr = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.CAST_TYPE)); castExpr.setSourceLocation(sourceLoc); castExpr.getArguments().add(new MutableObject<>(constExpr)); TypeCastUtils.setRequiredAndInputTypes(castExpr, BuiltinType.ANY, valueType); return castExpr; } else { return constExpr; } }
@Override public ScalarFunctionCallExpression cloneExpression() { List<Mutable<ILogicalExpression>> clonedArgs = cloneArguments(); ScalarFunctionCallExpression funcExpr = new ScalarFunctionCallExpression(finfo, clonedArgs); funcExpr.getAnnotations().putAll(cloneAnnotations()); funcExpr.setOpaqueParameters(this.getOpaqueParameters()); funcExpr.setSourceLocation(sourceLoc); return funcExpr; }
@Override public ILogicalExpression visitScalarFunctionCallExpression(ScalarFunctionCallExpression expr, Void arg) throws AlgebricksException { ScalarFunctionCallExpression exprCopy = new ScalarFunctionCallExpression(expr.getFunctionInfo(), deepCopyExpressionReferenceList(expr.getArguments())); deepCopyAnnotations(expr, exprCopy); deepCopyOpaqueParameters(expr, exprCopy); copySourceLocation(expr, exprCopy); return exprCopy; }
private static ILogicalExpression sfce(Function fn, ILogicalExpression... argExprs) { List<Mutable<ILogicalExpression>> args = new ArrayList<Mutable<ILogicalExpression>>(); for (ILogicalExpression e : argExprs) { args.add(mutable(e)); } return new ScalarFunctionCallExpression(fn, args); }
ScalarFunctionCallExpression similarityExp = new ScalarFunctionCallExpression( FunctionUtil.getFunctionInfo(simFunctionIdentifier), similarityArgs); similarityExp.setSourceLocation(sourceLoc); similarityExp.getAnnotations().putAll(funcExp.getAnnotations()); ArrayList<Mutable<ILogicalExpression>> cmpArgs = new ArrayList<Mutable<ILogicalExpression>>(); cmpArgs.add(new MutableObject<ILogicalExpression>(similarityExp));
private boolean replaceWithFunctionCallArg(Mutable<ILogicalExpression> expRef, FunctionIdentifier normFuncIdent, AsterixConstantValue constVal, AbstractFunctionCallExpression funcExpr) throws AlgebricksException { // Analyze func expr to see if it is an optimizable similarity function. ScalarFunctionCallExpression simCheckFuncExpr = getSimilarityCheckExpr(normFuncIdent, constVal, funcExpr); // Replace the expr in the select condition. if (simCheckFuncExpr != null) { // Get item 0 from var. List<Mutable<ILogicalExpression>> getItemArgs = new ArrayList<Mutable<ILogicalExpression>>(); // First arg is the similarity-check function call. getItemArgs.add(new MutableObject<ILogicalExpression>(simCheckFuncExpr)); // Second arg is the item index to be accessed. getItemArgs.add(new MutableObject<ILogicalExpression>( new ConstantExpression(new AsterixConstantValue(new AInt32(0))))); ScalarFunctionCallExpression getItemExpr = new ScalarFunctionCallExpression( FunctionUtil.getFunctionInfo(BuiltinFunctions.GET_ITEM), getItemArgs); getItemExpr.setSourceLocation(simCheckFuncExpr.getSourceLocation()); // Replace the old similarity function call with the new getItemExpr. expRef.setValue(getItemExpr); return true; } return false; }
/** * Inject a dynamic cast function wrapping an existing expression * * @param funcInfo * the cast function * @param reqType * the required type * @param inputType * the original type * @param exprRef * the expression reference * @param argExpr * the original expression * @throws AlgebricksException */ private static void injectCastFunction(IFunctionInfo funcInfo, IAType reqType, IAType inputType, Mutable<ILogicalExpression> exprRef, ILogicalExpression argExpr) throws AlgebricksException { ScalarFunctionCallExpression cast = new ScalarFunctionCallExpression(funcInfo); cast.getArguments().add(new MutableObject<ILogicalExpression>(argExpr)); exprRef.setValue(cast); TypeCastUtils.setRequiredAndInputTypes(cast, reqType, inputType); }
/** * Whether the expression contains a missing filtering * * @param expr * @return true if the expression contains a missing filtering function call; false otherwise. */ private boolean containsMissingFiltering(ILogicalExpression expr) { if (expr.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) { return false; } ScalarFunctionCallExpression func = (ScalarFunctionCallExpression) expr; if (func.getFunctionIdentifier() == AlgebricksBuiltinFunctions.AND) { for (Mutable<ILogicalExpression> argumentRef : func.getArguments()) { if (containsMissingFiltering(argumentRef.getValue())) { return true; } } return false; } if (func.getFunctionIdentifier() != AlgebricksBuiltinFunctions.IS_MISSING) { return false; } return true; } }
Void arg) throws AlgebricksException { boolean changed = changeRec(expr, arg); if (!checkArgs(expr) || !expr.isFunctional()) { return new Pair<>(changed, expr); if (FUNC_ID_SET_THAT_SHOULD_NOT_BE_APPLIED.contains(expr.getFunctionIdentifier())) { return new Pair<>(false, null); if (expr.getFunctionIdentifier().equals(BuiltinFunctions.UNORDERED_LIST_CONSTRUCTOR) || expr.getFunctionIdentifier().equals(BuiltinFunctions.ORDERED_LIST_CONSTRUCTOR)) { AbstractCollectionType listType = (AbstractCollectionType) TypeCastUtils.getRequiredType(expr); if (listType != null && (listType.getItemType().getTypeTag() == ATypeTag.ANY if (expr.getFunctionIdentifier().equals(BuiltinFunctions.FIELD_ACCESS_BY_NAME)) { ARecordType rt = (ARecordType) _emptyTypeEnv.getType(expr.getArguments().get(0).getValue()); String str = ConstantExpressionUtil.getStringConstant(expr.getArguments().get(1).getValue()); int k = rt.getFieldIndex(str); if (k >= 0) { IAObject c = FUNC_ID_TO_CONSTANT.get(expr.getFunctionIdentifier()); if (c != null) { return new Pair<>(true, new ConstantExpression(new AsterixConstantValue(c)));
Function fn = (Function) fcExpr.getFunctionInfo(); fcExpr.getArguments());
public static void resetLOJMissingPlaceholderVarInGroupByOp(AccessMethodAnalysisContext analysisCtx, LogicalVariable newMissingPlaceholderVaraible, IOptimizationContext context) throws AlgebricksException { //reset the missing placeholder variable in groupby operator ScalarFunctionCallExpression isMissingFuncExpr = analysisCtx.getLOJIsMissingFuncInGroupBy(); isMissingFuncExpr.getArguments().clear(); VariableReferenceExpression newMissingVarRef = new VariableReferenceExpression(newMissingPlaceholderVaraible); newMissingVarRef.setSourceLocation(isMissingFuncExpr.getSourceLocation()); isMissingFuncExpr.getArguments().add(new MutableObject<ILogicalExpression>(newMissingVarRef)); //recompute type environment. OperatorPropertiesUtil.typeOpRec(analysisCtx.getLOJGroupbyOpRef(), context); }
private static ScalarFunctionCallExpression getNestedIsMissingCall(AbstractFunctionCallExpression call, OptimizableOperatorSubTree rightSubTree) throws AlgebricksException { ScalarFunctionCallExpression isMissingFuncExpr; if (call.getFunctionIdentifier().equals(AlgebricksBuiltinFunctions.NOT)) { if (call.getArguments().get(0).getValue().getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL) { if (((AbstractFunctionCallExpression) call.getArguments().get(0).getValue()).getFunctionIdentifier() .equals(AlgebricksBuiltinFunctions.IS_MISSING)) { isMissingFuncExpr = (ScalarFunctionCallExpression) call.getArguments().get(0).getValue(); if (isMissingFuncExpr.getArguments().get(0).getValue() .getExpressionTag() == LogicalExpressionTag.VARIABLE) { LogicalVariable var = ((VariableReferenceExpression) isMissingFuncExpr.getArguments().get(0).getValue()) .getVariableReference(); List<LogicalVariable> liveSubplanVars = new ArrayList<>(); VariableUtilities.getSubplanLocalLiveVariables(rightSubTree.getRoot(), liveSubplanVars); if (liveSubplanVars.contains(var)) { return isMissingFuncExpr; } } } } } return null; }
ScalarFunctionCallExpression funcExpr = (ScalarFunctionCallExpression) assignOp.getExpressions() .get(expectedRecordIndex).getValue(); fid = funcExpr.getFunctionIdentifier();
public static ScalarFunctionCallExpression getComparisonExpr(String simFuncName, ArrayList<Mutable<ILogicalExpression>> cmpArgs) { if (simFuncName.equals(JACCARD_FUNCTION_NAME)) { return new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(AlgebricksBuiltinFunctions.GE), cmpArgs); } else if (simFuncName.equals(EDIT_DISTANCE_FUNCTION_NAME)) { return new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(AlgebricksBuiltinFunctions.LE), cmpArgs); } return null; }
similarityArgs.add(new MutableObject<ILogicalExpression>( new ConstantExpression(new AsterixConstantValue(jaccThresh)))); simCheckFuncExpr = new ScalarFunctionCallExpression( FunctionUtil.getFunctionInfo(BuiltinFunctions.SIMILARITY_JACCARD_CHECK), similarityArgs); simCheckFuncExpr.setSourceLocation(funcExpr.getSourceLocation()); similarityArgs.add( new MutableObject<ILogicalExpression>(new ConstantExpression(new AsterixConstantValue(edThresh)))); simCheckFuncExpr = new ScalarFunctionCallExpression( FunctionUtil.getFunctionInfo(BuiltinFunctions.EDIT_DISTANCE_CHECK), similarityArgs); simCheckFuncExpr.setSourceLocation(funcExpr.getSourceLocation()); simCheckFuncExpr.getAnnotations().putAll(funcExpr.getAnnotations());
SourceLocation sourceLoc = simCheckFuncExpr.getSourceLocation(); ScalarFunctionCallExpression selectGetItemExpr = new ScalarFunctionCallExpression( FunctionUtil.getFunctionInfo(BuiltinFunctions.GET_ITEM), selectGetItemArgs); selectGetItemExpr.setSourceLocation(sourceLoc); ScalarFunctionCallExpression assignGetItemExpr = new ScalarFunctionCallExpression( FunctionUtil.getFunctionInfo(BuiltinFunctions.GET_ITEM), assignGetItemArgs); assignGetItemExpr.setSourceLocation(sourceLoc);
matched = true; ScalarFunctionCallExpression notNullFunc = new ScalarFunctionCallExpression( FunctionUtil.getFunctionInfo(BuiltinFunctions.CHECK_UNKNOWN)); notNullFunc.getArguments().add(new MutableObject<ILogicalExpression>(arg));
if (func.getFunctionIdentifier() == AlgebricksBuiltinFunctions.AND) { for (Mutable<ILogicalExpression> argumentRef : func.getArguments()) { if (containsNotMissingFiltering(argumentRef.getValue())) { return true; if (func.getFunctionIdentifier() != AlgebricksBuiltinFunctions.NOT) { return false; ILogicalExpression arg = func.getArguments().get(0).getValue(); if (arg.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) { return false; if (func2.getFunctionIdentifier() != AlgebricksBuiltinFunctions.IS_MISSING) { return false;
private ILogicalExpression getScalarExpr(FunctionIdentifier func, ILogicalExpression interval) { List<Mutable<ILogicalExpression>> intervalArg = new ArrayList<>(); intervalArg.add(new MutableObject<ILogicalExpression>(interval)); ScalarFunctionCallExpression fnExpr = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(func), intervalArg); fnExpr.setSourceLocation(interval.getSourceLocation()); return fnExpr; }