protected static AbstractFunctionCallExpression createFunctionCallExpression(FunctionIdentifier fid, SourceLocation sourceLoc) { ScalarFunctionCallExpression callExpr = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(fid)); callExpr.setSourceLocation(sourceLoc); return callExpr; }
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; }
private ILogicalExpression createSelectCondition(List<Mutable<ILogicalExpression>> predList) { if (predList.size() > 1) { IFunctionInfo finfo = FunctionUtil.getFunctionInfo(AlgebricksBuiltinFunctions.AND); ScalarFunctionCallExpression andExpr = new ScalarFunctionCallExpression(finfo, predList); andExpr.setSourceLocation(predList.get(0).getValue().getSourceLocation()); return andExpr; } return predList.get(0).getValue(); }
private ILogicalExpression getScalarExpr(FunctionIdentifier func, ILogicalExpression interval1, ILogicalExpression interval2) { List<Mutable<ILogicalExpression>> intervalArg = new ArrayList<>(); intervalArg.add(new MutableObject<ILogicalExpression>(interval1)); intervalArg.add(new MutableObject<ILogicalExpression>(interval2)); ScalarFunctionCallExpression fnExpr = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(func), intervalArg); fnExpr.setSourceLocation(interval1.getSourceLocation()); return fnExpr; }
protected Mutable<ILogicalExpression> generateNoMatchedPrecedingWhenBranchesFilter( List<ILogicalExpression> inputBooleanExprs, SourceLocation sourceLoc) { List<Mutable<ILogicalExpression>> arguments = new ArrayList<>(); for (ILogicalExpression inputBooleanExpr : inputBooleanExprs) { // A NULL/MISSING valued WHEN expression does not lead to the corresponding THEN // execution. // Therefore, we should check a previous WHEN boolean condition is not unknown. arguments.add(generateAndNotIsUnknownWrap(inputBooleanExpr)); } ScalarFunctionCallExpression hasBeenExecutedExpr = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.OR), arguments); hasBeenExecutedExpr.setSourceLocation(sourceLoc); ScalarFunctionCallExpression notExpr = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.NOT), new ArrayList<>(Collections.singletonList(new MutableObject<>(hasBeenExecutedExpr)))); notExpr.setSourceLocation(sourceLoc); return new MutableObject<>(notExpr); }
protected Mutable<ILogicalExpression> generateAndNotIsUnknownWrap(ILogicalExpression logicalExpr) { SourceLocation sourceLoc = logicalExpr.getSourceLocation(); List<Mutable<ILogicalExpression>> arguments = new ArrayList<>(); arguments.add(new MutableObject<>(logicalExpr)); ScalarFunctionCallExpression isUnknownExpr = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.IS_UNKNOWN), new ArrayList<>(Collections.singletonList(new MutableObject<>(logicalExpr)))); isUnknownExpr.setSourceLocation(sourceLoc); ScalarFunctionCallExpression notExpr = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.NOT), new ArrayList<>(Collections.singletonList(new MutableObject<>(isUnknownExpr)))); notExpr.setSourceLocation(sourceLoc); arguments.add(new MutableObject<>(notExpr)); ScalarFunctionCallExpression andExpr = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.AND), arguments); andExpr.setSourceLocation(sourceLoc); return new MutableObject<>(andExpr); }
private Mutable<ILogicalExpression> createPrimaryKeysEqJoinCondition(List<LogicalVariable> originalSubTreePKs, List<LogicalVariable> surrogateSubTreePKs, SourceLocation sourceLoc) { List<Mutable<ILogicalExpression>> eqExprs = new ArrayList<Mutable<ILogicalExpression>>(); int numPKVars = originalSubTreePKs.size(); for (int i = 0; i < numPKVars; i++) { List<Mutable<ILogicalExpression>> args = new ArrayList<Mutable<ILogicalExpression>>(); VariableReferenceExpression surrogateSubTreePKRef = new VariableReferenceExpression(surrogateSubTreePKs.get(i)); surrogateSubTreePKRef.setSourceLocation(sourceLoc); args.add(new MutableObject<ILogicalExpression>(surrogateSubTreePKRef)); VariableReferenceExpression originalSubTreePKRef = new VariableReferenceExpression(originalSubTreePKs.get(i)); originalSubTreePKRef.setSourceLocation(sourceLoc); args.add(new MutableObject<ILogicalExpression>(originalSubTreePKRef)); ScalarFunctionCallExpression eqFunc = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(AlgebricksBuiltinFunctions.EQ), args); eqFunc.setSourceLocation(sourceLoc); eqExprs.add(new MutableObject<ILogicalExpression>(eqFunc)); } if (eqExprs.size() == 1) { return eqExprs.get(0); } else { ScalarFunctionCallExpression andFunc = new ScalarFunctionCallExpression( FunctionUtil.getFunctionInfo(AlgebricksBuiltinFunctions.AND), eqExprs); andFunc.setSourceLocation(sourceLoc); return new MutableObject<ILogicalExpression>(andFunc); } }
@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; }
protected AbstractFunctionCallExpression createRecordConstructor(List<Pair<Expression, Identifier>> fieldList, Mutable<ILogicalOperator> inputOp, SourceLocation sourceLoc) throws CompilationException { List<Mutable<ILogicalExpression>> args = new ArrayList<>(); for (Pair<Expression, Identifier> field : fieldList) { ILogicalExpression fieldNameExpr = langExprToAlgExpression(new LiteralExpr(new StringLiteral(field.second.getValue())), inputOp).first; args.add(new MutableObject<>(fieldNameExpr)); ILogicalExpression fieldExpr = langExprToAlgExpression(field.first, inputOp).first; args.add(new MutableObject<>(fieldExpr)); } ScalarFunctionCallExpression recordConstr = new ScalarFunctionCallExpression( FunctionUtil.getFunctionInfo(BuiltinFunctions.OPEN_RECORD_CONSTRUCTOR), args); recordConstr.setSourceLocation(sourceLoc); return recordConstr; }
private static AbstractFunctionCallExpression getOpenOrNestedFieldAccessFunction(Mutable<ILogicalExpression> varRef, List<String> fields, SourceLocation sourceLoc) { ScalarFunctionCallExpression func; if (fields.size() > 1) { IAObject fieldList = stringListToAOrderedList(fields); Mutable<ILogicalExpression> fieldRef = constantToMutableLogicalExpression(fieldList); // Create an expression for the nested case func = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.FIELD_ACCESS_NESTED), varRef, fieldRef); } else { IAObject fieldList = new AString(fields.get(0)); Mutable<ILogicalExpression> fieldRef = constantToMutableLogicalExpression(fieldList); // Create an expression for the open field case (By name) func = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.FIELD_ACCESS_BY_NAME), varRef, fieldRef); } func.setSourceLocation(sourceLoc); return func; }
private boolean rewriteFunctionArgument(Mutable<ILogicalExpression> argRef, IAType funcOutputType, IVariableTypeEnvironment env) throws AlgebricksException { ILogicalExpression argExpr = argRef.getValue(); IAType type = (IAType) env.getType(argExpr); if (TypeResolverUtil.needsCast(funcOutputType, type)) { // Injects a cast call to cast the data type to the produced type of the function call. ScalarFunctionCallExpression castFunc = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.CAST_TYPE), new ArrayList<>(Collections.singletonList(new MutableObject<>(argExpr)))); castFunc.setSourceLocation(argExpr.getSourceLocation()); TypeCastUtils.setRequiredAndInputTypes(castFunc, funcOutputType, type); argRef.setValue(castFunc); return true; } return false; } }
public static void prepareMetaKeyAccessExpression(List<String> field, LogicalVariable resVar, List<Mutable<ILogicalExpression>> assignExpressions, List<LogicalVariable> vars, List<Mutable<ILogicalExpression>> varRefs, IVariableContext context, SourceLocation sourceLoc) { IAObject value = (field.size() > 1) ? new AOrderedList(field) : new AString(field.get(0)); ScalarFunctionCallExpression metaKeyFunction = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.META_KEY)); metaKeyFunction.setSourceLocation(sourceLoc); VariableReferenceExpression resVarRef = new VariableReferenceExpression(resVar); resVarRef.setSourceLocation(sourceLoc); metaKeyFunction.getArguments().add(new MutableObject<ILogicalExpression>(resVarRef)); metaKeyFunction.getArguments() .add(new MutableObject<>(new ConstantExpression(new AsterixConstantValue(value)))); assignExpressions.add(new MutableObject<ILogicalExpression>(metaKeyFunction)); LogicalVariable v = context.newVar(); vars.add(v); if (varRefs != null) { VariableReferenceExpression vRef = new VariableReferenceExpression(v); vRef.setSourceLocation(sourceLoc); varRefs.add(new MutableObject<ILogicalExpression>(vRef)); } }
private ILogicalOperator createFieldAccessAssignOperator(LogicalVariable recordVar, Set<LogicalVariable> inputLiveVars, SourceLocation sourceLoc) { List<LogicalVariable> fieldAccessVars = new ArrayList<>(); List<Mutable<ILogicalExpression>> fieldAccessExprs = new ArrayList<>(); // Adds field access by name. for (LogicalVariable inputLiveVar : inputLiveVars) { if (!correlatedKeyVars.contains(inputLiveVar)) { // field Var LogicalVariable newVar = context.newVar(); fieldAccessVars.add(newVar); // fieldAcess expr List<Mutable<ILogicalExpression>> argRefs = new ArrayList<>(); VariableReferenceExpression recordVarRef = new VariableReferenceExpression(recordVar); recordVarRef.setSourceLocation(sourceLoc); argRefs.add(new MutableObject<>(recordVarRef)); argRefs.add(new MutableObject<>(new ConstantExpression( new AsterixConstantValue(new AString(Integer.toString(inputLiveVar.getId())))))); ScalarFunctionCallExpression faExpr = new ScalarFunctionCallExpression( FunctionUtil.getFunctionInfo(BuiltinFunctions.FIELD_ACCESS_BY_NAME), argRefs); faExpr.setSourceLocation(sourceLoc); fieldAccessExprs.add(new MutableObject<>(faExpr)); // Updates variable mapping for ancestor operators. updateInputToOutputVarMapping(inputLiveVar, newVar, false); } } AssignOperator assignOp = new AssignOperator(fieldAccessVars, fieldAccessExprs); assignOp.setSourceLocation(sourceLoc); return assignOp; }
private Pair<ILogicalOperator, LogicalVariable> createRecordConstructorAssignOp(Set<LogicalVariable> inputLiveVars, SourceLocation sourceLoc) { // Creates a nested record. List<Mutable<ILogicalExpression>> recordConstructorArgs = new ArrayList<>(); for (LogicalVariable inputLiveVar : inputLiveVars) { if (!correlatedKeyVars.contains(inputLiveVar)) { recordConstructorArgs.add(new MutableObject<>(new ConstantExpression( new AsterixConstantValue(new AString(Integer.toString(inputLiveVar.getId())))))); VariableReferenceExpression inputLiveVarRef = new VariableReferenceExpression(inputLiveVar); inputLiveVarRef.setSourceLocation(sourceLoc); recordConstructorArgs.add(new MutableObject<>(inputLiveVarRef)); } } LogicalVariable recordVar = context.newVar(); ScalarFunctionCallExpression openRecConstr = new ScalarFunctionCallExpression( FunctionUtil.getFunctionInfo(BuiltinFunctions.OPEN_RECORD_CONSTRUCTOR), recordConstructorArgs); openRecConstr.setSourceLocation(sourceLoc); Mutable<ILogicalExpression> recordExprRef = new MutableObject<ILogicalExpression>(openRecConstr); AssignOperator assignOp = new AssignOperator(recordVar, recordExprRef); assignOp.setSourceLocation(sourceLoc); return new Pair<>(assignOp, recordVar); }
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; }
private static ScalarFunctionCallExpression createFieldAccessExpression(ILogicalExpression target, List<String> field, SourceLocation sourceLoc) { FunctionIdentifier functionIdentifier; IAObject value; if (field.size() > 1) { functionIdentifier = BuiltinFunctions.FIELD_ACCESS_NESTED; value = new AOrderedList(field); } else { functionIdentifier = BuiltinFunctions.FIELD_ACCESS_BY_NAME; value = new AString(field.get(0)); } IFunctionInfo finfoAccess = FunctionUtil.getFunctionInfo(functionIdentifier); ScalarFunctionCallExpression faExpr = new ScalarFunctionCallExpression(finfoAccess, new MutableObject<>(target), new MutableObject<>(new ConstantExpression(new AsterixConstantValue(value)))); faExpr.setSourceLocation(sourceLoc); return faExpr; } }
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; } }
private static AbstractFunctionCallExpression getClosedFieldAccessFunction(Mutable<ILogicalExpression> varRef, int position, SourceLocation sourceLoc) { Mutable<ILogicalExpression> indexRef = new MutableObject<>(new ConstantExpression(new AsterixConstantValue(new AInt32(position)))); ScalarFunctionCallExpression fnExpr = new ScalarFunctionCallExpression( FunctionUtil.getFunctionInfo(BuiltinFunctions.FIELD_ACCESS_BY_INDEX), varRef, indexRef); fnExpr.setSourceLocation(sourceLoc); return fnExpr; }
new MutableObject<>(recordVarRef), new MutableObject<>( new ConstantExpression(new AsterixConstantValue(new AInt32(parameterIndex / 2))))); // Every two parameters corresponds to a field. expr.setSourceLocation(funcExpr.getSourceLocation()); EquivalenceClass equivClass = new EquivalenceClass(Collections.singletonList(fieldVar), fieldVar, Collections.singletonList(expr));
@SuppressWarnings("unchecked") private static ILogicalExpression createFieldAccessByIndex(ARecordType recType, AbstractFunctionCallExpression fce) { String s = ConstantExpressionUtil.getStringArgument(fce, 1); if (s == null) { return null; } int k = recType.getFieldIndex(s); if (k < 0) { return null; } ScalarFunctionCallExpression faExpr = new ScalarFunctionCallExpression( FunctionUtil.getFunctionInfo(BuiltinFunctions.FIELD_ACCESS_BY_INDEX), fce.getArguments().get(0), new MutableObject<>(new ConstantExpression(new AsterixConstantValue(new AInt32(k))))); faExpr.setSourceLocation(fce.getSourceLocation()); return faExpr; } }