private boolean transformFunctionCallExpression(AbstractFunctionCallExpression fce) throws AlgebricksException { boolean modified = false; for (Mutable<ILogicalExpression> arg : fce.getArguments()) { if (transform(arg)) { modified = true; } } return modified; }
private IAType computeContentType(IVariableTypeEnvironment env, AbstractFunctionCallExpression f) throws AlgebricksException { IAType currentType = null; for (int k = 0; k < f.getArguments().size(); k++) { IAType type = (IAType) env.getType(f.getArguments().get(k).getValue()); if (type.getTypeTag() == ATypeTag.UNION || (currentType != null && !currentType.equals(type))) { return null; } currentType = type; } return currentType; }
/** * 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 static ILogicalExpression findFieldByNameFromRecordConstructor(Object fldName, AbstractFunctionCallExpression fce) { Iterator<Mutable<ILogicalExpression>> fldIter = fce.getArguments().iterator(); while (fldIter.hasNext()) { ILogicalExpression fldExpr = fldIter.next().getValue(); if (fldName.equals(ConstantExpressionUtil.getStringConstant(fldExpr))) { return fldIter.next().getValue(); } fldIter.next(); } return null; }
private IScalarEvaluatorFactory[] codegenArguments(AbstractFunctionCallExpression expr, IVariableTypeEnvironment env, IOperatorSchema[] inputSchemas, JobGenContext context) throws AlgebricksException { List<Mutable<ILogicalExpression>> arguments = expr.getArguments(); int n = arguments.size(); IScalarEvaluatorFactory[] args = new IScalarEvaluatorFactory[n]; int i = 0; for (Mutable<ILogicalExpression> a : arguments) { args[i++] = createEvaluatorFactory(a.getValue(), env, inputSchemas, context); } return args; }
@Override public void infer(ILogicalExpression expr, IFunctionDescriptor fd, IVariableTypeEnvironment context, CompilerProperties compilerProps) throws AlgebricksException { AbstractFunctionCallExpression fce = (AbstractFunctionCallExpression) expr; IAType[] argsTypes = new IAType[fce.getArguments().size()]; int i = 0; for (Mutable<ILogicalExpression> arg : fce.getArguments()) { argsTypes[i] = TypeComputeUtils.getActualType((IAType) context.getType(arg.getValue())); i++; } fd.setImmutableStates((Object[]) argsTypes); } };
private boolean visitFunctionExpression(AbstractFunctionCallExpression expr, Void arg) throws AlgebricksException { for (Mutable<ILogicalExpression> argRef : expr.getArguments()) { if (argRef.getValue().accept(this, arg)) { return true; } } return false; } }
public static Pair<String, String> getExternalDatasetInfo(UnnestMapOperator op) throws AlgebricksException { AbstractFunctionCallExpression unnestExpr = (AbstractFunctionCallExpression) op.getExpressionRef().getValue(); String dataverseName = AccessMethodUtils.getStringConstant(unnestExpr.getArguments().get(0)); String datasetName = AccessMethodUtils.getStringConstant(unnestExpr.getArguments().get(1)); return new Pair<>(dataverseName, datasetName); }
@Override public void infer(ILogicalExpression expr, IFunctionDescriptor fd, IVariableTypeEnvironment context, CompilerProperties compilerProps) throws AlgebricksException { AbstractFunctionCallExpression f = (AbstractFunctionCallExpression) expr; IAType type0 = (IAType) context.getType(f.getArguments().get(0).getValue()); IAType type1 = (IAType) context.getType(f.getArguments().get(1).getValue()); fd.setImmutableStates(type0, type1); } }
private boolean checkArgs(AbstractFunctionCallExpression expr) { for (Mutable<ILogicalExpression> r : expr.getArguments()) { if (r.getValue().getExpressionTag() != LogicalExpressionTag.CONSTANT) { return false; } } return true; } }
private boolean isEqJoinCondition(ILogicalExpression expr) { AbstractFunctionCallExpression funcExpr = (AbstractFunctionCallExpression) expr; if (funcExpr.getFunctionIdentifier().equals(AlgebricksBuiltinFunctions.EQ)) { ILogicalExpression arg1 = funcExpr.getArguments().get(0).getValue(); ILogicalExpression arg2 = funcExpr.getArguments().get(1).getValue(); if (arg1.getExpressionTag() == LogicalExpressionTag.VARIABLE && arg2.getExpressionTag() == LogicalExpressionTag.VARIABLE) { return true; } } return false; }
private ILogicalExpression createEqExpr(LogicalVariable lhsVar, IAObject rhsValue, SourceLocation sourceLoc) throws CompilationException { VariableReferenceExpression lhsExpr = new VariableReferenceExpression(lhsVar); lhsExpr.setSourceLocation(sourceLoc); ILogicalExpression rhsExpr = translateConstantValue(rhsValue, sourceLoc); AbstractFunctionCallExpression opExpr = createFunctionCallExpressionForBuiltinOperator(OperatorType.EQ, sourceLoc); opExpr.getArguments().add(new MutableObject<>(lhsExpr)); opExpr.getArguments().add(new MutableObject<>(rhsExpr)); return opExpr; }
@Override public void infer(ILogicalExpression expr, IFunctionDescriptor fd, IVariableTypeEnvironment context, CompilerProperties compilerProps) throws AlgebricksException { AbstractFunctionCallExpression f = (AbstractFunctionCallExpression) expr; IAType outType = (IAType) context.getType(expr); IAType type0 = (IAType) context.getType(f.getArguments().get(0).getValue()); IAType type1 = (IAType) context.getType(f.getArguments().get(1).getValue()); fd.setImmutableStates(outType, type0, type1); } }
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 rewriteFunction(ILogicalOperator op, AbstractFunctionCallExpression func, IntPredicate argChecker, IOptimizationContext context) throws AlgebricksException { IVariableTypeEnvironment env = op.computeInputTypeEnvironment(context); IAType producedType = (IAType) env.getType(func); List<Mutable<ILogicalExpression>> argRefs = func.getArguments(); int argSize = argRefs.size(); boolean rewritten = false; for (int argIndex = 0; argIndex < argSize; argIndex++) { if (argChecker == null || argChecker.test(argIndex)) { rewritten |= rewriteFunctionArgument(argRefs.get(argIndex), producedType, env); } } return rewritten; }
public static void findVariableExpressions(Mutable<ILogicalExpression> mutableLe, List<Mutable<ILogicalExpression>> finds) { ILogicalExpression le = mutableLe.getValue(); if (le.getExpressionTag() == LogicalExpressionTag.VARIABLE) { finds.add(mutableLe); } else if (le.getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL) { AbstractFunctionCallExpression afce = (AbstractFunctionCallExpression) le; for (Mutable<ILogicalExpression> argExp : afce.getArguments()) { findVariableExpressions(argExp, finds); } } }
private boolean changeRec(AbstractFunctionCallExpression expr, Void arg) throws AlgebricksException { boolean changed = false; for (Mutable<ILogicalExpression> r : expr.getArguments()) { Pair<Boolean, ILogicalExpression> p2 = r.getValue().accept(this, arg); if (p2.first) { r.setValue(p2.second); changed = true; } } return changed; }
@Override public void infer(ILogicalExpression expr, IFunctionDescriptor fd, IVariableTypeEnvironment context, CompilerProperties compilerProps) throws AlgebricksException { AbstractFunctionCallExpression fce = (AbstractFunctionCallExpression) expr; IAType t = (IAType) context.getType(fce.getArguments().get(0).getValue()); fd.setImmutableStates(TypeComputeUtils.getActualType(t)); } };
@Override public void infer(ILogicalExpression expr, IFunctionDescriptor fd, IVariableTypeEnvironment context, CompilerProperties compilerProps) throws AlgebricksException { AbstractFunctionCallExpression funcExpr = (AbstractFunctionCallExpression) expr; IAType rt = TypeCastUtils.getRequiredType(funcExpr); IAType it = (IAType) context.getType(funcExpr.getArguments().get(0).getValue()); fd.setImmutableStates(rt, it); } }
private boolean probeIsOnLhs(IOptimizableFuncExpr optFuncExpr, OptimizableOperatorSubTree probeSubTree) { if (probeSubTree == null) { if (optFuncExpr.getConstantExpressions().length == 0) { return optFuncExpr.getLogicalExpr(0) == null; } // We are optimizing a selection query. Search key is a constant. Return true if constant is on lhs. return optFuncExpr.getFuncExpr().getArguments().get(0) == optFuncExpr.getConstantExpr(0); } else { // We are optimizing a join query. Determine whether the feeding variable is on the lhs. return (optFuncExpr.getOperatorSubTree(0) == null || optFuncExpr.getOperatorSubTree(0) == probeSubTree); } }