Search in sources :

Example 1 with IFunctionManager

use of org.apache.asterix.om.functions.IFunctionManager in project asterixdb by apache.

the class AbstractScalarAggregateDescriptor method createEvaluatorFactory.

@Override
public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) throws AlgebricksException {
    // The aggregate function will get a SingleFieldFrameTupleReference that points to the result of the ScanCollection.
    // The list-item will always reside in the first field (column) of the SingleFieldFrameTupleReference.
    IScalarEvaluatorFactory[] aggFuncArgs = new IScalarEvaluatorFactory[1];
    aggFuncArgs[0] = new ColumnAccessEvalFactory(0);
    // Create aggregate function from this scalar version.
    FunctionIdentifier fid = BuiltinFunctions.getAggregateFunction(getIdentifier());
    IFunctionManager mgr = FunctionManagerHolder.getFunctionManager();
    IFunctionDescriptor fd = mgr.lookupFunction(fid);
    AbstractAggregateFunctionDynamicDescriptor aggFuncDesc = (AbstractAggregateFunctionDynamicDescriptor) fd;
    final IAggregateEvaluatorFactory aggFuncFactory = aggFuncDesc.createAggregateEvaluatorFactory(aggFuncArgs);
    return new IScalarEvaluatorFactory() {

        private static final long serialVersionUID = 1L;

        @Override
        public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws HyracksDataException {
            // Use ScanCollection to iterate over list items.
            ScanCollectionUnnestingFunctionFactory scanCollectionFactory = new ScanCollectionUnnestingFunctionFactory(args[0]);
            return new GenericScalarAggregateFunction(aggFuncFactory.createAggregateEvaluator(ctx), scanCollectionFactory, ctx);
        }
    };
}
Also used : FunctionIdentifier(org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier) IFunctionDescriptor(org.apache.asterix.om.functions.IFunctionDescriptor) IHyracksTaskContext(org.apache.hyracks.api.context.IHyracksTaskContext) ScanCollectionUnnestingFunctionFactory(org.apache.asterix.runtime.unnestingfunctions.std.ScanCollectionDescriptor.ScanCollectionUnnestingFunctionFactory) ColumnAccessEvalFactory(org.apache.hyracks.algebricks.runtime.evaluators.ColumnAccessEvalFactory) AbstractAggregateFunctionDynamicDescriptor(org.apache.asterix.runtime.aggregates.base.AbstractAggregateFunctionDynamicDescriptor) IAggregateEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IAggregateEvaluatorFactory) IScalarEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory) IFunctionManager(org.apache.asterix.om.functions.IFunctionManager)

Example 2 with IFunctionManager

use of org.apache.asterix.om.functions.IFunctionManager in project asterixdb by apache.

the class NonTaggedDataFormat method registerRuntimeFunctions.

@Override
public void registerRuntimeFunctions(List<IFunctionDescriptorFactory> funcDescriptors) throws AlgebricksException {
    if (registered) {
        return;
    }
    registered = true;
    if (FunctionManagerHolder.getFunctionManager() != null) {
        return;
    }
    IFunctionManager mgr = new FunctionManagerImpl();
    for (IFunctionDescriptorFactory fdFactory : funcDescriptors) {
        mgr.registerFunction(fdFactory);
    }
    FunctionManagerHolder.setFunctionManager(mgr);
    registerTypeInferers();
}
Also used : IFunctionDescriptorFactory(org.apache.asterix.om.functions.IFunctionDescriptorFactory) FunctionManagerImpl(org.apache.asterix.runtime.evaluators.common.FunctionManagerImpl) IFunctionManager(org.apache.asterix.om.functions.IFunctionManager)

Example 3 with IFunctionManager

use of org.apache.asterix.om.functions.IFunctionManager in project asterixdb by apache.

the class NonTaggedDataFormat method resolveFunction.

@Override
public IFunctionDescriptor resolveFunction(ILogicalExpression expr, IVariableTypeEnvironment context) throws AlgebricksException {
    FunctionIdentifier fnId = ((AbstractFunctionCallExpression) expr).getFunctionIdentifier();
    IFunctionManager mgr = FunctionManagerHolder.getFunctionManager();
    IFunctionDescriptor fd = mgr.lookupFunction(fnId);
    if (fd == null) {
        throw new AlgebricksException("Unresolved function " + fnId);
    }
    final FunctionIdentifier fid = fd.getIdentifier();
    if (functionTypeInferers.containsKey(fid)) {
        functionTypeInferers.get(fid).infer(expr, fd, context);
    }
    return fd;
}
Also used : FunctionIdentifier(org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier) IFunctionDescriptor(org.apache.asterix.om.functions.IFunctionDescriptor) AbstractFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression) AlgebricksException(org.apache.hyracks.algebricks.common.exceptions.AlgebricksException) IFunctionManager(org.apache.asterix.om.functions.IFunctionManager)

Aggregations

IFunctionManager (org.apache.asterix.om.functions.IFunctionManager)3 IFunctionDescriptor (org.apache.asterix.om.functions.IFunctionDescriptor)2 FunctionIdentifier (org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier)2 IFunctionDescriptorFactory (org.apache.asterix.om.functions.IFunctionDescriptorFactory)1 AbstractAggregateFunctionDynamicDescriptor (org.apache.asterix.runtime.aggregates.base.AbstractAggregateFunctionDynamicDescriptor)1 FunctionManagerImpl (org.apache.asterix.runtime.evaluators.common.FunctionManagerImpl)1 ScanCollectionUnnestingFunctionFactory (org.apache.asterix.runtime.unnestingfunctions.std.ScanCollectionDescriptor.ScanCollectionUnnestingFunctionFactory)1 AlgebricksException (org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)1 AbstractFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression)1 IAggregateEvaluatorFactory (org.apache.hyracks.algebricks.runtime.base.IAggregateEvaluatorFactory)1 IScalarEvaluatorFactory (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)1 ColumnAccessEvalFactory (org.apache.hyracks.algebricks.runtime.evaluators.ColumnAccessEvalFactory)1 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)1