Fix ASTERIXDB-1255
This changes enable dynamic hashtable size in SimilarityJaccardEvaluator
Change-Id: I08c550d35d864df08792369d38ff81012e3976af
Reviewed-on: https://asterix-gerrit.ics.uci.edu/586
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Till Westmann <tillw@apache.org>
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/common/SimilarityJaccardEvaluator.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/common/SimilarityJaccardEvaluator.java
index e9928a1..ab817bd 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/common/SimilarityJaccardEvaluator.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/common/SimilarityJaccardEvaluator.java
@@ -50,11 +50,11 @@
public class SimilarityJaccardEvaluator implements IScalarEvaluator {
// Parameters for hash table.
- protected final int TABLE_SIZE = 100;
- protected final int TABLE_FRAME_SIZE = 32768;
+ protected static final int MIN_TABLE_SIZE = 100;
+ protected static final int TABLE_FRAME_SIZE = 32768;
// Assuming type indicator in serde format.
- protected final int TYPE_INDICATOR_SIZE = 1;
+ protected static final int TYPE_INDICATOR_SIZE = 1;
protected final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
protected final DataOutput out = resultStorage.getDataOutput();
@@ -89,6 +89,8 @@
// Ignore case for strings. Defaults to true.
protected final boolean ignoreCase = true;
+ protected int hashTableSize = MIN_TABLE_SIZE;
+
public SimilarityJaccardEvaluator(IScalarEvaluatorFactory[] args, IHyracksTaskContext context)
throws HyracksDataException {
firstOrdListEval = args[0].createScalarEvaluator(context);
@@ -140,6 +142,10 @@
if (firstListIter.size() == 0 || secondListIter.size() == 0) {
return false;
}
+
+ // Set the size of the table dynamically
+ hashTableSize = Math.max(Math.max(firstListIter.size(), secondListIter.size()), MIN_TABLE_SIZE);
+
// TODO: Check item types are compatible.
return true;
}
@@ -229,7 +235,7 @@
.createBinaryHashFunction(probeItemTypeTag, ignoreCase);
IBinaryComparator cmp = ListItemBinaryComparatorFactory.INSTANCE.createBinaryComparator(buildItemTypeTag,
probeItemTypeTag, ignoreCase);
- hashMap = new BinaryHashMap(TABLE_SIZE, TABLE_FRAME_SIZE, putHashFunc, getHashFunc, cmp);
+ hashMap = new BinaryHashMap(hashTableSize, TABLE_FRAME_SIZE, putHashFunc, getHashFunc, cmp);
}
protected boolean checkArgTypes(ATypeTag typeTag1, ATypeTag typeTag2) throws HyracksDataException {