richardstartin commented on code in PR #8766:
URL: https://github.com/apache/pinot/pull/8766#discussion_r882766409
##########
pinot-core/src/main/java/org/apache/pinot/core/query/pruner/ColumnValueSegmentPruner.java:
##########
@@ -483,26 +476,97 @@ private static Comparable convertValue(String
stringValue, DataType dataType) {
}
}
- private static class CachedValue {
- private final String _strValue;
- private final long _hash1;
- private final long _hash2;
- private DataType _dt;
- private Comparable _comparableValue;
-
- private CachedValue(Object value) {
- _strValue = value.toString();
- byte[] hash = GuavaBloomFilterReaderUtils.hash(_strValue);
- _hash1 = Longs.fromBytes(hash[7], hash[6], hash[5], hash[4], hash[3],
hash[2], hash[1], hash[0]);
- _hash2 = Longs.fromBytes(hash[15], hash[14], hash[13], hash[12],
hash[11], hash[10], hash[9], hash[8]);
+ private static class ValueCache {
+ // As Predicates are recursive structures, their hashCode is quite
expensive.
+ // By using an IdentityHashMap here we don't need to iterate over the
recursive
+ // structure. This is specially useful in the IN expression.
+ private final Map<Predicate, Object> _cache = new IdentityHashMap<>();
+
+ public void add(EqPredicate pred) {
+ _cache.put(pred, new CachedValue(pred.getValue()));
+ }
+
+ public void add(InPredicate pred) {
+ List<CachedValue> list = new ArrayList<>(pred.getValues().size());
+ for (String value : pred.getValues()) {
+ list.add(new CachedValue(value));
+ }
+ _cache.put(pred, list);
+ }
+
+ public CachedValue get(EqPredicate pred, DataType dt) {
+ CachedValue cachedValue = (CachedValue) _cache.get(pred);
+ cachedValue.ensureDataType(dt);
+ return cachedValue;
+ }
+
+ public List<CachedValue> get(InPredicate pred, DataType dt) {
+ List<CachedValue> cachedValues = (List<CachedValue>) _cache.get(pred);
+ for (CachedValue cachedValue : cachedValues) {
+ cachedValue.ensureDataType(dt);
+ }
+ return cachedValues;
}
- private Comparable getComparableValue(DataType dt) {
- if (!dt.equals(_dt)) {
- _dt = dt;
- _comparableValue = convertValue(_strValue, dt);
+ public static class CachedValue {
+ private final Object _value;
+ private boolean _hashed = false;
+ private long _hash1;
+ private long _hash2;
+ private DataType _dt;
+ private Comparable _comparableValue;
+
+ private CachedValue(Object value) {
+ _value = value;
+ }
+
+ private Comparable getComparableValue() {
+ assert _dt != null;
+ return _comparableValue;
+ }
+
+ static final LongExtractor EXTRACTOR;
+
+ interface LongExtractor {
+ long extract(byte[] bytes, int index);
+ }
+
+ static {
+ LongExtractor extractor;
+ try {
+ MethodType mt = MethodType.methodType(VarHandle.class, Class.class,
ByteOrder.class);
+ MethodHandle mh =
MethodHandles.lookup().findStatic(MethodHandles.class,
"byteArrayViewVarHandle", mt);
+
+ VarHandle varHandle = (VarHandle) mh.invokeExact(long[].class,
ByteOrder.LITTLE_ENDIAN);
+ extractor = (bytes, index) -> (long) varHandle.get(bytes, index * 8);
+ } catch (Throwable e) {
+ extractor = (bytes, index) -> {
+ int i = index * 8;
+ return Longs.fromBytes(bytes[i + 7], bytes[i + 6], bytes[i + 5],
+ bytes[i + 4], bytes[i + 3], bytes[i + 2], bytes[i + 1],
bytes[i]);
+ };
Review Comment:
You will need a little more indirection here to make this compile to JDK8 :(
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]