JackieTien97 commented on code in PR #172:
URL: https://github.com/apache/tsfile/pull/172#discussion_r1671556298


##########
java/tsfile/src/main/java/org/apache/tsfile/read/filter/operator/ValueFilterOperators.java:
##########
@@ -765,7 +771,89 @@ public ValueIn(ByteBuffer buffer) {
 
     @Override
     public boolean valueSatisfy(Object value) {
-      return candidates.contains(value);
+      return candidates.contains((T) value);
+    }
+
+    @Override
+    public boolean canSkip(IMetadata metadata) {
+      Optional<Statistics<? extends Serializable>> statistics =
+          metadata.getMeasurementStatistics(measurementIndex);
+
+      // All values are null, but candidates do not contain null
+      if ((!statistics.isPresent() || isAllNulls(statistics.get())) && 
!candidates.contains(null)) {
+        return true;
+      }
+
+      // All values are not null, but candidate is one null value
+      if (metadata.hasNullValue(measurementIndex)
+          && candidates.size() == 1
+          && candidates.contains(null)) {
+        return true;
+      }
+
+      if (statistics.isPresent()) {
+        T valuesMin = (T) statistics.get().getMinValue();
+        T valuesMax = (T) statistics.get().getMaxValue();
+        // All values are same
+        if (valuesMin == valuesMax) {
+          for (T val : candidates) {
+            if (valuesMin == val) {
+              return false;
+            }
+          }
+          return true;
+        } else {
+          // All values are less than min, or greater than max
+          if (candidatesMin.compareTo(valuesMax) > 0) {
+            return true;
+          }
+          if (candidatesMax.compareTo(valuesMax) < 0) {
+            return true;
+          }
+        }
+      }
+
+      return false;
+    }
+
+    @Override
+    protected boolean canSkip(Statistics<? extends Serializable> statistics) {
+      throw new NotImplementedException();
+    }
+
+    @Override
+    public boolean allSatisfy(IMetadata metadata) {
+      Optional<Statistics<? extends Serializable>> statistics =
+          metadata.getMeasurementStatistics(measurementIndex);
+
+      // All values are null, and candidate is one null
+      if ((!statistics.isPresent() || isAllNulls(statistics.get()))
+          && candidates.size() == 1
+          && candidates.contains(null)) {
+        return true;
+      }
+
+      // All values are same
+      if (statistics.isPresent()) {
+        T valuesMin = (T) statistics.get().getMinValue();
+        T valuesMax = (T) statistics.get().getMaxValue();
+        // All values are same
+        if (valuesMin == valuesMax) {
+          for (T val : candidates) {

Review Comment:
   why not use contains?



##########
java/tsfile/src/main/java/org/apache/tsfile/read/filter/operator/ValueFilterOperators.java:
##########
@@ -794,6 +886,16 @@ public boolean valueSatisfy(Object value) {
       return !candidates.contains(value);
     }
 
+    @Override
+    protected boolean canSkip(Statistics<? extends Serializable> statistics) {
+      throw new NotImplementedException();

Review Comment:
   return false? why throw exception here?



##########
java/tsfile/src/main/java/org/apache/tsfile/read/filter/operator/ValueFilterOperators.java:
##########
@@ -765,7 +771,89 @@ public ValueIn(ByteBuffer buffer) {
 
     @Override
     public boolean valueSatisfy(Object value) {
-      return candidates.contains(value);
+      return candidates.contains((T) value);
+    }
+
+    @Override
+    public boolean canSkip(IMetadata metadata) {
+      Optional<Statistics<? extends Serializable>> statistics =
+          metadata.getMeasurementStatistics(measurementIndex);
+
+      // All values are null, but candidates do not contain null
+      if ((!statistics.isPresent() || isAllNulls(statistics.get())) && 
!candidates.contains(null)) {
+        return true;
+      }
+
+      // All values are not null, but candidate is one null value
+      if (metadata.hasNullValue(measurementIndex)
+          && candidates.size() == 1
+          && candidates.contains(null)) {
+        return true;
+      }
+
+      if (statistics.isPresent()) {
+        T valuesMin = (T) statistics.get().getMinValue();
+        T valuesMax = (T) statistics.get().getMaxValue();
+        // All values are same
+        if (valuesMin == valuesMax) {
+          for (T val : candidates) {
+            if (valuesMin == val) {

Review Comment:
   why not use candidates.contains(valuesMin) ?



##########
java/tsfile/src/main/java/org/apache/tsfile/read/filter/operator/ValueFilterOperators.java:
##########
@@ -794,6 +886,16 @@ public boolean valueSatisfy(Object value) {
       return !candidates.contains(value);
     }
 
+    @Override
+    protected boolean canSkip(Statistics<? extends Serializable> statistics) {
+      throw new NotImplementedException();
+    }
+
+    @Override
+    protected boolean allSatisfy(Statistics<? extends Serializable> 
statistics) {
+      throw new NotImplementedException();

Review Comment:
   return false? why throw exception here?



##########
java/tsfile/src/main/java/org/apache/tsfile/read/filter/operator/ValueFilterOperators.java:
##########
@@ -765,7 +771,89 @@ public ValueIn(ByteBuffer buffer) {
 
     @Override
     public boolean valueSatisfy(Object value) {
-      return candidates.contains(value);
+      return candidates.contains((T) value);
+    }
+
+    @Override
+    public boolean canSkip(IMetadata metadata) {
+      Optional<Statistics<? extends Serializable>> statistics =
+          metadata.getMeasurementStatistics(measurementIndex);
+
+      // All values are null, but candidates do not contain null
+      if ((!statistics.isPresent() || isAllNulls(statistics.get())) && 
!candidates.contains(null)) {
+        return true;
+      }
+
+      // All values are not null, but candidate is one null value
+      if (metadata.hasNullValue(measurementIndex)
+          && candidates.size() == 1
+          && candidates.contains(null)) {
+        return true;
+      }
+
+      if (statistics.isPresent()) {
+        T valuesMin = (T) statistics.get().getMinValue();
+        T valuesMax = (T) statistics.get().getMaxValue();
+        // All values are same
+        if (valuesMin == valuesMax) {
+          for (T val : candidates) {
+            if (valuesMin == val) {
+              return false;
+            }
+          }
+          return true;
+        } else {
+          // All values are less than min, or greater than max
+          if (candidatesMin.compareTo(valuesMax) > 0) {
+            return true;
+          }
+          if (candidatesMax.compareTo(valuesMax) < 0) {
+            return true;
+          }
+        }
+      }
+
+      return false;
+    }
+
+    @Override
+    protected boolean canSkip(Statistics<? extends Serializable> statistics) {
+      throw new NotImplementedException();
+    }
+
+    @Override
+    public boolean allSatisfy(IMetadata metadata) {
+      Optional<Statistics<? extends Serializable>> statistics =
+          metadata.getMeasurementStatistics(measurementIndex);
+
+      // All values are null, and candidate is one null
+      if ((!statistics.isPresent() || isAllNulls(statistics.get()))
+          && candidates.size() == 1

Review Comment:
   no need to be size == 1 ?



##########
java/tsfile/src/main/java/org/apache/tsfile/read/filter/operator/ValueFilterOperators.java:
##########
@@ -765,7 +771,89 @@ public ValueIn(ByteBuffer buffer) {
 
     @Override
     public boolean valueSatisfy(Object value) {
-      return candidates.contains(value);
+      return candidates.contains((T) value);
+    }
+
+    @Override
+    public boolean canSkip(IMetadata metadata) {
+      Optional<Statistics<? extends Serializable>> statistics =
+          metadata.getMeasurementStatistics(measurementIndex);
+
+      // All values are null, but candidates do not contain null
+      if ((!statistics.isPresent() || isAllNulls(statistics.get())) && 
!candidates.contains(null)) {
+        return true;
+      }
+
+      // All values are not null, but candidate is one null value
+      if (metadata.hasNullValue(measurementIndex)
+          && candidates.size() == 1
+          && candidates.contains(null)) {
+        return true;
+      }
+
+      if (statistics.isPresent()) {
+        T valuesMin = (T) statistics.get().getMinValue();
+        T valuesMax = (T) statistics.get().getMaxValue();
+        // All values are same
+        if (valuesMin == valuesMax) {
+          for (T val : candidates) {
+            if (valuesMin == val) {
+              return false;
+            }
+          }
+          return true;
+        } else {
+          // All values are less than min, or greater than max
+          if (candidatesMin.compareTo(valuesMax) > 0) {
+            return true;
+          }
+          if (candidatesMax.compareTo(valuesMax) < 0) {
+            return true;
+          }
+        }
+      }
+
+      return false;
+    }
+
+    @Override
+    protected boolean canSkip(Statistics<? extends Serializable> statistics) {
+      throw new NotImplementedException();
+    }
+
+    @Override
+    public boolean allSatisfy(IMetadata metadata) {
+      Optional<Statistics<? extends Serializable>> statistics =
+          metadata.getMeasurementStatistics(measurementIndex);
+
+      // All values are null, and candidate is one null
+      if ((!statistics.isPresent() || isAllNulls(statistics.get()))
+          && candidates.size() == 1
+          && candidates.contains(null)) {
+        return true;
+      }
+
+      // All values are same
+      if (statistics.isPresent()) {
+        T valuesMin = (T) statistics.get().getMinValue();
+        T valuesMax = (T) statistics.get().getMaxValue();
+        // All values are same
+        if (valuesMin == valuesMax) {
+          for (T val : candidates) {
+            if (valuesMin != val) {
+              return false;

Review Comment:
   wrong?
   
   Any values in set equals to valuesMin, should return true



-- 
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]

Reply via email to