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