alpass163 commented on code in PR #16917:
URL: https://github.com/apache/iotdb/pull/16917#discussion_r2625993937


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/predicate/ConvertPredicateToFilterVisitor.java:
##########
@@ -155,9 +163,117 @@ public static <T extends Comparable<T>> Filter 
constructCompareFilter(
 
     int measurementIndex = 
context.getMeasurementIndex(symbolReference.getName());
     Type type = context.getType(Symbol.from(symbolReference));
+    TSDataType columnDataType = InternalTypeManager.getTSDataType(type);
+
+    // when literal is the doubleLiteral type, the columnDataType INT64 or 
INT32 has to be
+    // converted.
+    if (literal instanceof DoubleLiteral) {
+      DoubleLiteral doubleLiteral = (DoubleLiteral) literal;
+      double doubleLiteralValue = doubleLiteral.getValue();
+
+      if (columnDataType == INT64) {
+        if (doubleLiteralValue > Long.MAX_VALUE) {
+          return constructFilterForGreaterThanMax(operator, measurementIndex);
+        }
+        if (doubleLiteralValue < Long.MIN_VALUE) {
+          return constructFilterForLessThanMin(operator, measurementIndex);
+        }
+        return constructFilterFromDouble(operator, doubleLiteralValue, 
measurementIndex, type);
+
+      } else if (columnDataType == INT32) {
+        if (doubleLiteralValue > Integer.MAX_VALUE) {
+          return constructFilterForGreaterThanMax(operator, measurementIndex);
+        }
+
+        if (doubleLiteralValue < Integer.MIN_VALUE) {
+          return constructFilterForLessThanMin(operator, measurementIndex);
+        }
+        return constructFilterFromDouble(operator, doubleLiteralValue, 
measurementIndex, type);
+      }
+    }
+
+    if (literal instanceof LongLiteral && columnDataType == INT32) {
+      return constructValueFilter(operator, literal, LongType.INT64, 
measurementIndex);
+    }
+
+    return constructValueFilter(operator, literal, type, measurementIndex);
+  }
+
+  private static Filter constructFilterFromDouble(
+      ComparisonExpression.Operator operator, double doubleValue, int 
measurementIndex, Type type) {
+
+    switch (operator) {
+      case GREATER_THAN_OR_EQUAL:
+      case LESS_THAN:
+        double ceil = Math.ceil(doubleValue);
+        //  for targeted type is INT32 or INT64, transformed the double value 
to LongLiteral
+        Literal ceilLiteral = new LongLiteral(String.valueOf((long) ceil));
+        return constructValueFilter(operator, ceilLiteral, type, 
measurementIndex);
+
+      case LESS_THAN_OR_EQUAL:
+      case GREATER_THAN:
+        double floor = Math.floor(doubleValue);
+        Literal floorLiteral = new LongLiteral(String.valueOf((long) floor));
+        return constructValueFilter(operator, floorLiteral, type, 
measurementIndex);

Review Comment:
   The tree Model use the String type that accepts the input literal in 
substance, while the table model use the double type that accepts the literal 
input, so the rounding approach is different, which is normal



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