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 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); } } }
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()); } }
funcExpr.getSourceLocation(), LogRedactionUtil.userData(funcExpr.toString()));
@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); } }
funcExpr.getSourceLocation(), fi, oldExprs.size());
private void rewriteAggregateInNestedSubplan(LogicalVariable oldAggVar, AbstractOperatorWithNestedPlans nspOp, AggregateFunctionCallExpression aggFun, LogicalVariable newAggVar, IOptimizationContext context) throws AlgebricksException { for (int j = 0; j < nspOp.getNestedPlans().size(); j++) { AggregateOperator aggOp = (AggregateOperator) nspOp.getNestedPlans().get(j).getRoots().get(0).getValue(); int n = aggOp.getVariables().size(); for (int i = 0; i < n; i++) { LogicalVariable v = aggOp.getVariables().get(i); if (v.equals(oldAggVar)) { AbstractFunctionCallExpression oldAggExpr = (AbstractFunctionCallExpression) aggOp.getExpressions().get(i).getValue(); AggregateFunctionCallExpression newAggFun = BuiltinFunctions .makeAggregateFunctionExpression(aggFun.getFunctionIdentifier(), new ArrayList<>()); newAggFun.setSourceLocation(oldAggExpr.getSourceLocation()); for (Mutable<ILogicalExpression> arg : oldAggExpr.getArguments()) { ILogicalExpression cloned = arg.getValue().cloneExpression(); newAggFun.getArguments().add(new MutableObject<>(cloned)); } aggOp.getVariables().add(newAggVar); aggOp.getExpressions().add(new MutableObject<>(newAggFun)); context.computeAndSetTypeEnvironmentForOperator(aggOp); break; } } } }
AUnionType ut = (AUnionType) t; if (!ut.isUnknownableType()) { throw new TypeMismatchException(fun.getSourceLocation(), funcName, 0, actualTypeTag, ATypeTag.MULTISET, ATypeTag.ARRAY); return act.getItemType(); throw new TypeMismatchException(fun.getSourceLocation(), funcName, 0, actualTypeTag, ATypeTag.MULTISET, ATypeTag.ARRAY); return BuiltinType.ANY; default: throw new TypeMismatchException(fun.getSourceLocation(), funcName, 0, actualTypeTag, ATypeTag.MULTISET, ATypeTag.ARRAY);
FunctionIdentifier fid = f.getFunctionIdentifier(); if (!fid.equals(BuiltinFunctions.INDEX_SEARCH)) { throw new CompilationException(ErrorCode.COMPILATION_ILLEGAL_STATE, f.getSourceLocation(), fid.getName());
Deque<String> fieldPathStack = new ArrayDeque<>(); ARecordType inputRecordType = getRecordTypeFromType(funcName, type0, funcExpr.getSourceLocation()); if (inputRecordType == null) { return BuiltinType.ANY; AOrderedListType inputOrderedListType = TypeComputeUtils.extractOrderedListType(inputListType); if (inputOrderedListType == null) { throw new TypeMismatchException(funcExpr.getSourceLocation(), funcName, 1, inputListType.getTypeTag(), ATypeTag.ARRAY);
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; } }
recordVarRef.setSourceLocation(funcExpr.getSourceLocation()); ScalarFunctionCallExpression expr = new ScalarFunctionCallExpression( FunctionUtil.getFunctionInfo(BuiltinFunctions.FIELD_ACCESS_BY_INDEX), 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));
@Override public StorageComponentsDatasource toDatasource(IOptimizationContext context, AbstractFunctionCallExpression f) throws AlgebricksException { String dataverseName = getString(f.getArguments(), 0); String datasetName = getString(f.getArguments(), 1); MetadataProvider metadataProvider = (MetadataProvider) context.getMetadataProvider(); Dataset dataset = metadataProvider.findDataset(dataverseName, datasetName); if (dataset == null) { throw new CompilationException(ErrorCode.UNKNOWN_DATASET_IN_DATAVERSE, f.getSourceLocation(), datasetName, dataverseName); } return new StorageComponentsDatasource(context.getComputationNodeDomain(), dataset.getDatasetId()); } }
@Override public DatasetResourcesDatasource toDatasource(IOptimizationContext context, AbstractFunctionCallExpression f) throws AlgebricksException { String dataverseName = getString(f.getArguments(), 0); String datasetName = getString(f.getArguments(), 1); MetadataProvider metadataProvider = (MetadataProvider) context.getMetadataProvider(); Dataset dataset = metadataProvider.findDataset(dataverseName, datasetName); if (dataset == null) { throw new CompilationException(ErrorCode.UNKNOWN_DATASET_IN_DATAVERSE, f.getSourceLocation(), datasetName, dataverseName); } return new DatasetResourcesDatasource(context.getComputationNodeDomain(), dataset.getDatasetId()); } }
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; }
new UnnestingFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.SCAN_COLLECTION), new MutableObject<ILogicalExpression>(argExpr)); scanCollExpr.setSourceLocation(func.getSourceLocation()); @SuppressWarnings("unchecked") UnnestOperator unnest = new UnnestOperator(var, new MutableObject<ILogicalExpression>(scanCollExpr));
List<Mutable<ILogicalExpression>> args = f.getArguments(); if (args.size() != functionId.getArity()) { throw new CompilationException(ErrorCode.COMPILATION_ERROR, f.getSourceLocation(), "Function " + functionId.getNamespace() + "." + functionId.getName() + " expects " + functionId.getArity() + " arguments");
datasetName = jobGenParams.datasetName; } else { throw new CompilationException(ErrorCode.COMPILATION_ERROR, f.getSourceLocation(), "Unexpected function for Unnest Map: " + fid);
@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; } }
optFuncExpr.getFuncExpr().getSourceLocation());