This is an automated email from the ASF dual-hosted git repository.
wombatu-kun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hudi.git
The following commit(s) were added to refs/heads/master by this push:
new 58dd532e64a7 fix(hive-sync): set HMS table createTime in seconds
instead of milliseconds (#19335)
58dd532e64a7 is described below
commit 58dd532e64a7631971c0f735b82edb87285ad326
Author: Vova Kolmakov <[email protected]>
AuthorDate: Wed Jul 22 10:41:10 2026 +0700
fix(hive-sync): set HMS table createTime in seconds instead of milliseconds
(#19335)
---
.../org/apache/hudi/hive/ddl/HMSDDLExecutor.java | 4 +-
.../hive/ddl/TestHMSDDLExecutorCreateTable.java | 70 ++++++++++++++++++++++
2 files changed, 73 insertions(+), 1 deletion(-)
diff --git
a/hudi-sync/hudi-hive-sync/src/main/java/org/apache/hudi/hive/ddl/HMSDDLExecutor.java
b/hudi-sync/hudi-hive-sync/src/main/java/org/apache/hudi/hive/ddl/HMSDDLExecutor.java
index fa0d31a74cfa..b97bc8010d75 100644
---
a/hudi-sync/hudi-hive-sync/src/main/java/org/apache/hudi/hive/ddl/HMSDDLExecutor.java
+++
b/hudi-sync/hudi-hive-sync/src/main/java/org/apache/hudi/hive/ddl/HMSDDLExecutor.java
@@ -122,7 +122,9 @@ public class HMSDDLExecutor implements DDLExecutor {
newTb.setDbName(databaseName);
newTb.setTableName(tableName);
newTb.setOwner(UserGroupInformation.getCurrentUser().getShortUserName());
- newTb.setCreateTime((int) System.currentTimeMillis());
+ // Hive stores createTime as seconds since the epoch in an i32 field;
passing raw
+ // milliseconds both uses the wrong unit and overflows the int cast.
+ newTb.setCreateTime((int) (System.currentTimeMillis() / 1000));
StorageDescriptor storageDescriptor = new StorageDescriptor();
storageDescriptor.setCols(fieldSchema);
storageDescriptor.setInputFormat(inputFormatClass);
diff --git
a/hudi-sync/hudi-hive-sync/src/test/java/org/apache/hudi/hive/ddl/TestHMSDDLExecutorCreateTable.java
b/hudi-sync/hudi-hive-sync/src/test/java/org/apache/hudi/hive/ddl/TestHMSDDLExecutorCreateTable.java
new file mode 100644
index 000000000000..a03a7c28042f
--- /dev/null
+++
b/hudi-sync/hudi-hive-sync/src/test/java/org/apache/hudi/hive/ddl/TestHMSDDLExecutorCreateTable.java
@@ -0,0 +1,70 @@
+/*
+ * 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.
+ */
+
+package org.apache.hudi.hive.ddl;
+
+import org.apache.hudi.common.schema.HoodieSchema;
+import org.apache.hudi.common.schema.HoodieSchemaField;
+import org.apache.hudi.common.schema.HoodieSchemaType;
+import org.apache.hudi.hive.HiveSyncConfig;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hive.metastore.IMetaStoreClient;
+import org.apache.hadoop.hive.metastore.api.Table;
+import org.junit.jupiter.api.Test;
+import org.mockito.ArgumentCaptor;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Properties;
+
+import static org.apache.hudi.sync.common.HoodieSyncConfig.META_SYNC_BASE_PATH;
+import static
org.apache.hudi.sync.common.HoodieSyncConfig.META_SYNC_DATABASE_NAME;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+class TestHMSDDLExecutorCreateTable {
+
+ @Test
+ void createTableSetsCreateTimeInSeconds() throws Exception {
+ Properties props = new Properties();
+ props.setProperty(META_SYNC_DATABASE_NAME.key(), "testdb");
+ props.setProperty(META_SYNC_BASE_PATH.key(), "/tmp/test_table");
+ HiveSyncConfig config = new HiveSyncConfig(props, new Configuration());
+
+ IMetaStoreClient client = mock(IMetaStoreClient.class);
+ HMSDDLExecutor executor = new HMSDDLExecutor(config, client);
+
+ HoodieSchema schema = HoodieSchema.createRecord("test_record", null, null,
+ Collections.singletonList(HoodieSchemaField.of("id",
HoodieSchema.create(HoodieSchemaType.INT))));
+
+ long beforeSec = System.currentTimeMillis() / 1000;
+ executor.createTable("test_table", schema, "input.Format",
"output.Format", "serde.Class",
+ new HashMap<>(), new HashMap<>());
+ long afterSec = System.currentTimeMillis() / 1000;
+
+ ArgumentCaptor<Table> captor = ArgumentCaptor.forClass(Table.class);
+ verify(client).createTable(captor.capture());
+ int createTime = captor.getValue().getCreateTime();
+
+ // createTime must be epoch seconds within the call window.
+ assertTrue(createTime >= beforeSec && createTime <= afterSec,
+ "createTime should be epoch seconds within [" + beforeSec + ", " +
afterSec + "] but was " + createTime);
+ }
+}