use of org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference in project asterixdb by apache.
the class TidRunningAggregateDescriptor method createRunningAggregateEvaluatorFactory.
@Override
public IRunningAggregateEvaluatorFactory createRunningAggregateEvaluatorFactory(IScalarEvaluatorFactory[] args) {
return new IRunningAggregateEvaluatorFactory() {
private static final long serialVersionUID = 1L;
@SuppressWarnings("unchecked")
@Override
public IRunningAggregateEvaluator createRunningAggregateEvaluator(IHyracksTaskContext ctx) throws HyracksDataException {
return new IRunningAggregateEvaluator() {
private final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
private final ISerializerDeserializer<AInt64> serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT64);
private final AMutableInt64 m = new AMutableInt64(0);
private int cnt;
@Override
public void step(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
resultStorage.reset();
m.setValue(cnt);
serde.serialize(m, resultStorage.getDataOutput());
result.set(resultStorage);
++cnt;
}
@Override
public void init() throws HyracksDataException {
cnt = 1;
}
};
}
};
}
use of org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference in project asterixdb by apache.
the class RangeDescriptor method createUnnestingEvaluatorFactory.
@Override
public IUnnestingEvaluatorFactory createUnnestingEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
return new IUnnestingEvaluatorFactory() {
private static final long serialVersionUID = 1L;
@Override
public IUnnestingEvaluator createUnnestingEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
return new IUnnestingEvaluator() {
private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
@SuppressWarnings("rawtypes")
private ISerializerDeserializer serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT64);
private IPointable inputVal = new VoidPointable();
private IScalarEvaluator eval0 = args[0].createScalarEvaluator(ctx);
private IScalarEvaluator eval1 = args[1].createScalarEvaluator(ctx);
private AMutableInt64 aInt64 = new AMutableInt64(0);
private long current;
private long max;
@Override
public void init(IFrameTupleReference tuple) throws HyracksDataException {
eval0.evaluate(tuple, inputVal);
current = ATypeHierarchy.getLongValue(getIdentifier().getName(), 0, inputVal.getByteArray(), inputVal.getStartOffset());
eval1.evaluate(tuple, inputVal);
max = ATypeHierarchy.getLongValue(getIdentifier().getName(), 1, inputVal.getByteArray(), inputVal.getStartOffset());
}
@SuppressWarnings("unchecked")
@Override
public boolean step(IPointable result) throws HyracksDataException {
if (current > max) {
return false;
}
aInt64.setValue(current);
resultStorage.reset();
serde.serialize(aInt64, resultStorage.getDataOutput());
result.set(resultStorage);
current++;
return true;
}
};
}
};
}
use of org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference in project asterixdb by apache.
the class SubsetCollectionDescriptor method createUnnestingEvaluatorFactory.
@Override
public IUnnestingEvaluatorFactory createUnnestingEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
return new IUnnestingEvaluatorFactory() {
private static final long serialVersionUID = 1L;
@Override
public IUnnestingEvaluator createUnnestingEvaluator(IHyracksTaskContext ctx) throws HyracksDataException {
return new IUnnestingEvaluator() {
private IPointable inputVal = new VoidPointable();
private IScalarEvaluator evalList = args[0].createScalarEvaluator(ctx);
private IScalarEvaluator evalStart = args[1].createScalarEvaluator(ctx);
private IScalarEvaluator evalLen = args[2].createScalarEvaluator(ctx);
private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
private int numItems;
private int numItemsMax;
private int posStart;
private int posCrt;
private ATypeTag itemTag;
private boolean selfDescList = false;
private boolean metUnknown = false;
@Override
public void init(IFrameTupleReference tuple) throws HyracksDataException {
try {
evalStart.evaluate(tuple, inputVal);
posStart = ATypeHierarchy.getIntegerValue(getIdentifier().getName(), 0, inputVal.getByteArray(), inputVal.getStartOffset());
evalLen.evaluate(tuple, inputVal);
numItems = ATypeHierarchy.getIntegerValue(getIdentifier().getName(), 1, inputVal.getByteArray(), inputVal.getStartOffset());
evalList.evaluate(tuple, inputVal);
byte[] serList = inputVal.getByteArray();
int offset = inputVal.getStartOffset();
metUnknown = false;
byte typeTag = serList[offset];
if (typeTag == ATypeTag.SERIALIZED_MISSING_TYPE_TAG || typeTag == ATypeTag.SERIALIZED_NULL_TYPE_TAG) {
metUnknown = true;
return;
}
if (typeTag != ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG && typeTag != ATypeTag.SERIALIZED_UNORDEREDLIST_TYPE_TAG) {
throw new RuntimeDataException(ErrorCode.COERCION, getIdentifier());
}
if (typeTag == ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG) {
numItemsMax = AOrderedListSerializerDeserializer.getNumberOfItems(serList, offset);
} else {
numItemsMax = AUnorderedListSerializerDeserializer.getNumberOfItems(serList, offset);
}
itemTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serList[offset + 1]);
if (itemTag == ATypeTag.ANY) {
selfDescList = true;
}
posCrt = posStart;
} catch (IOException e) {
throw new HyracksDataException(e);
}
}
@Override
public boolean step(IPointable result) throws HyracksDataException {
if (!metUnknown && posCrt < posStart + numItems && posCrt < numItemsMax) {
resultStorage.reset();
byte[] serList = inputVal.getByteArray();
int offset = inputVal.getStartOffset();
int itemLength = 0;
try {
int itemOffset = AOrderedListSerializerDeserializer.getItemOffset(serList, offset, posCrt);
if (selfDescList) {
itemTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serList[itemOffset]);
}
itemLength = NonTaggedFormatUtil.getFieldValueLength(serList, itemOffset, itemTag, selfDescList);
if (!selfDescList) {
resultStorage.getDataOutput().writeByte(itemTag.serialize());
}
resultStorage.getDataOutput().write(serList, itemOffset, itemLength + (!selfDescList ? 0 : 1));
} catch (IOException e) {
throw new HyracksDataException(e);
} catch (AsterixException e) {
throw new HyracksDataException(e);
}
result.set(resultStorage);
++posCrt;
return true;
}
return false;
}
};
}
};
}
use of org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference in project asterixdb by apache.
the class PrefixLenDescriptor 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 final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
private final DataOutput out = resultStorage.getDataOutput();
private final IPointable inputVal = new VoidPointable();
private final IScalarEvaluator evalLen = args[0].createScalarEvaluator(ctx);
private final IScalarEvaluator evalSimilarity = args[1].createScalarEvaluator(ctx);
private final IScalarEvaluator evalThreshold = args[2].createScalarEvaluator(ctx);
private final SimilarityFiltersCache similarityFiltersCache = new SimilarityFiltersCache();
// result
private final AMutableInt32 res = new AMutableInt32(0);
@SuppressWarnings("unchecked")
private final ISerializerDeserializer<AInt32> int32Serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT32);
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
resultStorage.reset();
// length
evalLen.evaluate(tuple, inputVal);
byte[] data = inputVal.getByteArray();
int offset = inputVal.getStartOffset();
if (data[offset] != ATypeTag.SERIALIZED_INT32_TYPE_TAG) {
throw new TypeMismatchException(getIdentifier(), 0, data[offset], ATypeTag.SERIALIZED_INT32_TYPE_TAG);
}
int length = IntegerPointable.getInteger(data, offset + 1);
// similarity threshold
evalThreshold.evaluate(tuple, inputVal);
data = inputVal.getByteArray();
offset = inputVal.getStartOffset();
if (data[offset] != ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG) {
throw new TypeMismatchException(getIdentifier(), 1, data[offset], ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG);
}
float similarityThreshold = (float) ADoubleSerializerDeserializer.getDouble(data, offset + 1);
// similarity name
evalSimilarity.evaluate(tuple, inputVal);
data = inputVal.getByteArray();
offset = inputVal.getStartOffset();
int len = inputVal.getLength();
if (data[offset] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
throw new TypeMismatchException(getIdentifier(), 2, data[offset], ATypeTag.SERIALIZED_STRING_TYPE_TAG);
}
SimilarityFilters similarityFilters = similarityFiltersCache.get(similarityThreshold, data, offset, len);
int prefixLength = similarityFilters.getPrefixLength(length);
res.setValue(prefixLength);
try {
int32Serde.serialize(res, out);
} catch (IOException e) {
throw new HyracksDataException(e);
}
result.set(resultStorage);
}
};
}
};
}
use of org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference in project asterixdb by apache.
the class PrefixLenJaccardDescriptor 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 final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
private final DataOutput out = resultStorage.getDataOutput();
private final IPointable lenPtr = new VoidPointable();
private final IPointable thresholdPtr = new VoidPointable();
private final IScalarEvaluator evalLen = args[0].createScalarEvaluator(ctx);
private final IScalarEvaluator evalThreshold = args[1].createScalarEvaluator(ctx);
private float similarityThresholdCache;
private SimilarityFiltersJaccard similarityFilters;
// result
private final AMutableInt32 res = new AMutableInt32(0);
@SuppressWarnings("unchecked")
private final ISerializerDeserializer<AInt32> int32Serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT32);
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
resultStorage.reset();
evalLen.evaluate(tuple, lenPtr);
evalThreshold.evaluate(tuple, thresholdPtr);
// length
int length = ATypeHierarchy.getIntegerValue(getIdentifier().getName(), 0, lenPtr.getByteArray(), lenPtr.getStartOffset());
// similarity threshold
byte[] data = thresholdPtr.getByteArray();
int offset = thresholdPtr.getStartOffset();
if (data[offset] != ATypeTag.SERIALIZED_FLOAT_TYPE_TAG) {
throw new TypeMismatchException(getIdentifier(), 1, data[offset], ATypeTag.SERIALIZED_FLOAT_TYPE_TAG);
}
float similarityThreshold = AFloatSerializerDeserializer.getFloat(data, offset + 1);
if (similarityThreshold != similarityThresholdCache || similarityFilters == null) {
similarityFilters = new SimilarityFiltersJaccard(similarityThreshold);
}
int prefixLength = similarityFilters.getPrefixLength(length);
res.setValue(prefixLength);
try {
int32Serde.serialize(res, out);
} catch (IOException e) {
throw new HyracksDataException(e);
}
result.set(resultStorage);
}
};
}
};
}
Aggregations