Search in sources :

Example 1 with IFunctionDescriptor

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

the class QueryLogicalExpressionJobGen method createAggregateFunctionFactory.

@Override
public IAggregateEvaluatorFactory createAggregateFunctionFactory(AggregateFunctionCallExpression expr, IVariableTypeEnvironment env, IOperatorSchema[] inputSchemas, JobGenContext context) throws AlgebricksException {
    IScalarEvaluatorFactory[] args = codegenArguments(expr, env, inputSchemas, context);
    IFunctionDescriptor fd = getFunctionDescriptor(expr, env, context);
    switch(fd.getFunctionDescriptorTag()) {
        case SERIALAGGREGATE:
            return null;
        case AGGREGATE:
            return fd.createAggregateEvaluatorFactory(args);
        default:
            throw new IllegalStateException("Invalid function descriptor " + fd.getFunctionDescriptorTag() + " expected " + FunctionDescriptorTag.SERIALAGGREGATE + " or " + FunctionDescriptorTag.AGGREGATE);
    }
}
Also used : IFunctionDescriptor(org.apache.asterix.om.functions.IFunctionDescriptor) IScalarEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)

Example 2 with IFunctionDescriptor

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

the class QueryLogicalExpressionJobGen method createScalarFunctionEvaluatorFactory.

private IScalarEvaluatorFactory createScalarFunctionEvaluatorFactory(AbstractFunctionCallExpression expr, IVariableTypeEnvironment env, IOperatorSchema[] inputSchemas, JobGenContext context) throws AlgebricksException {
    IScalarEvaluatorFactory[] args = codegenArguments(expr, env, inputSchemas, context);
    IFunctionDescriptor fd = null;
    if (!(expr.getFunctionInfo() instanceof IExternalFunctionInfo)) {
        IDataFormat format = FormatUtils.getDefaultFormat();
        fd = format.resolveFunction(expr, env);
    } else {
        ICcApplicationContext appCtx = (ICcApplicationContext) context.getAppContext();
        fd = ExternalFunctionDescriptorProvider.getExternalFunctionDescriptor((IExternalFunctionInfo) expr.getFunctionInfo(), appCtx);
    }
    return fd.createEvaluatorFactory(args);
}
Also used : IFunctionDescriptor(org.apache.asterix.om.functions.IFunctionDescriptor) ICcApplicationContext(org.apache.asterix.common.dataflow.ICcApplicationContext) IDataFormat(org.apache.asterix.formats.base.IDataFormat) IExternalFunctionInfo(org.apache.asterix.om.functions.IExternalFunctionInfo) IScalarEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)

Example 3 with IFunctionDescriptor

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

the class QueryLogicalExpressionJobGen method createSerializableAggregateFunctionFactory.

@Override
public ISerializedAggregateEvaluatorFactory createSerializableAggregateFunctionFactory(AggregateFunctionCallExpression expr, IVariableTypeEnvironment env, IOperatorSchema[] inputSchemas, JobGenContext context) throws AlgebricksException {
    IScalarEvaluatorFactory[] args = codegenArguments(expr, env, inputSchemas, context);
    IFunctionDescriptor fd = getFunctionDescriptor(expr, env, context);
    switch(fd.getFunctionDescriptorTag()) {
        case AGGREGATE:
            {
                if (BuiltinFunctions.isAggregateFunctionSerializable(fd.getIdentifier())) {
                    AggregateFunctionCallExpression serialAggExpr = BuiltinFunctions.makeSerializableAggregateFunctionExpression(fd.getIdentifier(), expr.getArguments());
                    IFunctionDescriptor afdd = getFunctionDescriptor(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);
    }
}
Also used : AggregateFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AggregateFunctionCallExpression) IFunctionDescriptor(org.apache.asterix.om.functions.IFunctionDescriptor) AlgebricksException(org.apache.hyracks.algebricks.common.exceptions.AlgebricksException) IScalarEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)

Example 4 with IFunctionDescriptor

use of org.apache.asterix.om.functions.IFunctionDescriptor 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 5 with IFunctionDescriptor

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

the class NullMissingTest method testFunction.

private void testFunction(IFunctionDescriptorFactory funcFactory) throws Exception {
    IFunctionDescriptor functionDescriptor = funcFactory.createFunctionDescriptor();
    if (!(functionDescriptor instanceof AbstractScalarFunctionDynamicDescriptor)) {
        return;
    }
    AbstractScalarFunctionDynamicDescriptor funcDesc = (AbstractScalarFunctionDynamicDescriptor) functionDescriptor;
    int inputArity = funcDesc.getIdentifier().getArity();
    Iterator<IScalarEvaluatorFactory[]> argEvalFactoryIterator = getArgCombinations(inputArity);
    int index = 0;
    while (argEvalFactoryIterator.hasNext()) {
        IScalarEvaluatorFactory evalFactory = funcDesc.createEvaluatorFactory(argEvalFactoryIterator.next());
        IHyracksTaskContext ctx = mock(IHyracksTaskContext.class);
        IScalarEvaluator evaluator = evalFactory.createScalarEvaluator(ctx);
        IPointable resultPointable = new VoidPointable();
        evaluator.evaluate(null, resultPointable);
        if (index != 0) {
            Assert.assertTrue(resultPointable.getByteArray()[resultPointable.getStartOffset()] == ATypeTag.SERIALIZED_MISSING_TYPE_TAG);
        } else {
            Assert.assertTrue(resultPointable.getByteArray()[resultPointable.getStartOffset()] == ATypeTag.SERIALIZED_NULL_TYPE_TAG);
        }
        ++index;
    }
}
Also used : IFunctionDescriptor(org.apache.asterix.om.functions.IFunctionDescriptor) IHyracksTaskContext(org.apache.hyracks.api.context.IHyracksTaskContext) VoidPointable(org.apache.hyracks.data.std.primitive.VoidPointable) IPointable(org.apache.hyracks.data.std.api.IPointable) IScalarEvaluator(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator) AbstractScalarFunctionDynamicDescriptor(org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor) IScalarEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)

Aggregations

IFunctionDescriptor (org.apache.asterix.om.functions.IFunctionDescriptor)7 IScalarEvaluatorFactory (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)5 AlgebricksException (org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)3 IFunctionManager (org.apache.asterix.om.functions.IFunctionManager)2 AbstractFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression)2 FunctionIdentifier (org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier)2 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ICcApplicationContext (org.apache.asterix.common.dataflow.ICcApplicationContext)1 IDataFormat (org.apache.asterix.formats.base.IDataFormat)1 AOrderedList (org.apache.asterix.om.base.AOrderedList)1 AString (org.apache.asterix.om.base.AString)1 IExternalFunctionInfo (org.apache.asterix.om.functions.IExternalFunctionInfo)1 ARecordType (org.apache.asterix.om.types.ARecordType)1 ATypeTag (org.apache.asterix.om.types.ATypeTag)1 AUnionType (org.apache.asterix.om.types.AUnionType)1 IAType (org.apache.asterix.om.types.IAType)1 AbstractAggregateFunctionDynamicDescriptor (org.apache.asterix.runtime.aggregates.base.AbstractAggregateFunctionDynamicDescriptor)1 AbstractScalarFunctionDynamicDescriptor (org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor)1