public FunctionManager(FunctionCollection functionCollection) { Map<Pair<FunctionIdentifier, Integer>, IFunctionDescriptorFactory> functionsMap = new HashMap<>(); Map<FunctionIdentifier, IFunctionTypeInferer> typeInferersMap = new HashMap<>(); for (IFunctionDescriptorFactory descriptorFactory : functionCollection.getFunctionDescriptorFactories()) { FunctionIdentifier fid = descriptorFactory.createFunctionDescriptor().getIdentifier(); functionsMap.put(new Pair<>(fid, fid.getArity()), descriptorFactory); IFunctionTypeInferer typeInferer = descriptorFactory.createFunctionTypeInferer(); if (typeInferer != null) { typeInferersMap.put(fid, typeInferer); } } this.functions = functionsMap; this.typeInferers = typeInferersMap; }
@Override public ISerializedAggregateEvaluatorFactory createSerializableAggregateFunctionFactory( AggregateFunctionCallExpression expr, IVariableTypeEnvironment env, IOperatorSchema[] inputSchemas, JobGenContext context) throws AlgebricksException { IScalarEvaluatorFactory[] args = codegenArguments(expr, env, inputSchemas, context); IFunctionDescriptor fd = resolveFunction(expr, env, context); switch (fd.getFunctionDescriptorTag()) { case AGGREGATE: { if (BuiltinFunctions.isAggregateFunctionSerializable(fd.getIdentifier())) { AggregateFunctionCallExpression serialAggExpr = BuiltinFunctions .makeSerializableAggregateFunctionExpression(fd.getIdentifier(), expr.getArguments()); IFunctionDescriptor afdd = resolveFunction(serialAggExpr, env, context); return afdd.createSerializableAggregateEvaluatorFactory(args); } else { throw new AlgebricksException( "Trying to create a serializable aggregate from a non-serializable aggregate function descriptor. (fi=" + expr.getFunctionIdentifier() + ")"); } } case SERIALAGGREGATE: { return fd.createSerializableAggregateEvaluatorFactory(args); } default: throw new IllegalStateException( "Invalid function descriptor " + fd.getFunctionDescriptorTag() + " expected " + FunctionDescriptorTag.SERIALAGGREGATE + " or " + FunctionDescriptorTag.AGGREGATE); } }
@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()); ATypeTag typeTag = t.getTypeTag(); switch (typeTag) { case OBJECT: { fd.setImmutableStates(t); break; } case ANY: { fd.setImmutableStates(RecordUtil.FULLY_OPEN_RECORD_TYPE); break; } default: { if (strict) { throw new NotImplementedException(fd.getIdentifier().getName() + " for data of type " + t); } else { fd.setImmutableStates(new Object[] { null }); } break; } } } }