This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-4.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-4.1 by this push:
new dea8d02044c [fix](paimon) Default new tables to portable ORC LTZ
encoding (#68924)
dea8d02044c is described below
commit dea8d02044cc0f2585d15b81345f61b5ff2d4b6f
Author: Gabriel <[email protected]>
AuthorDate: Mon Oct 12 14:39:15 2026 +0800
[fix](paimon) Default new tables to portable ORC LTZ encoding (#68924)
### What problem does this PR solve?
Paimon's default legacy ORC encoding for `TIMESTAMP_LTZ` depends on the
writer and reader JVM time zones. For example, an instant written in a
UTC JVM and read in an Asia/Shanghai JVM shifts by eight hours, even
when both engines agree on the SQL session time zone. Doris currently
inherits this legacy default when creating Paimon tables.
Persist `orc.timestamp-ltz.legacy.type=false` when Doris creates a
Paimon table. Explicit table settings take precedence over the Paimon
catalog's `table-default.orc.timestamp-ltz.legacy.type`, and both take
precedence over the new default. Persist the option for all new tables
so adding an LTZ column or subsequently selecting ORC does not silently
enable legacy encoding.
Existing tables retain their encoding settings. This change does **not**
repair historical legacy files or change tables created by Spark/Flink.
Modern and legacy LTZ files share the same ORC physical type, and
LTZ-only legacy files may omit the writer time zone, so an automatic
reinterpretation would be unsafe. Existing legacy data needs a
controlled rewrite into a table with the modern encoding; changing the
property alone is not a migration.
### Release note
New Paimon tables created through Doris default to portable ORC
`TIMESTAMP_LTZ` encoding. Explicit table and catalog defaults remain
supported, and existing table options are unchanged.
### Validation
- Compiled the changed production and test classes and ran
`PaimonMetadataOpsTest` with JUnit using an existing branch-4.1 FE
dependency classpath: 28 tests passed. Before the fix, the new
default-encoding test failed because the persisted option was absent.
- Repository FE Checkstyle (`mvn -pl fe-core checkstyle:check`): passed
with zero violations.
- Added coverage for ORC/Parquet tables, LTZ/NTZ schema types, explicit
legacy/modern options, catalog defaults, table overrides, and
preservation of existing legacy options through `IF NOT EXISTS` and
unrelated `ALTER`.
- Real Paimon 1.4.2 ORC `FormatWriter`/`FormatReader` probe with
`orc.timestamp-ltz.legacy.type=false`: separate JVMs using
`-Duser.timezone=UTC`, `Asia/Shanghai`, and `America/Los_Angeles`, all
nine writer/reader combinations. Ten synthetic timestamps covering
winter/summer, DST boundaries, microseconds, epoch zero, a negative
epoch and 2038 produced 180/180 LTZ/NTZ value assertions and 9/9
row-count assertions passing.
- Validation limits: the local end-to-end run uses cached Doris binaries
with the equivalent FE fix, rather than a complete rebuild of the
current branch; Flink was not included. A separate pre-epoch subsecond
edge (`-1us` and `-1001us`) fails with the same +1-second result under
both legacy and modern SDK encoding in UTC; that existing SDK issue is
outside this time-zone-default change.
- Added `test_paimon_orc_ltz_encoding` to the Paimon regression suites.
It checks persisted properties through Spark, explicit legacy opt-in,
bidirectional Doris/Spark writes, exact epoch microseconds, NTZ civil
fields, NULLs, and reads with both `force_jni_scanner` settings in UTC
and Asia/Shanghai.
- Ran that exact regression suite against cached Doris 4.1.4-rc04
binaries and Spark 4/Paimon 1.4.2, with the BE JVM in Asia/Shanghai and
Spark JVM in UTC. The unmodified FE failed on the missing persisted
option; applying the equivalent seven-line FE fix produced **1 suite
passed, 0 failed, 0 skipped**. No generated golden output was used. The
task-owned test services were stopped after validation.
### Check List (For Author)
- Test
- [x] Regression test
- [x] Unit Test
- [x] Manual test (real Paimon ORC files in separate writer/reader JVMs)
- Behavior changed:
- [x] Yes. New-table default only, as described above.
- Does this need documentation?
- [x] Yes. Document the new default and the requirement to rewrite
historical legacy data before opting into modern encoding.
### Check List (For Reviewer who merge this PR)
- [ ] Confirm the release note
- [ ] Confirm test cases
- [ ] Confirm document
- [ ] Add branch pick label
---
.../doris/datasource/paimon/PaimonMetadataOps.java | 7 ++
.../datasource/paimon/PaimonMetadataOpsTest.java | 80 +++++++++++++
.../write/test_paimon_orc_ltz_encoding.groovy | 125 +++++++++++++++++++++
3 files changed, 212 insertions(+)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/datasource/paimon/PaimonMetadataOps.java
b/fe/fe-core/src/main/java/org/apache/doris/datasource/paimon/PaimonMetadataOps.java
index dab26f3acc9..9e8aa8c0b5e 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/datasource/paimon/PaimonMetadataOps.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/datasource/paimon/PaimonMetadataOps.java
@@ -50,6 +50,7 @@ import
org.apache.paimon.catalog.Catalog.DatabaseNotExistException;
import org.apache.paimon.catalog.Catalog.TableAlreadyExistException;
import org.apache.paimon.catalog.Catalog.TableNotExistException;
import org.apache.paimon.catalog.Identifier;
+import org.apache.paimon.format.OrcOptions;
import org.apache.paimon.schema.Schema;
import org.apache.paimon.schema.SchemaChange;
import org.apache.paimon.schema.SchemaManager;
@@ -296,6 +297,12 @@ public class PaimonMetadataOps implements
ExternalMetadataOps {
Map<String, String> normalizedProperties = new HashMap<>(properties);
normalizedProperties.remove(PRIMARY_KEY_IDENTIFIER);
normalizedProperties.remove(PROP_COMMENT);
+ // Legacy ORC LTZ encoding depends on the writer and reader JVM time
zones. Persist the
+ // portable encoding for new tables only; changing an existing table
can reinterpret its files.
+ // Explicit table options take precedence over catalog defaults,
including a legacy opt-in.
+ String orcTimestampLegacyKey =
OrcOptions.ORC_TIMESTAMP_LTZ_LEGACY_TYPE.key();
+ normalizedProperties.putIfAbsent(orcTimestampLegacyKey,
catalog.options().getOrDefault(
+ Catalog.TABLE_DEFAULT_OPTION_PREFIX + orcTimestampLegacyKey,
"false"));
if (normalizedProperties.containsKey(PROP_LOCATION)) {
String path = normalizedProperties.remove(PROP_LOCATION);
normalizedProperties.put(CoreOptions.PATH.key(), path);
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/datasource/paimon/PaimonMetadataOpsTest.java
b/fe/fe-core/src/test/java/org/apache/doris/datasource/paimon/PaimonMetadataOpsTest.java
index 5ce12fe698e..d55fab81086 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/datasource/paimon/PaimonMetadataOpsTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/datasource/paimon/PaimonMetadataOpsTest.java
@@ -36,9 +36,13 @@ import org.apache.doris.qe.ConnectContext;
import com.google.common.collect.Maps;
import org.apache.paimon.catalog.Catalog;
+import org.apache.paimon.catalog.CatalogContext;
import org.apache.paimon.catalog.FileSystemCatalog;
import org.apache.paimon.catalog.Identifier;
+import org.apache.paimon.format.OrcOptions;
+import org.apache.paimon.fs.local.LocalFileIO;
import org.apache.paimon.hive.HiveCatalog;
+import org.apache.paimon.options.Options;
import org.apache.paimon.schema.Schema;
import org.apache.paimon.schema.SchemaChange;
import org.apache.paimon.table.Table;
@@ -49,6 +53,7 @@ import org.apache.paimon.types.DecimalType;
import org.apache.paimon.types.DoubleType;
import org.apache.paimon.types.FloatType;
import org.apache.paimon.types.IntType;
+import org.apache.paimon.types.LocalZonedTimestampType;
import org.apache.paimon.types.TimestampType;
import org.apache.paimon.types.VarCharType;
import org.junit.Assert;
@@ -144,6 +149,81 @@ public class PaimonMetadataOpsTest {
Assert.assertEquals(1, table.primaryKeys().size());
}
+ @Test
+ public void testNewTablesPersistModernOrcTimestampEncoding() throws
Exception {
+ for (String format : Arrays.asList("orc", "parquet")) {
+ String tableName = getTableName();
+ createTable("create table " + dbName + "." + tableName
+ + " (ts timestamptz(6), local_ts datetime(6)) engine =
paimon"
+ + " properties ('file.format' = '" + format + "')");
+
+ Table table = ops.getCatalog().getTable(new Identifier(dbName,
tableName));
+ Assert.assertTrue(table.rowType().getTypeAt(0) instanceof
LocalZonedTimestampType);
+ Assert.assertTrue(table.rowType().getTypeAt(1) instanceof
TimestampType);
+ Assert.assertEquals("false",
table.options().get(OrcOptions.ORC_TIMESTAMP_LTZ_LEGACY_TYPE.key()));
+ }
+ }
+
+ @Test
+ public void testExplicitOrcTimestampEncodingIsPreserved() throws Exception
{
+ for (String legacy : Arrays.asList("true", "false")) {
+ String tableName = getTableName();
+ createTable("create table " + dbName + "." + tableName
+ + " (ts timestamptz(6)) engine = paimon properties
('file.format' = 'orc', '"
+ + OrcOptions.ORC_TIMESTAMP_LTZ_LEGACY_TYPE.key() + "' = '"
+ legacy + "')");
+
+ Assert.assertEquals(legacy, ops.getCatalog().getTable(new
Identifier(dbName, tableName))
+
.options().get(OrcOptions.ORC_TIMESTAMP_LTZ_LEGACY_TYPE.key()));
+ }
+ }
+
+ @Test
+ public void testOrcTimestampEncodingHonorsCatalogDefaultAndTableOverride()
throws Exception {
+ String key = OrcOptions.ORC_TIMESTAMP_LTZ_LEGACY_TYPE.key();
+ Options options = new Options();
+ options.setString(Catalog.TABLE_DEFAULT_OPTION_PREFIX + key, "true");
+ try (FileSystemCatalog remoteCatalog = new
FileSystemCatalog(LocalFileIO.create(),
+ new org.apache.paimon.fs.Path(warehouse),
CatalogContext.create(options))) {
+ PaimonMetadataOps catalogOps = new
PaimonMetadataOps(paimonCatalog, remoteCatalog);
+ for (boolean override : Arrays.asList(false, true)) {
+ String tableName = getTableName();
+ catalogOps.createTable(parseCreateTableInfo("create table " +
dbName + "." + tableName
+ + " (ts timestamptz(6)) engine = paimon properties
('file.format' = 'orc'"
+ + (override ? ", '" + key + "' = 'false'" : "") +
")"));
+
+ Assert.assertEquals(override ? "false" : "true", remoteCatalog
+ .loadTableSchema(new Identifier(dbName,
tableName)).options().get(key));
+ }
+ }
+ }
+
+ @Test
+ public void testExistingLegacyOrcTableEncodingIsNotChanged() throws
Exception {
+ String key = OrcOptions.ORC_TIMESTAMP_LTZ_LEGACY_TYPE.key();
+ for (boolean explicitLegacy : Arrays.asList(false, true)) {
+ String tableName = getTableName();
+ Identifier identifier = new Identifier(dbName, tableName);
+ Schema.Builder schema = Schema.newBuilder().column("ts", new
LocalZonedTimestampType(6))
+ .option("file.format", "orc");
+ if (explicitLegacy) {
+ schema.option(key, "true");
+ }
+ // SDK-created tables model historical schemas where the legacy
option may be absent.
+ ops.getCatalog().createTable(identifier, schema.build(), false);
+ createTable("create table if not exists " + dbName + "." +
tableName
+ + " (ts timestamptz(6)) engine = paimon");
+ Assert.assertEquals(explicitLegacy ? "true" : null,
+ ops.getCatalog().getTable(identifier).options().get(key));
+
+ Map<String, String> properties = new HashMap<>();
+ properties.put("snapshot.num-retained.min", "2");
+ ops.updateTableProperties(mockExternalTable(tableName),
properties, 123L);
+ ops.getCatalog().invalidateTable(identifier);
+ Assert.assertEquals(explicitLegacy ? "true" : null,
+ ops.getCatalog().getTable(identifier).options().get(key));
+ }
+ }
+
@Test
public void testUpdateTablePropertiesPersistsAllOptions() throws Exception
{
String tableName = getTableName();
diff --git
a/regression-test/suites/external_table_p0/paimon/write/test_paimon_orc_ltz_encoding.groovy
b/regression-test/suites/external_table_p0/paimon/write/test_paimon_orc_ltz_encoding.groovy
new file mode 100644
index 00000000000..fc3f30477c5
--- /dev/null
+++
b/regression-test/suites/external_table_p0/paimon/write/test_paimon_orc_ltz_encoding.groovy
@@ -0,0 +1,125 @@
+// 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_paimon_orc_ltz_encoding", "p0,external,paimon") {
+ String enabled = context.config.otherConfigs.get("enablePaimonTest")
+ if (enabled == null || !enabled.equalsIgnoreCase("true")) {
+ logger.info("disable paimon test.")
+ return
+ }
+
+ String externalEnvIp = context.config.otherConfigs.get("externalEnvIp")
+ String minioPort = context.config.otherConfigs.get("iceberg_minio_port")
+ String catalogName = "test_pw_orc_ltz_catalog"
+ String dbName = "test_pw_orc_ltz_db"
+ String legacyKey = "orc.timestamp-ltz.legacy.type"
+ def originalTimeZone = sql "SELECT @@time_zone"
+ def originalJniScanner = sql "SELECT @@force_jni_scanner"
+
+ sql "DROP CATALOG IF EXISTS ${catalogName}"
+ sql """CREATE CATALOG ${catalogName} PROPERTIES (
+ 'type' = 'paimon',
+ 'paimon.catalog.type' = 'filesystem',
+ 'warehouse' = 's3://warehouse/wh',
+ 's3.endpoint' = 'http://${externalEnvIp}:${minioPort}',
+ 's3.access_key' = 'admin',
+ 's3.secret_key' = 'password',
+ 's3.path.style.access' = 'true'
+ )"""
+ try {
+ sql "SWITCH ${catalogName}"
+ sql "DROP DATABASE IF EXISTS ${dbName} FORCE"
+ sql "CREATE DATABASE ${dbName}"
+ sql "USE ${dbName}"
+ sql """CREATE TABLE t_modern (
+ id INT, event_time TIMESTAMPTZ(6), local_time DATETIME(6)
+ ) ENGINE=paimon PROPERTIES ('file.format' = 'orc')"""
+
+ // Inspect persisted metadata through Spark: a same-JVM legacy round
trip can hide the bug.
+ def assertEncoding = { String tableName, String expected ->
+ assertEquals([[legacyKey, expected]], spark_paimon("""
+ SHOW TBLPROPERTIES paimon.${dbName}.${tableName}
('${legacyKey}')
+ """))
+ }
+ assertEncoding("t_modern", "false")
+ sql """CREATE TABLE t_legacy (event_time TIMESTAMPTZ(6)) ENGINE=paimon
+ PROPERTIES ('file.format' = 'orc', '${legacyKey}' = 'true')"""
+ sql """CREATE TABLE IF NOT EXISTS t_legacy (event_time TIMESTAMPTZ(6))
ENGINE=paimon"""
+ assertEncoding("t_legacy", "true")
+
+ sql "SET time_zone = 'Asia/Shanghai'"
+ sql """INSERT INTO t_modern VALUES
+ (1, CAST('2024-01-15 10:30:00.123456+08:00' AS TIMESTAMPTZ(6)),
+ CAST('2024-03-10 02:30:00.123456' AS DATETIME(6)))"""
+ sql "SET time_zone = 'UTC'"
+ sql """INSERT INTO t_modern VALUES
+ (2, CAST('2024-07-15 02:30:00.654321+00:00' AS TIMESTAMPTZ(6)),
+ CAST('2024-07-15 10:30:00.654321' AS DATETIME(6)))"""
+
+ // Epoch microseconds check the stored instants independently of
display/session time zones.
+ spark_paimon "REFRESH TABLE paimon.${dbName}.t_modern"
+ assertSparkDorisResultEquals(spark_paimon("""
+ SELECT id, unix_micros(event_time), CAST(local_time AS STRING)
+ FROM paimon.${dbName}.t_modern ORDER BY id
+ """), [
+ [1, 1705285800123456L, "2024-03-10 02:30:00.123456"],
+ [2, 1721010600654321L, "2024-07-15 10:30:00.654321"]
+ ])
+ spark_paimon """
+ INSERT INTO paimon.${dbName}.t_modern VALUES
+ (3, TIMESTAMP '2023-11-05 08:30:00.123456+00:00',
+ CAST('2023-11-05 01:30:00.123456' AS TIMESTAMP_NTZ)),
+ (4, TIMESTAMP '2023-11-05 09:30:00.654321+00:00',
+ CAST('2023-11-05 01:30:00.654321' AS TIMESTAMP_NTZ)),
+ (5, NULL, NULL)
+ """
+ sql "REFRESH TABLE t_modern"
+ def expectedUtc = [
+ [1, "2024-01-15 02:30:00.123456+00:00", "2024-03-10
02:30:00.123456"],
+ [2, "2024-07-15 02:30:00.654321+00:00", "2024-07-15
10:30:00.654321"],
+ [3, "2023-11-05 08:30:00.123456+00:00", "2023-11-05
01:30:00.123456"],
+ [4, "2023-11-05 09:30:00.654321+00:00", "2023-11-05
01:30:00.654321"],
+ [5, null, null]
+ ]
+ def expectedShanghai = [
+ [1, "2024-01-15 10:30:00.123456+08:00", "2024-03-10
02:30:00.123456"],
+ [2, "2024-07-15 10:30:00.654321+08:00", "2024-07-15
10:30:00.654321"],
+ [3, "2023-11-05 16:30:00.123456+08:00", "2023-11-05
01:30:00.123456"],
+ [4, "2023-11-05 17:30:00.654321+08:00", "2023-11-05
01:30:00.654321"],
+ [5, null, null]
+ ]
+ for (boolean jni : [false, true]) {
+ sql "SET force_jni_scanner = ${jni}"
+ for (String zone : ["UTC", "Asia/Shanghai"]) {
+ sql "SET time_zone = '${zone}'"
+ assertEquals(zone == "UTC" ? expectedUtc : expectedShanghai,
sql("""
+ SELECT id, CAST(event_time AS STRING), CAST(local_time AS
STRING)
+ FROM t_modern ORDER BY id
+ """))
+ }
+ }
+ } finally {
+ sql "SET time_zone = '${originalTimeZone[0][0]}'"
+ sql "SET force_jni_scanner = ${originalJniScanner[0][0]}"
+ try {
+ sql "DROP DATABASE IF EXISTS ${catalogName}.${dbName} FORCE"
+ } finally {
+ sql "SWITCH internal"
+ sql "DROP CATALOG IF EXISTS ${catalogName}"
+ }
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]