ashoka1981 opened a new pull request, #71075:
URL: https://github.com/apache/doris/pull/71075

   ### Background
   
   AUTO RANGE PARTITION creates range partitions on demand while loading: BE 
evaluates the partition function (`date_trunc`/`date_floor`/`date_ceil`) for 
each row, and for a value no partition covers it asks FE (`createPartition` 
RPC) to add `[begin, begin + interval)`. Ordinary range partitions already 
accept a nullable column, ordering NULL below every value so it lands in the 
first partition, the one whose lower bound is `MIN_VALUE`. AUTO LIST PARTITION 
also accepts NULL, in partition `pX`.
   
   ### What problem does this PR solve?
   
   Issue Number: None
   Related PR: None
   PR Type: Enhancement
   
   Problem Summary:
   
   **Reason for this change:** time columns that drive partitioning are often 
nullable in practice, for example event, ship or close dates that are not known 
yet, or tables created by CTAS from external sources where every column is 
nullable. Today AUTO RANGE PARTITION rejects these columns outright (`AUTO 
RANGE PARTITION doesn't support NULL column`), and even past that check a NULL 
value fails the load with `Can't create partition for NULL Range`. Users must 
either declare the column NOT NULL and rewrite NULLs to a fake date, or give up 
auto partitioning. Plain range partitioning and auto list partitioning already 
handle NULL, so auto range is the only partitioning mode that cannot.
   
   With this PR a nullable column is accepted, and a NULL row goes to the 
partition that starts at the type's minimum (`p00000101000000` = `[0000-01-01, 
...)`), which is where range partitioning already places NULL. It is FE only. 
Existing tables and NOT NULL columns behave as before.
   
   ### Details
   
   - **Before and after:**
       - `CREATE TABLE` and CTAS with a nullable AUTO RANGE PARTITION column 
used to fail; they now succeed. The nullable check is removed from 
`PartitionTableInfo`. CTAS keeps the source column's nullability.
       - `PartitionExprUtil.getAddPartitionClauseFromPartitionValues` used to 
throw for a NULL range value. It now creates the range that starts at the 
column type's minimum: `0000-01-01` for date types, the minimum timestamp for 
`TIMESTAMP_NS`. That lower bound is `MIN_VALUE`, which `OlapTableSink` sends to 
BE without a start key. BE's `_part_contains` treats a partition with no start 
key as unbounded below, so NULL rows (which compare below every bound) route 
there with no BE change. It is the same partition a row holding the minimum 
value would create, so the two never conflict. If the table already has an 
explicit first `LESS THAN` partition, it holds NULL and BE never asks for a new 
one.
       - `DynamicPartitionScheduler`: on a nullable auto range table, 
`partition.retention_count` and `dynamic_partition.start` cleanup no longer 
drop or count the `MIN_VALUE` partition. It always has the oldest bounds, so 
cleanup would otherwise drop every NULL row first. Users can still drop it 
explicitly.
   - **Configs and defaults:** no new config. `allow_partition_column_nullable` 
(default true) still applies: when it is false, a nullable partition column is 
rejected as before.
   - **Impact on existing users:** none for existing tables. The NOT NULL path, 
list auto partitions, and dynamic-partition tables that are not auto 
partitioned are unchanged. Tables that used to fail at `CREATE TABLE` now 
succeed.
   
   ### Testing
   
   - FE unit tests, run locally on this branch (based on `e46677d8008`): 
`run-fe-ut.sh --run 'PartitionExprUtilTest,DynamicPartitionTableTest'`, 59/59 
pass.
       - `PartitionExprUtilTest`: NULL creates `p00000101000000` with a 
`MIN_VALUE` lower bound and no start key in the returned `TOlapTablePartition`. 
A repeated NULL and the minimum value in one batch reuse it while an ordinary 
value creates its own partition. DATE/month gives bounds `[0000-01-01, 
0000-02-01)`.
       - `DynamicPartitionTableTest`: with `retention_count = 1`, the 
`MIN_VALUE` partition is kept on a nullable column and dropped on a NOT NULL 
one.
   - Regression tests (not run locally; need a cluster, left to CI):
       - New `partition_p0/auto_partition/test_auto_range_partition_nullable` 
covers insert with NULL, reuse of the NULL partition, `IS NULL` / `IS NOT NULL` 
/ equality queries, `INSERT OVERWRITE ... PARTITION(*)`, DATETIME(6) hourly, an 
explicit `LESS THAN` first partition, and `allow_partition_column_nullable = 
false`.
       - Updated `test_ctas_auto_partition`, `test_auto_partition_behavior` and 
the auto-partitioning doc suite, which asserted the old error.
   
   ### Notes for Reviewers
   
   - Start at `PartitionExprUtil.getNullRangeBegin` and 
`DynamicPartitionScheduler.holdsNullPartitionValues`.
   - I chose the existing "NULL is the smallest value" placement over a 
dedicated NULL partition with a special name so that partition pruning (`IS 
NULL` keeps the `MIN_VALUE` partition), BE routing and partition naming all 
stay as they are for ordinary range partitions.
   - With `date_floor` and a multi-unit period, the NULL partition is `[min, 
min + period)` rather than a floor-aligned bucket. It could only collide with 
real data dated in year 0.
   
   ### Release note
   
   AUTO RANGE PARTITION now accepts a nullable partition column. Rows whose 
partition column is NULL are stored in the partition that starts at the type's 
minimum (for example `p00000101000000`), and partition retention never drops 
that partition.
   
   ### Check List (For Author)
   
   - Behavior changed: Yes (see Details)
   - Does this need documentation: Yes. The auto partition doc currently says 
AUTO RANGE PARTITION does not support NULL columns; I will update it in 
apache/doris-website once this is accepted.
   - Pre-submission status: Partially verified: FE unit tests pass locally; 
regression suites not run locally.
   
   ### AI Disclosure
   
   - Tool: Claude Code (Claude Opus 5.5)
   - Generated: code, tests, and this description
   - Human review: pending the author's review of the diff before it is marked 
ready
   


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