ashoka1981 commented on code in PR #71075:
URL: https://github.com/apache/doris/pull/71075#discussion_r4783503871


##########
fe/fe-core/src/main/java/org/apache/doris/analysis/PartitionExprUtil.java:
##########
@@ -167,7 +165,9 @@ public static Map<String, AddPartitionOp> 
getAddPartitionClauseFromPartitionValu
             if (partitionType == PartitionType.RANGE) {
                 String beginTime = curPartitionValues.get(0); // have check 
range type size must be 1
                 Type partitionColumnType = partitionColumn.get(0).getType();
-                LiteralExpr beginDateTime = 
DateLiteralUtils.createLiteral(beginTime, partitionColumnType);
+                LiteralExpr beginDateTime = beginTime == null
+                        ? getNullRangeBegin(partitionColumnType)

Review Comment:
   Thanks, fixed in 49fa58199d5. `OneRangePartitionEvaluator` now keeps a 
nullable RANGE slot whose partition starts at `MIN_VALUE` as a slot instead of 
expanding it to literals (`keepNullableSlots`), so `IS NULL` reaches 
`visitIsNull` and keeps the partition. 
`PartitionPrunerTest.testIsNullKeepsExpandableMinValueDatePartition` covers a 
one-day and a one-week range, and the regression suite now has a daily DATE 
table: `where d is null` returns the NULL row on a local cluster.



##########
fe/fe-core/src/main/java/org/apache/doris/analysis/PartitionExprUtil.java:
##########
@@ -248,6 +248,24 @@ public static Map<String, AddPartitionOp> 
getAddPartitionClauseFromPartitionValu
         return result;
     }
 
+    /**
+     * The start of the range partition that holds NULL values of a nullable 
AUTO RANGE PARTITION column.
+     *
+     * <p>A range partition orders NULL below every value, so NULL belongs to 
the first range: the one that
+     * starts at the type's minimum (0000-01-01 for date types). A lower bound 
equal to MIN_VALUE reaches BE
+     * without a start key, which BE reads as "no lower bound", so the NULL 
rows route to that partition. It is
+     * the same partition a row holding the minimum value would create (for 
example p00000101000000), so the two
+     * never conflict. CREATE TABLE allows a nullable AUTO RANGE PARTITION 
column only for these date types.
+     */
+    private static LiteralExpr getNullRangeBegin(Type partitionColumnType) 
throws AnalysisException {
+        Preconditions.checkState(partitionColumnType.isDate() || 
partitionColumnType.isDateV2()
+                || partitionColumnType.isDatetime() || 
partitionColumnType.isDatetimeV2(),
+                "NULL value of AUTO RANGE PARTITION column type %s", 
partitionColumnType);
+        String minValue = (partitionColumnType.isDate() || 
partitionColumnType.isDateV2())
+                ? "0000-01-01" : "0000-01-01 00:00:00";
+        return DateLiteralUtils.createLiteral(minValue, partitionColumnType);

Review Comment:
   Thanks, fixed in 49fa58199d5. The partition that starts at the minimum now 
ends at the first bucket boundary after it, as BE computes it 
(`PartitionExprUtil.getFirstBoundaryAfterMinimum`): for `week` that is 
0000-01-02, since 0000-01-01 is a Sunday in BE's calendar; for 
`*_floor`/`*_ceil` the grid from 0001-01-01; other units are unchanged. 
Separately, java.time gives year 0 a February 29 that BE's calendar lacks, so 
duration-based range ends now skip it (a week from 0000-02-27 ends at 
0000-03-06). The regression suite covers NULL-then-week and week-then-NULL, 
plus the leap-day week; on a local ASAN cluster the partitions are `[MIN, 
0000-01-02)` and `[0000-01-02, 0000-01-09)` and `d = '0000-01-08'` finds its 
row.



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

Reply via email to