use of org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory in project asterixdb by apache.
the class IsSystemNullDescriptor method createEvaluatorFactory.
@Override
public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
return new IScalarEvaluatorFactory() {
private static final long serialVersionUID = 1L;
@Override
public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
return new IScalarEvaluator() {
private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
private DataOutput out = resultStorage.getDataOutput();
private IPointable argPtr = new VoidPointable();
private IScalarEvaluator eval = args[0].createScalarEvaluator(ctx);
private final AObjectSerializerDeserializer aObjSerDer = AObjectSerializerDeserializer.INSTANCE;
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
eval.evaluate(tuple, argPtr);
boolean isSystemNull = argPtr.getByteArray()[argPtr.getStartOffset()] == ATypeTag.SERIALIZED_SYSTEM_NULL_TYPE_TAG;
ABoolean res = isSystemNull ? ABoolean.TRUE : ABoolean.FALSE;
aObjSerDer.serialize(res, out);
}
};
}
};
}
use of org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory in project asterixdb by apache.
the class NotDescriptor method createEvaluatorFactory.
@Override
public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
return new IScalarEvaluatorFactory() {
private static final long serialVersionUID = 1L;
@Override
public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws HyracksDataException {
return new IScalarEvaluator() {
private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
private DataOutput out = resultStorage.getDataOutput();
private IPointable argPtr = new VoidPointable();
private IScalarEvaluator eval = args[0].createScalarEvaluator(ctx);
@SuppressWarnings("unchecked")
private ISerializerDeserializer<ABoolean> booleanSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ABOOLEAN);
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
resultStorage.reset();
eval.evaluate(tuple, argPtr);
byte[] bytes = argPtr.getByteArray();
int offset = argPtr.getStartOffset();
if (bytes[offset] == ATypeTag.SERIALIZED_BOOLEAN_TYPE_TAG) {
boolean argRes = ABooleanSerializerDeserializer.getBoolean(bytes, offset + 1);
ABoolean aResult = argRes ? ABoolean.FALSE : ABoolean.TRUE;
booleanSerde.serialize(aResult, out);
} else {
throw new TypeMismatchException(getIdentifier(), 0, bytes[offset], ATypeTag.SERIALIZED_BOOLEAN_TYPE_TAG);
}
result.set(resultStorage);
}
};
}
};
}
use of org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory in project asterixdb by apache.
the class NumericATan2Descriptor method createEvaluatorFactory.
@Override
public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
return new IScalarEvaluatorFactory() {
private static final long serialVersionUID = 1L;
@Override
public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
return new IScalarEvaluator() {
// For inputs.
private final IPointable leftPtr = new VoidPointable();
private final IPointable rightPtr = new VoidPointable();
private final IScalarEvaluator evalLeft = args[0].createScalarEvaluator(ctx);
private final IScalarEvaluator evalRight = args[1].createScalarEvaluator(ctx);
private final double[] operands = new double[args.length];
// For the output.
private final AMutableDouble aDouble = new AMutableDouble(0.0);
@SuppressWarnings("rawtypes")
private final ISerializerDeserializer outputSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADOUBLE);
private final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
private final DataOutput out = resultStorage.getDataOutput();
@SuppressWarnings("unchecked")
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
resultStorage.reset();
evalLeft.evaluate(tuple, leftPtr);
evalRight.evaluate(tuple, rightPtr);
for (int i = 0; i < args.length; i++) {
IPointable argPtr = i == 0 ? leftPtr : rightPtr;
byte[] data = argPtr.getByteArray();
int offset = argPtr.getStartOffset();
operands[i] = ATypeHierarchy.getDoubleValue(getIdentifier().getName(), i, data, offset);
}
aDouble.setValue(Math.atan2(operands[0], operands[1]));
outputSerde.serialize(aDouble, out);
result.set(resultStorage);
}
};
}
};
}
use of org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory in project asterixdb by apache.
the class NestedLoopJoinPOperator method contributeRuntimeOperator.
@Override
public void contributeRuntimeOperator(IHyracksJobBuilder builder, JobGenContext context, ILogicalOperator op, IOperatorSchema propagatedSchema, IOperatorSchema[] inputSchemas, IOperatorSchema outerPlanSchema) throws AlgebricksException {
AbstractBinaryJoinOperator join = (AbstractBinaryJoinOperator) op;
RecordDescriptor recDescriptor = JobGenHelper.mkRecordDescriptor(context.getTypeEnvironment(op), propagatedSchema, context);
IOperatorSchema[] conditionInputSchemas = new IOperatorSchema[1];
conditionInputSchemas[0] = propagatedSchema;
IExpressionRuntimeProvider expressionRuntimeProvider = context.getExpressionRuntimeProvider();
IScalarEvaluatorFactory cond = expressionRuntimeProvider.createEvaluatorFactory(join.getCondition().getValue(), context.getTypeEnvironment(op), conditionInputSchemas, context);
ITuplePairComparatorFactory comparatorFactory = new TuplePairEvaluatorFactory(cond, context.getBinaryBooleanInspectorFactory());
IOperatorDescriptorRegistry spec = builder.getJobSpec();
IOperatorDescriptor opDesc = null;
switch(kind) {
case INNER:
{
opDesc = new NestedLoopJoinOperatorDescriptor(spec, comparatorFactory, recDescriptor, memSize, false, null);
break;
}
case LEFT_OUTER:
{
IMissingWriterFactory[] nonMatchWriterFactories = new IMissingWriterFactory[inputSchemas[1].getSize()];
for (int j = 0; j < nonMatchWriterFactories.length; j++) {
nonMatchWriterFactories[j] = context.getMissingWriterFactory();
}
opDesc = new NestedLoopJoinOperatorDescriptor(spec, comparatorFactory, recDescriptor, memSize, true, nonMatchWriterFactories);
break;
}
default:
{
throw new NotImplementedException();
}
}
contributeOpDesc(builder, (AbstractLogicalOperator) op, opDesc);
ILogicalOperator src1 = op.getInputs().get(0).getValue();
builder.contributeGraphEdge(src1, 0, op, 0);
ILogicalOperator src2 = op.getInputs().get(1).getValue();
builder.contributeGraphEdge(src2, 0, op, 1);
}
use of org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory in project asterixdb by apache.
the class AssignPOperator method contributeRuntimeOperator.
@Override
public void contributeRuntimeOperator(IHyracksJobBuilder builder, JobGenContext context, ILogicalOperator op, IOperatorSchema opSchema, IOperatorSchema[] inputSchemas, IOperatorSchema outerPlanSchema) throws AlgebricksException {
AssignOperator assign = (AssignOperator) op;
List<LogicalVariable> variables = assign.getVariables();
List<Mutable<ILogicalExpression>> expressions = assign.getExpressions();
int[] outColumns = new int[variables.size()];
for (int i = 0; i < outColumns.length; i++) {
outColumns[i] = opSchema.findVariable(variables.get(i));
}
IScalarEvaluatorFactory[] evalFactories = new IScalarEvaluatorFactory[expressions.size()];
IExpressionRuntimeProvider expressionRuntimeProvider = context.getExpressionRuntimeProvider();
for (int i = 0; i < evalFactories.length; i++) {
evalFactories[i] = expressionRuntimeProvider.createEvaluatorFactory(expressions.get(i).getValue(), context.getTypeEnvironment(op.getInputs().get(0).getValue()), inputSchemas, context);
}
// TODO push projections into the operator
int[] projectionList = JobGenHelper.projectAllVariables(opSchema);
AssignRuntimeFactory runtime = new AssignRuntimeFactory(outColumns, evalFactories, projectionList, flushFramesRapidly);
// contribute one Asterix framewriter
RecordDescriptor recDesc = JobGenHelper.mkRecordDescriptor(context.getTypeEnvironment(op), opSchema, context);
if (cardinalityConstraint > 0) {
AlgebricksCountPartitionConstraint countConstraint = new AlgebricksCountPartitionConstraint(cardinalityConstraint);
builder.contributeMicroOperator(assign, runtime, recDesc, countConstraint);
} else {
builder.contributeMicroOperator(assign, runtime, recDesc);
}
// and contribute one edge from its child
ILogicalOperator src = assign.getInputs().get(0).getValue();
builder.contributeGraphEdge(src, 0, assign, 0);
}
Aggregations