[HUDI-3171] Sync empty table to hive metastore (#4511)
This commit is contained in:
@@ -198,8 +198,15 @@ public class TableSchemaResolver {
|
|||||||
*/
|
*/
|
||||||
public MessageType getTableParquetSchema() throws Exception {
|
public MessageType getTableParquetSchema() throws Exception {
|
||||||
Option<Schema> schemaFromCommitMetadata = getTableSchemaFromCommitMetadata(true);
|
Option<Schema> schemaFromCommitMetadata = getTableSchemaFromCommitMetadata(true);
|
||||||
return schemaFromCommitMetadata.isPresent() ? convertAvroSchemaToParquet(schemaFromCommitMetadata.get()) :
|
if (schemaFromCommitMetadata.isPresent()) {
|
||||||
getTableParquetSchemaFromDataFile();
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
package org.apache.hudi.hive;
|
package org.apache.hudi.hive;
|
||||||
|
|
||||||
import org.apache.hudi.common.fs.FSUtils;
|
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.table.timeline.HoodieTimeline;
|
||||||
import org.apache.hudi.common.util.Option;
|
import org.apache.hudi.common.util.Option;
|
||||||
import org.apache.hudi.common.util.StringUtils;
|
import org.apache.hudi.common.util.StringUtils;
|
||||||
@@ -331,13 +332,15 @@ public class HoodieHiveClient extends AbstractSyncHoodieClient {
|
|||||||
@Override
|
@Override
|
||||||
public void updateLastCommitTimeSynced(String tableName) {
|
public void updateLastCommitTimeSynced(String tableName) {
|
||||||
// Set the last commit time from the TBLproperties
|
// Set the last commit time from the TBLproperties
|
||||||
String lastCommitSynced = activeTimeline.lastInstant().get().getTimestamp();
|
Option<String> lastCommitSynced = activeTimeline.lastInstant().map(HoodieInstant::getTimestamp);
|
||||||
|
if (lastCommitSynced.isPresent()) {
|
||||||
try {
|
try {
|
||||||
Table table = client.getTable(syncConfig.databaseName, tableName);
|
Table table = client.getTable(syncConfig.databaseName, tableName);
|
||||||
table.putToParameters(HOODIE_LAST_COMMIT_TIME_SYNC, lastCommitSynced);
|
table.putToParameters(HOODIE_LAST_COMMIT_TIME_SYNC, lastCommitSynced.get());
|
||||||
client.alter_table(syncConfig.databaseName, tableName, table);
|
client.alter_table(syncConfig.databaseName, tableName, table);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new HoodieHiveSyncException("Failed to get update last commit time synced to " + lastCommitSynced, e);
|
throw new HoodieHiveSyncException("Failed to get update last commit time synced to " + lastCommitSynced, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user