Gabriel39 commented on code in PR #71365:
URL: https://github.com/apache/doris/pull/71365#discussion_r4794056093


##########
regression-test/suites/mtmv_p0/test_iceberg_mtmv_retained_specs.groovy:
##########
@@ -0,0 +1,136 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+suite("test_iceberg_mtmv_retained_specs", 
"p0,external,iceberg,external_docker,external_docker_hive") {
+    if 
(!"true".equalsIgnoreCase(context.config.otherConfigs.get("enableIcebergTest")))
 {
+        logger.info("disable iceberg test.")
+        return
+    }
+    String externalEnvIp = context.config.otherConfigs.get("externalEnvIp")
+    String restPort = context.config.otherConfigs.get("iceberg_rest_uri_port")
+    String minioPort = context.config.otherConfigs.get("iceberg_minio_port")
+    String catalog = "iceberg_mtmv_retained_specs"
+    String database = "regression_test_iceberg_mtmv_retained_specs"
+    String sourceDatabase = "mtmv_retained_specs"
+
+    sql "drop catalog if exists ${catalog}"
+    sql """create catalog ${catalog} properties (
+        'type'='iceberg',
+        'iceberg.catalog.type'='rest',
+        'uri'='http://${externalEnvIp}:${restPort}',
+        's3.access_key'='admin',
+        's3.secret_key'='password',
+        's3.endpoint'='http://${externalEnvIp}:${minioPort}',
+        's3.region'='us-east-1'
+    )"""
+    sql "switch internal"
+    sql "drop database if exists ${database} force"
+    sql "create database ${database}"
+    sql "use ${database}"
+    sql "drop database if exists ${catalog}.${sourceDatabase} force"
+    sql "create database ${catalog}.${sourceDatabase}"
+
+    def compareWithSource = { String mv, String source ->
+        // Compare complete ordered rows against the independently executed 
base-table query.
+        def expected = sql "select /*+ 
SET_VAR(enable_materialized_view_rewrite=false) */ id, event_date from 
${catalog}.${sourceDatabase}.${source} order by id"
+        def actual = sql "select id, event_date from ${mv} order by id"
+        assertEquals(expected, actual)
+    }
+
+    def overwriteAll = { String statement ->
+        String previousMode = sql("show variables like 
'iceberg_partition_overwrite_mode'")[0][1].toString()
+        try {
+            sql "set iceberg_partition_overwrite_mode='static'"
+            sql statement
+        } finally {
+            sql "set iceberg_partition_overwrite_mode='${previousMode}'"
+        }
+    }
+
+    sql """create table ${catalog}.${sourceDatabase}.evolved_events (id int, 
event_date date)
+        engine=iceberg properties ('format-version'='2')"""
+    sql """insert into ${catalog}.${sourceDatabase}.evolved_events values
+        (1, '1969-12-31'), (2, null)"""
+    sql "alter table ${catalog}.${sourceDatabase}.evolved_events add partition 
key event_date"
+    sql "alter table ${catalog}.${sourceDatabase}.evolved_events drop 
partition key event_date"
+    sql "alter table ${catalog}.${sourceDatabase}.evolved_events add partition 
key day(event_date)"
+    sql "insert into ${catalog}.${sourceDatabase}.evolved_events values (3, 
'2024-01-02')"
+    sql "refresh table ${catalog}.${sourceDatabase}.evolved_events"
+
+    // The default day spec is insufficient while unpartitioned data is still 
live.
+    test {
+        sql """create materialized view mv_evolved_events build deferred 
refresh auto on manual
+            partition by(event_date) distributed by random buckets 1
+            properties ('replication_num'='1')
+            as select id, event_date from 
${catalog}.${sourceDatabase}.evolved_events"""
+        exception "Unable to find a suitable base table for partitioning"
+    }
+
+    // Rewriting live files keeps the old specs and snapshots but makes the 
current layout representable.
+    overwriteAll """insert overwrite table 
${catalog}.${sourceDatabase}.evolved_events
+        select /*+ SET_VAR(enable_materialized_view_rewrite=false) */ id, 
event_date from ${catalog}.${sourceDatabase}.evolved_events"""
+    sql "refresh table ${catalog}.${sourceDatabase}.evolved_events"
+    sql """create materialized view mv_evolved_events build deferred refresh 
auto on manual
+        partition by(event_date) distributed by random buckets 1
+        properties ('replication_num'='1')
+        as select id, event_date from 
${catalog}.${sourceDatabase}.evolved_events"""
+    sql "refresh materialized view mv_evolved_events complete"
+    waitingMTMVTaskFinishedByMvName("mv_evolved_events", database)
+    compareWithSource("mv_evolved_events", "evolved_events")
+    sql "insert into ${catalog}.${sourceDatabase}.evolved_events values (4, 
'2024-01-03')"
+    sql "refresh materialized view mv_evolved_events auto"
+    waitingMTMVTaskFinishedByMvName("mv_evolved_events", database)
+    compareWithSource("mv_evolved_events", "evolved_events")
+
+    sql """create table ${catalog}.${sourceDatabase}.identity_events (id int, 
event_date date)
+        engine=iceberg partition by list(event_date) () properties 
('format-version'='2')"""
+    sql """insert into ${catalog}.${sourceDatabase}.identity_events values
+        (1, '2024-02-01'), (2, null), (6, '9999-12-31')"""
+    sql "alter table ${catalog}.${sourceDatabase}.identity_events drop 
partition key event_date"
+    sql "alter table ${catalog}.${sourceDatabase}.identity_events add 
partition key day(event_date)"
+    sql """insert into ${catalog}.${sourceDatabase}.identity_events values
+        (3, '2024-02-01'), (4, null), (5, '2024-02-02')"""
+    sql "refresh table ${catalog}.${sourceDatabase}.identity_events"
+    sql """create materialized view mv_identity_events build deferred refresh 
auto on manual
+        partition by(event_date) distributed by random buckets 1
+        properties ('replication_num'='1')
+        as select id, event_date from 
${catalog}.${sourceDatabase}.identity_events"""
+    sql "refresh materialized view mv_identity_events complete"
+    waitingMTMVTaskFinishedByMvName("mv_identity_events", database)
+    compareWithSource("mv_identity_events", "identity_events")
+
+    // NULL must not absorb other timestamp hours in the first representable 
day.
+    sql """create table ${catalog}.${sourceDatabase}.hour_events (id int, 
event_date datetimev2(6))
+        engine=iceberg properties ('format-version'='2')"""
+    sql "alter table ${catalog}.${sourceDatabase}.hour_events add partition 
key hour(event_date)"
+    sql """insert into ${catalog}.${sourceDatabase}.hour_events values
+        (1, null), (2, '0000-01-01 12:00:00'), (3, '0000-01-01 00:00:00')"""

