Search in sources :

Example 1 with AbstractScalarFunctionDynamicDescriptor

use of org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor in project asterixdb by apache.

the class ExceptionIT method testFunction.

private void testFunction(IFunctionDescriptorFactory funcFactory) throws Exception {
    AbstractScalarFunctionDynamicDescriptor funcDesc = (AbstractScalarFunctionDynamicDescriptor) funcFactory.createFunctionDescriptor();
    int inputArity = funcDesc.getIdentifier().getArity();
    Iterator<IScalarEvaluatorFactory[]> argEvalFactoryIterator = getArgCombinations(inputArity);
    while (argEvalFactoryIterator.hasNext()) {
        IScalarEvaluatorFactory evalFactory = funcDesc.createEvaluatorFactory(argEvalFactoryIterator.next());
        IHyracksTaskContext ctx = mock(IHyracksTaskContext.class);
        IScalarEvaluator evaluator = evalFactory.createScalarEvaluator(ctx);
        IPointable resultPointable = new VoidPointable();
        try {
            evaluator.evaluate(null, resultPointable);
        } catch (Throwable e) {
            String msg = e.getMessage();
            if (msg == null) {
                continue;
            }
            if (msg.startsWith("ASX")) {
                // Verifies the error code.
                int errorCode = Integer.parseInt(msg.substring(3, 7));
                Assert.assertTrue(errorCode >= 0 && errorCode < 1000);
                continue;
            } else {
                // Any root-level data exceptions thrown from runtime functions should have an error code.
                Assert.assertTrue(!(e instanceof HyracksDataException) || (e.getCause() != null));
            }
        }
    }
}
Also used : 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) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) IScalarEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)

Example 2 with AbstractScalarFunctionDynamicDescriptor

use of org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor 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)

Example 3 with AbstractScalarFunctionDynamicDescriptor

use of org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor in project asterixdb by apache.

the class EvaluatorGeneratorMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    baseDir = project.getBuild().getDirectory() + File.separator + "classes";
    try {
        // Finds all sub-classes of AbstractScalarFunctionDynamicDescriptor with in the package
        // org.apache.asterix.runtime.evaluators.
        Reflections reflections = new Reflections(evaluatorPackagePrefix);
        Set<Class<? extends AbstractScalarFunctionDynamicDescriptor>> allClasses = reflections.getSubTypesOf(AbstractScalarFunctionDynamicDescriptor.class);
        // Generates byte code for all sub-classes of AbstractScalarFunctionDynamicDescriptor.
        for (Class<?> cl : allClasses) {
            getLog().info("Generating byte code for " + cl.getName());
            CodeGenUtil.generateScalarFunctionDescriptorBinary(evaluatorPackagePrefix, cl.getName(), CodeGenUtil.DEFAULT_SUFFIX_FOR_GENERATED_CLASS, reflections.getClass().getClassLoader(), (name, bytes) -> writeFile(name, bytes));
        }
    } catch (Exception e) {
        getLog().error(e);
        throw new MojoFailureException(e.toString());
    }
}
Also used : MojoFailureException(org.apache.maven.plugin.MojoFailureException) AbstractScalarFunctionDynamicDescriptor(org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) Reflections(org.reflections.Reflections)

Aggregations

AbstractScalarFunctionDynamicDescriptor (org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor)3 IScalarEvaluator (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator)2 IScalarEvaluatorFactory (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)2 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)2 IPointable (org.apache.hyracks.data.std.api.IPointable)2 VoidPointable (org.apache.hyracks.data.std.primitive.VoidPointable)2 IOException (java.io.IOException)1 IFunctionDescriptor (org.apache.asterix.om.functions.IFunctionDescriptor)1 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1 Reflections (org.reflections.Reflections)1