private boolean hasTranslatableInterval(AbstractFunctionCallExpression funcExpr) { if (TRANSLATABLE_INTERVALS.contains(funcExpr.getFunctionIdentifier())) { return true; } return false; }
private void analyzeFunctionExpr(AbstractFunctionCallExpression funcExpr, AccessMethodAnalysisContext analysisCtx, IOptimizationContext context, IVariableTypeEnvironment typeEnvironment) throws AlgebricksException { FunctionIdentifier funcIdent = funcExpr.getFunctionIdentifier(); if (funcIdent == AlgebricksBuiltinFunctions.LE || funcIdent == AlgebricksBuiltinFunctions.GE || funcIdent == AlgebricksBuiltinFunctions.LT || funcIdent == AlgebricksBuiltinFunctions.GT || funcIdent == AlgebricksBuiltinFunctions.EQ) { AccessMethodUtils.analyzeFuncExprArgsForOneConstAndVarAndUpdateAnalysisCtx(funcExpr, analysisCtx, context, typeEnvironment); } }
@Override public boolean splitIntoConjuncts(List<Mutable<ILogicalExpression>> conjs) { if (!getFunctionIdentifier().equals(AlgebricksBuiltinFunctions.AND) || arguments.size() <= 1) { return false; } else { conjs.addAll(arguments); return true; } }
public static boolean isAccessByNameToFieldRecord(ILogicalExpression expr) { if (expr.getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL) { AbstractFunctionCallExpression fc = (AbstractFunctionCallExpression) expr; FunctionIdentifier fid = fc.getFunctionIdentifier(); if (fid.equals(BuiltinFunctions.FIELD_ACCESS_BY_NAME)) { return true; } } return false; }
private Object getTypeForFunction(AbstractFunctionCallExpression expr, IVariableTypeEnvironment env, IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException { return BuiltinFunctions.getResultTypeComputer(expr.getFunctionIdentifier()).computeType(expr, env, metadataProvider); } }
private static AbstractFunctionCallExpression asFunctionCallExpression(ILogicalExpression ex, FunctionIdentifier fi) { AbstractFunctionCallExpression fctCall = (ex.getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL ? (AbstractFunctionCallExpression) ex : null); if (fctCall != null && (fi == null || fctCall.getFunctionIdentifier().equals(fi))) return fctCall; return null; }
private static ILogicalExpression resolveFieldExpression(AbstractLogicalExpression constr, Object accessKey, IVariableTypeEnvironment typeEnvironment, FieldResolver resolver) throws AlgebricksException { if (constr.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) { return null; } AbstractFunctionCallExpression fce = (AbstractFunctionCallExpression) constr; if (!fce.getFunctionIdentifier().equals(BuiltinFunctions.OPEN_RECORD_CONSTRUCTOR) && !fce.getFunctionIdentifier().equals(BuiltinFunctions.CLOSED_RECORD_CONSTRUCTOR)) { return null; } return resolver.resolve(accessKey, fce, typeEnvironment); }
private boolean isEquiJoin(Mutable<ILogicalExpression> conditionExpr) { AbstractLogicalExpression expr = (AbstractLogicalExpression) conditionExpr.getValue(); if (expr.getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL) { AbstractFunctionCallExpression funcExpr = (AbstractFunctionCallExpression) expr; FunctionIdentifier funcIdent = funcExpr.getFunctionIdentifier(); if (funcIdent != AlgebricksBuiltinFunctions.AND && funcIdent != AlgebricksBuiltinFunctions.EQ) { return false; } } return true; } }
public static boolean isRunnableAccessToFieldRecord(ILogicalExpression expr) { if (expr.getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL) { AbstractFunctionCallExpression fc = (AbstractFunctionCallExpression) expr; FunctionIdentifier fid = fc.getFunctionIdentifier(); if (AnalysisUtil.isRunnableFieldAccessFunction(fid)) { return true; } } return false; }
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 void gatherFunctionCalls(Mutable<ILogicalExpression> exprRef, List<Mutable<ILogicalExpression>> funcExprs) { AbstractLogicalExpression expr = (AbstractLogicalExpression) exprRef.getValue(); if (expr.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) { return; } // Check whether the function is a function we want to push. AbstractFunctionCallExpression funcExpr = (AbstractFunctionCallExpression) expr; if (toPushFuncIdents.contains(funcExpr.getFunctionIdentifier())) { funcExprs.add(exprRef); } // Traverse arguments. for (Mutable<ILogicalExpression> funcArg : funcExpr.getArguments()) { gatherFunctionCalls(funcArg, funcExprs); } }
@Override public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env, IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException { AbstractFunctionCallExpression functionCallExpression = (AbstractFunctionCallExpression) expression; String funcName = functionCallExpression.getFunctionIdentifier().getName(); // Boolean type computer doesn't follow the null/missing-in/out semantics. return TypeComputeUtils.resolveResultType(expression, env, (index, type, sourceLoc) -> checkArgType(funcName, index, type, sourceLoc), this::getResultType, false); }
@Override public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { AbstractFunctionCallExpression f = getFunctionCall(opRef); if (f == null) { return false; } return BuiltinFunctions.getDatasourceTransformer(f.getFunctionIdentifier()).rewrite(opRef, context); }
public static boolean isFunctionExpression(Mutable<ILogicalExpression> mutableLe, AbstractFunctionCallExpression afce) { ILogicalExpression le = mutableLe.getValue(); if (le.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) { return false; } AbstractFunctionCallExpression fc = (AbstractFunctionCallExpression) le; if (!fc.getFunctionIdentifier().equals(afce)) { return false; } return true; } }
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 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 void sweepExpression(ILogicalExpression expr) throws AlgebricksException { if (expr.getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL && !expr.isFunctional()) { AbstractFunctionCallExpression fce = (AbstractFunctionCallExpression) expr; throw new CompilationException(ErrorCode.COMPILATION_ERROR, fce.getSourceLocation(), "Found non-functional function " + fce.getFunctionIdentifier()); } }
public static boolean isAccessToFieldRecord(ILogicalExpression expr) { if (expr.getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL) { AbstractFunctionCallExpression fc = (AbstractFunctionCallExpression) expr; FunctionIdentifier fid = fc.getFunctionIdentifier(); if (fid.equals(BuiltinFunctions.FIELD_ACCESS_BY_INDEX) || fid.equals(BuiltinFunctions.FIELD_ACCESS_BY_NAME) || fid.equals(BuiltinFunctions.FIELD_ACCESS_NESTED)) { return true; } } return false; }
@Override public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env, IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException { AbstractFunctionCallExpression functionCallExpression = (AbstractFunctionCallExpression) expression; String funcName = functionCallExpression.getFunctionIdentifier().getName(); return TypeComputeUtils.resolveResultType(expression, env, (index, type, sourceLoc) -> checkArgType(funcName, index, type, sourceLoc), this::getResultType, propagateNullAndMissing()); }
private IFunctionDescriptor resolveFunction(AbstractFunctionCallExpression expr, IVariableTypeEnvironment env, JobGenContext context) throws AlgebricksException { FunctionIdentifier fnId = expr.getFunctionIdentifier(); IFunctionDescriptor fd = functionManager.lookupFunction(fnId); fd.setSourceLocation(expr.getSourceLocation()); IFunctionTypeInferer fnTypeInfer = functionManager.lookupFunctionTypeInferer(fnId); if (fnTypeInfer != null) { CompilerProperties compilerProps = ((IApplicationContext) context.getAppContext()).getCompilerProperties(); fnTypeInfer.infer(expr, fd, env, compilerProps); } return fd; } }