This is an automated email from the ASF dual-hosted git repository.

sivabalan pushed a commit to branch release-0.10.1-rc1
in repository https://gitbox.apache.org/repos/asf/hudi.git

commit 8fdcbb1e0c48c71d2f50bdc5d69823d23b437896
Author: Danny Chan <[email protected]>
AuthorDate: Wed Jan 5 16:41:33 2022 +0800

    [HUDI-3171] Sync empty table to hive metastore (#4511)
---
 .../apache/hudi/common/table/TableSchemaResolver.java   | 11 +++++++++--
 .../java/org/apache/hudi/hive/HoodieHiveClient.java     | 17 ++++++++++-------
 2 files changed, 19 insertions(+), 9 deletions(-)

diff --git 
a/hudi-common/src/main/java/org/apache/hudi/common/table/TableSchemaResolver.java
 
b/hudi-common/src/main/java/org/apache/hudi/common/table/TableSchemaResolver.java
index 0508c1b..a953ac3 100644
--- 
a/hudi-common/src/main/java/org/apache/hudi/common/table/TableSchemaResolver.java
+++ 
b/hudi-common/src/main/java/org/apache/hudi/common/table/TableSchemaResolver.java
@@ -198,8 +198,15 @@ public class TableSchemaResolver {
    */
   public MessageType getTableParquetSchema() throws Exception {
     Option<Schema> schemaFromCommitMetadata = 
getTableSchemaFromCommitMetadata(true);
-    return schemaFromCommitMetadata.isPresent() ? 
convertAvroSchemaToParquet(schemaFromCommitMetadata.get()) :
-           getTableParquetSchemaFromDataFile();
+    if (schemaFromCommitMetadata.isPresent()) {
+      return convertAvroSchemaToParquet(schemaFromCommitMetadata.get());
+    }
+    Option<Schema> schemaFromTableConfig = 
metaClient.getTableConfig().getTableCreateSchema();
+    if (schemaFromTableConfig.isPresent()) {
+      Schema schema = 
HoodieAvroUtils.addMetadataFields(schemaFromTableConfig.get(), 
withOperationField);
+      return convertAvroSchemaToParquet(schema);
+    }
+    return getTableParquetSchemaFromDataFile();
   }
 
   /**
diff --git 
a/hudi-sync/hudi-hive-sync/src/main/java/org/apache/hudi/hive/HoodieHiveClient.java
 
b/hudi-sync/hudi-hive-sync/src/main/java/org/apache/hudi/hive/HoodieHiveClient.java
index 287de57..acaf6ca 100644
--- 
a/hudi-sync/hudi-hive-sync/src/main/java/org/apache/hudi/hive/HoodieHiveClient.java
+++ 
b/hudi-sync/hudi-hive-sync/src/main/java/org/apache/hudi/hive/HoodieHiveClient.java
@@ -19,6 +19,7 @@
 package org.apache.hudi.hive;
 
 import org.apache.hudi.common.fs.FSUtils;
+import org.apache.hudi.common.table.timeline.HoodieInstant;
 import org.apache.hudi.common.table.timeline.HoodieTimeline;
 import org.apache.hudi.common.util.Option;
 import org.apache.hudi.common.util.StringUtils;
@@ -331,13 +332,15 @@ public class HoodieHiveClient extends 
AbstractSyncHoodieClient {
   @Override
   public void updateLastCommitTimeSynced(String tableName) {
     // Set the last commit time from the TBLproperties
-    String lastCommitSynced = 
activeTimeline.lastInstant().get().getTimestamp();
-    try {
-      Table table = client.getTable(syncConfig.databaseName, tableName);
-      table.putToParameters(HOODIE_LAST_COMMIT_TIME_SYNC, lastCommitSynced);
-      client.alter_table(syncConfig.databaseName, tableName, table);
-    } catch (Exception e) {
-      throw new HoodieHiveSyncException("Failed to get update last commit time 
synced to " + lastCommitSynced, e);
+    Option<String> lastCommitSynced = 
activeTimeline.lastInstant().map(HoodieInstant::getTimestamp);
+    if (lastCommitSynced.isPresent()) {
+      try {
+        Table table = client.getTable(syncConfig.databaseName, tableName);
+        table.putToParameters(HOODIE_LAST_COMMIT_TIME_SYNC, 
lastCommitSynced.get());
+        client.alter_table(syncConfig.databaseName, tableName, table);
+      } catch (Exception e) {
+        throw new HoodieHiveSyncException("Failed to get update last commit 
time synced to " + lastCommitSynced, e);
+      }
     }
   }
 }

Reply via email to