use of org.apache.hyracks.api.dataflow.value.IBinaryComparator in project asterixdb by apache.
the class MetadataNode method searchIndex.
private <ResultType> void searchIndex(JobId jobId, IMetadataIndex index, ITupleReference searchKey, IValueExtractor<ResultType> valueExtractor, List<ResultType> results) throws MetadataException, HyracksDataException, RemoteException {
IBinaryComparatorFactory[] comparatorFactories = index.getKeyBinaryComparatorFactory();
if (index.getFile() == null) {
throw new MetadataException("No file for Index " + index.getDataverseName() + "." + index.getIndexName());
}
String resourceName = index.getFile().getRelativePath();
IIndex indexInstance = datasetLifecycleManager.get(resourceName);
datasetLifecycleManager.open(resourceName);
IIndexAccessor indexAccessor = indexInstance.createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
ITreeIndexCursor rangeCursor = (ITreeIndexCursor) indexAccessor.createSearchCursor(false);
IBinaryComparator[] searchCmps = null;
MultiComparator searchCmp = null;
RangePredicate rangePred = null;
if (searchKey != null) {
searchCmps = new IBinaryComparator[searchKey.getFieldCount()];
for (int i = 0; i < searchKey.getFieldCount(); i++) {
searchCmps[i] = comparatorFactories[i].createBinaryComparator();
}
searchCmp = new MultiComparator(searchCmps);
}
rangePred = new RangePredicate(searchKey, searchKey, true, true, searchCmp, searchCmp);
indexAccessor.search(rangeCursor, rangePred);
try {
while (rangeCursor.hasNext()) {
rangeCursor.next();
ResultType result = valueExtractor.getValue(jobId, rangeCursor.getTuple());
if (result != null) {
results.add(result);
}
}
} finally {
rangeCursor.close();
}
datasetLifecycleManager.close(resourceName);
}
use of org.apache.hyracks.api.dataflow.value.IBinaryComparator in project asterixdb by apache.
the class ADoubleConstructorDescriptor 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 final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
private final DataOutput out = resultStorage.getDataOutput();
private final IPointable inputArg = new VoidPointable();
private IScalarEvaluator eval = args[0].createScalarEvaluator(ctx);
private final byte[] POSITIVE_INF = UTF8StringUtil.writeStringToBytes("INF");
private final byte[] NEGATIVE_INF = UTF8StringUtil.writeStringToBytes("-INF");
private final byte[] NAN = UTF8StringUtil.writeStringToBytes("NaN");
IBinaryComparator utf8BinaryComparator = BinaryComparatorFactoryProvider.UTF8STRING_POINTABLE_INSTANCE.createBinaryComparator();
private AMutableDouble aDouble = new AMutableDouble(0);
@SuppressWarnings("unchecked")
private ISerializerDeserializer<ADouble> doubleSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADOUBLE);
private final UTF8StringPointable utf8Ptr = new UTF8StringPointable();
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
try {
resultStorage.reset();
eval.evaluate(tuple, inputArg);
byte[] serString = inputArg.getByteArray();
int offset = inputArg.getStartOffset();
int len = inputArg.getLength();
if (serString[offset] == ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
if (utf8BinaryComparator.compare(serString, offset + 1, len - 1, POSITIVE_INF, 0, 5) == 0) {
aDouble.setValue(Double.POSITIVE_INFINITY);
} else if (utf8BinaryComparator.compare(serString, offset + 1, len - 1, NEGATIVE_INF, 0, 6) == 0) {
aDouble.setValue(Double.NEGATIVE_INFINITY);
} else if (utf8BinaryComparator.compare(serString, offset + 1, len - 1, NAN, 0, 5) == 0) {
aDouble.setValue(Double.NaN);
} else {
utf8Ptr.set(serString, offset + 1, len - 1);
aDouble.setValue(Double.parseDouble(utf8Ptr.toString()));
}
doubleSerde.serialize(aDouble, out);
} else {
throw new TypeMismatchException(getIdentifier(), 0, serString[offset], ATypeTag.SERIALIZED_STRING_TYPE_TAG);
}
result.set(resultStorage);
} catch (IOException e) {
throw new InvalidDataFormatException(getIdentifier(), e, ATypeTag.SERIALIZED_DATETIME_TYPE_TAG);
}
}
};
}
};
}
use of org.apache.hyracks.api.dataflow.value.IBinaryComparator in project asterixdb by apache.
the class ANullConstructorDescriptor 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 inputArg = new VoidPointable();
private IScalarEvaluator eval = args[0].createScalarEvaluator(ctx);
private final byte[] NULL = UTF8StringUtil.writeStringToBytes("null");
IBinaryComparator utf8BinaryComparator = BinaryComparatorFactoryProvider.UTF8STRING_POINTABLE_INSTANCE.createBinaryComparator();
@SuppressWarnings("unchecked")
private ISerializerDeserializer<AMissing> nullSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AMISSING);
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
try {
eval.evaluate(tuple, inputArg);
byte[] serString = inputArg.getByteArray();
int offset = inputArg.getStartOffset();
int len = inputArg.getLength();
if (serString[offset] == ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
if (utf8BinaryComparator.compare(serString, offset + 1, len - 1, NULL, 0, NULL.length) == 0) {
resultStorage.reset();
nullSerde.serialize(AMissing.MISSING, out);
result.set(resultStorage);
return;
} else {
throw new InvalidDataFormatException(getIdentifier(), ATypeTag.SERIALIZED_NULL_TYPE_TAG);
}
} else {
throw new TypeMismatchException(getIdentifier(), 0, serString[offset], ATypeTag.SERIALIZED_STRING_TYPE_TAG);
}
} catch (IOException e) {
throw new InvalidDataFormatException(getIdentifier(), e, ATypeTag.SERIALIZED_NULL_TYPE_TAG);
}
}
};
}
};
}
use of org.apache.hyracks.api.dataflow.value.IBinaryComparator in project asterixdb by apache.
the class SimilarityJaccardEvaluator method setHashMap.
protected void setHashMap(ATypeTag buildItemTypeTag, ATypeTag probeItemTypeTag) {
if (hashMap != null) {
hashMap.clear();
return;
}
IBinaryHashFunction putHashFunc = ListItemBinaryHashFunctionFactory.INSTANCE.createBinaryHashFunction(buildItemTypeTag, ignoreCase);
IBinaryHashFunction getHashFunc = ListItemBinaryHashFunctionFactory.INSTANCE.createBinaryHashFunction(probeItemTypeTag, ignoreCase);
IBinaryComparator cmp = ListItemBinaryComparatorFactory.INSTANCE.createBinaryComparator(buildItemTypeTag, probeItemTypeTag, ignoreCase);
hashMap = new BinaryHashMap(hashTableSize, TABLE_FRAME_SIZE, putHashFunc, getHashFunc, cmp);
}
use of org.apache.hyracks.api.dataflow.value.IBinaryComparator in project asterixdb by apache.
the class BTreeSearchCursorTest method createRangePredicate.
public RangePredicate createRangePredicate(int lk, int hk, boolean lowKeyInclusive, boolean highKeyInclusive) throws HyracksDataException {
// create tuplereferences for search keys
ITupleReference lowKey = TupleUtils.createIntegerTuple(false, lk);
ITupleReference highKey = TupleUtils.createIntegerTuple(false, hk);
IBinaryComparator[] searchCmps = new IBinaryComparator[1];
searchCmps[0] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY).createBinaryComparator();
MultiComparator searchCmp = new MultiComparator(searchCmps);
RangePredicate rangePred = new RangePredicate(lowKey, highKey, lowKeyInclusive, highKeyInclusive, searchCmp, searchCmp);
return rangePred;
}
Aggregations