Search in sources :

Example 1 with PointableBinaryHashFunctionFactory

use of org.apache.hyracks.data.std.accessors.PointableBinaryHashFunctionFactory in project asterixdb by apache.

the class ListItemBinaryHashFunctionFactory method createBinaryHashFunction.

public IBinaryHashFunction createBinaryHashFunction(final ATypeTag itemTypeTag, final boolean ignoreCase) {
    return new IBinaryHashFunction() {

        private IBinaryHashFunction lowerCaseStringHash = new PointableBinaryHashFunctionFactory(UTF8StringLowercasePointable.FACTORY).createBinaryHashFunction();

        private IBinaryHashFunction genericBinaryHash = MurmurHash3BinaryHashFunctionFamily.INSTANCE.createBinaryHashFunction(0);

        private GrowableArray taggedBytes = new GrowableArray();

        @Override
        public int hash(byte[] bytes, int offset, int length) throws HyracksDataException {
            ATypeTag tag = itemTypeTag;
            int skip = 0;
            if (itemTypeTag == ATypeTag.ANY) {
                tag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes[offset]);
                skip = 1;
            }
            switch(tag) {
                case STRING:
                    {
                        if (ignoreCase) {
                            return lowerCaseStringHash.hash(bytes, offset + skip, length - skip);
                        }
                    }
                default:
                    {
                        if (itemTypeTag != ATypeTag.ANY) {
                            // add the itemTypeTag in front of the data
                            try {
                                resetTaggedBytes(bytes, offset, length);
                                return genericBinaryHash.hash(taggedBytes.getByteArray(), 0, length + 1);
                            } catch (IOException e) {
                                throw new HyracksDataException(e);
                            }
                        } else {
                            return genericBinaryHash.hash(bytes, offset, length);
                        }
                    }
            }
        }

        private void resetTaggedBytes(byte[] data, int offset, int length) throws IOException {
            taggedBytes.reset();
            taggedBytes.getDataOutput().writeByte(itemTypeTag.serialize());
            taggedBytes.getDataOutput().write(data, offset, length);
        }
    };
}
Also used : IBinaryHashFunction(org.apache.hyracks.api.dataflow.value.IBinaryHashFunction) ATypeTag(org.apache.asterix.om.types.ATypeTag) GrowableArray(org.apache.hyracks.data.std.util.GrowableArray) PointableBinaryHashFunctionFactory(org.apache.hyracks.data.std.accessors.PointableBinaryHashFunctionFactory) IOException(java.io.IOException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 2 with PointableBinaryHashFunctionFactory

use of org.apache.hyracks.data.std.accessors.PointableBinaryHashFunctionFactory in project asterixdb by apache.

the class FullTextContainsEvaluator method initializeFullTextContains.

private void initializeFullTextContains() {
    // We use a hash set to store tokens from the right side (query predicate).
    // Initialize necessary variables.
    hashFunc = new PointableBinaryHashFunctionFactory(UTF8StringLowercaseTokenPointable.FACTORY).createBinaryHashFunction();
    keyEntry = new BinaryEntry();
    // Parameter: number of bucket, frame size, hashFunction, Comparator, byte array
    // that contains the key (this array will be set later.)
    rightHashSet = new BinaryHashSet(HASH_SET_SLOT_SIZE, HASH_SET_FRAME_SIZE, hashFunc, strLowerCaseTokenCmp, null);
    tokenizerForLeftArray = BinaryTokenizerFactoryProvider.INSTANCE.getWordTokenizerFactory(ATypeTag.STRING, false, true).createTokenizer();
}
Also used : BinaryEntry(org.apache.hyracks.data.std.util.BinaryEntry) BinaryHashSet(org.apache.hyracks.data.std.util.BinaryHashSet) PointableBinaryHashFunctionFactory(org.apache.hyracks.data.std.accessors.PointableBinaryHashFunctionFactory)

Aggregations

PointableBinaryHashFunctionFactory (org.apache.hyracks.data.std.accessors.PointableBinaryHashFunctionFactory)2 IOException (java.io.IOException)1 ATypeTag (org.apache.asterix.om.types.ATypeTag)1 IBinaryHashFunction (org.apache.hyracks.api.dataflow.value.IBinaryHashFunction)1 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)1 BinaryEntry (org.apache.hyracks.data.std.util.BinaryEntry)1 BinaryHashSet (org.apache.hyracks.data.std.util.BinaryHashSet)1 GrowableArray (org.apache.hyracks.data.std.util.GrowableArray)1