qzsee commented on code in PR #12151:
URL: https://github.com/apache/doris/pull/12151#discussion_r963204841


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/Literal.java:
##########
@@ -82,6 +107,90 @@ public <R, C> R accept(ExpressionVisitor<R, C> visitor, C 
context) {
         return visitor.visitLiteral(this, context);
     }
 
+    public boolean isNull() {
+        return this instanceof NullLiteral;
+    }
+
+    /**
+     * literal expr compare.
+     */
+    public int compareTo(Literal other) {
+        if (isNull() && other.isNull()) {
+            return 0;
+        }
+        DataType oType = other.getDataType();
+        DataType type = getDataType();
+        if (!type.equals(oType)) {
+            throw new RuntimeException("data type not equal!");
+        } else if (type.isBooleanType()) {
+            return Boolean.compare((boolean) getValue(), (boolean) 
other.getValue());
+        } else if (type.isTinyIntType()) {
+            return Byte.compare((byte) getValue(), (byte) other.getValue());
+        } else if (type.isSmallIntType()) {
+            return Short.compare((short) getValue(), (short) other.getValue());
+        } else if (type.isIntType()) {
+            return Integer.compare((int) getValue(), (int) other.getValue());
+        } else if (type.isBigIntType()) {
+            return Long.compare((long) getValue(), (long) other.getValue());
+        } else if (type.isLargeIntType()) {
+            return ((BigInteger) getValue()).compareTo((BigInteger) 
other.getValue());
+        } else if (type.isFloatType()) {
+            return Float.compare((float) getValue(), (float) other.getValue());
+        } else if (type.isDoubleType()) {
+            return Double.compare((double) getValue(), (double) 
other.getValue());
+        } else if (type.isDecimalType()) {
+            return Long.compare((Long) getValue(), (Long) other.getValue());
+        } else if (type.isDateType()) {
+            // todo process date
+        } else if (type.isDecimalType()) {
+            return ((BigDecimal) getValue()).compareTo((BigDecimal) 
other.getValue());
+        } else if (type instanceof StringType) {
+            return StringUtils.compare((String) getValue(), (String) 
other.getValue());
+        }

Review Comment:
   Literal generic comparison functions, so if you put them in each literal 
there's redundant code



-- 
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: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to