Search in sources :

Example 6 with IBinaryHashFunction

use of org.apache.hyracks.api.dataflow.value.IBinaryHashFunction in project asterixdb by apache.

the class FieldHashPartitionComputerFactory method createPartitioner.

@Override
public ITuplePartitionComputer createPartitioner() {
    final IBinaryHashFunction[] hashFunctions = new IBinaryHashFunction[hashFunctionFactories.length];
    for (int i = 0; i < hashFunctionFactories.length; ++i) {
        hashFunctions[i] = hashFunctionFactories[i].createBinaryHashFunction();
    }
    return new ITuplePartitionComputer() {

        @Override
        public int partition(IFrameTupleAccessor accessor, int tIndex, int nParts) throws HyracksDataException {
            if (nParts == 1) {
                return 0;
            }
            int h = 0;
            int startOffset = accessor.getTupleStartOffset(tIndex);
            int slotLength = accessor.getFieldSlotsLength();
            for (int j = 0; j < hashFields.length; ++j) {
                int fIdx = hashFields[j];
                IBinaryHashFunction hashFn = hashFunctions[j];
                int fStart = accessor.getFieldStartOffset(tIndex, fIdx);
                int fEnd = accessor.getFieldEndOffset(tIndex, fIdx);
                int fh = hashFn.hash(accessor.getBuffer().array(), startOffset + slotLength + fStart, fEnd - fStart);
                h = h * 31 + fh;
            }
            if (h < 0) {
                h = -(h + 1);
            }
            return h % nParts;
        }
    };
}
Also used : IBinaryHashFunction(org.apache.hyracks.api.dataflow.value.IBinaryHashFunction) IFrameTupleAccessor(org.apache.hyracks.api.comm.IFrameTupleAccessor) ITuplePartitionComputer(org.apache.hyracks.api.dataflow.value.ITuplePartitionComputer)

Example 7 with IBinaryHashFunction

use of org.apache.hyracks.api.dataflow.value.IBinaryHashFunction 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);
}
Also used : IBinaryHashFunction(org.apache.hyracks.api.dataflow.value.IBinaryHashFunction) IBinaryComparator(org.apache.hyracks.api.dataflow.value.IBinaryComparator) BinaryHashMap(org.apache.asterix.runtime.evaluators.functions.BinaryHashMap)

Aggregations

IBinaryHashFunction (org.apache.hyracks.api.dataflow.value.IBinaryHashFunction)7 IBinaryComparator (org.apache.hyracks.api.dataflow.value.IBinaryComparator)3 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)3 DataOutput (java.io.DataOutput)2 IOException (java.io.IOException)2 ATypeTag (org.apache.asterix.om.types.ATypeTag)2 BinaryHashMap (org.apache.asterix.runtime.evaluators.functions.BinaryHashMap)2 IFrameTupleAccessor (org.apache.hyracks.api.comm.IFrameTupleAccessor)2 ITuplePartitionComputer (org.apache.hyracks.api.dataflow.value.ITuplePartitionComputer)2 ArrayBackedValueStorage (org.apache.hyracks.data.std.util.ArrayBackedValueStorage)2 RecordBuilder (org.apache.asterix.builders.RecordBuilder)1 AsterixException (org.apache.asterix.common.exceptions.AsterixException)1 RuntimeDataException (org.apache.asterix.common.exceptions.RuntimeDataException)1 AListVisitablePointable (org.apache.asterix.om.pointables.AListVisitablePointable)1 ARecordVisitablePointable (org.apache.asterix.om.pointables.ARecordVisitablePointable)1 PointableAllocator (org.apache.asterix.om.pointables.PointableAllocator)1 IVisitablePointable (org.apache.asterix.om.pointables.base.IVisitablePointable)1 RuntimeRecordTypeInfo (org.apache.asterix.om.types.runtime.RuntimeRecordTypeInfo)1 PointableHelper (org.apache.asterix.runtime.evaluators.functions.PointableHelper)1 InvalidDataFormatException (org.apache.asterix.runtime.exceptions.InvalidDataFormatException)1