Apparently, the fix in
DRILL-4119 did not fully resolve the data skew issue. It worked fine on the smaller sample of the data set but on another sample of the same data set, it still produces skewed values - see below the hash values which are all odd numbers.
This indicates an underlying issue with the XXHash64 java implementation, which is Drill's implementation of the C version. One of the key difference as pointed out by Jacques Nadeau was the use of unsigned int64 in the C version compared to the Java version which uses (signed) long. I created an XXHash version using com.google.common.primitives.UnsignedLong. However, UnsignedLong does not have bit-wise operations that are needed for XXHash such as rotateLeft(), XOR etc. One could write wrappers for these but at this point, the question is: should we think of an alternative hash function ?
The alternative approach could be the murmur hash for numeric data types that we were using earlier and the Mahout version of hash function for string types (https://github.com/apache/drill/blob/master/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/HashHelper.java#L28). As a test, I reverted to this function and was getting good hash distribution for the test data.
I could not find any performance comparisons of our perf tests (TPC-H or DS) with the original and newer (XXHash) hash functions. If performance is comparable, should we revert to the original function ?
As an aside, I would like to remove the hash64 versions of the functions since these are not used anywhere.