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);
}
}
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);
}
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);
}
}
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);
}
};
}
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;
}
}
Aggregations