Review Comment:
   The earlier source/MV equality check missed a shared calendar error. Fixed 
in 939966739808909ef795e670f87e0de959d2ef23: timestamp day/hour transforms now 
produce Gregorian Iceberg ordinals before March of year zero, and the Parquet 
DATETIMEV2 consumer uses the matching calendar conversion. The shared SQL test 
now checks explicit midnight/noon literals after a real Doris write and MV 
refresh. Transformer, decoded-value and Parquet tests passed, as did both SQL 
suites on each branch's own FE/BE. Review also caught conversion-generated 
NULLs inside valid timestamp statistics bounds; the new footer/page regression 
proves those candidates are retained. Synchronized to #71373.



##########
fe/fe-connector/fe-connector-iceberg/src/main/java/org/apache/doris/connector/iceberg/IcebergPartitionUtils.java:
##########
@@ -1143,9 +1146,11 @@ static RangeBuild buildRange(String name, String value, 
String transform, Type s
         // "yyyy-MM-dd", iceberg TIMESTAMP/TIMESTAMPTZ -> "yyyy-MM-dd 
HH:mm:ss" (HOUR's source is always a
         // timestamp). Equivalent to master's c.getType().isDate()||isDateV2() 
formatter switch.
         DateTimeFormatter formatter = sourceType.typeId() == TypeID.DATE ? 
RANGE_DATE_FORMAT : RANGE_DATETIME_FORMAT;
+        // The last valid calendar interval ends in year 10000, outside 
Doris's literal domain.
+        String upperBound = upper.getYear() > 9999 ? "MAXVALUE" : 
upper.format(formatter) + rangeOffset(sourceType);

Review Comment:
   Fixed in 939966739808909ef795e670f87e0de959d2ef23. The common projection 
validates both closed-open endpoints against the Doris calendar, and the legacy 
adapter applies the same endpoint check. An hour ending at 0000-02-29 is 
unsupported and falls back to native planning instead of throwing while 
materializing a range. Only the final 10000-01-01 exclusive boundary is 
represented by MAXVALUE. Real-manifest tests cover the February boundary; newly 
admitted fine-grained year-zero DATE ranges also use the same conservative 
domain on both branches. Synchronized to #71373.



##########
fe/fe-connector/fe-connector-spi/src/main/java/org/apache/doris/connector/spi/mvcc/ConnectorMvccPartition.java:
##########
@@ -40,6 +40,10 @@
  * upper as {@code lowerKey.successor()} in that case — matching the 
connector's source behavior (e.g. iceberg's
  * {@code nullLowKey.successor()}). A non-NULL RANGE partition always carries 
BOTH bounds non-empty; the model
  * must not call {@code createPartitionKey} on an empty upper tuple.</p>
+ *
+ * <p>For temporal RANGE columns, {@code "MAXVALUE"} denotes an unbounded 
endpoint when the

Review Comment:
   Fixed in 939966739808909ef795e670f87e0de959d2ef23. The connector plugin API 
is now 43.0, the range contract documents that temporal MAXVALUE starts at API 
43, and the surface test checks the new version. An API-42 engine cannot accept 
the new plugin through the existing major-version gate. The native branch uses 
its existing MAXVALUE representation and needs no SPI change.



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