Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.apache.hudi.hadoop.fs.HadoopFSUtils.getStorageConf;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
Expand All @@ -30,13 +31,15 @@

import org.apache.hadoop.conf.Configuration;

import org.apache.hudi.common.fs.FSUtils;
import org.apache.hudi.common.model.HoodieAvroPayload;
import org.apache.hudi.common.model.HoodieTableType;
import org.apache.hudi.common.model.HoodieTimelineTimeZone;
import org.apache.hudi.common.table.HoodieTableMetaClient;
import org.apache.hudi.common.table.HoodieTableVersion;
import org.apache.hudi.common.util.VisibleForTesting;
import org.apache.hudi.exception.TableNotFoundException;
import org.apache.hudi.storage.hadoop.HoodieHadoopStorage;

import org.apache.xtable.exception.PartitionSpecException;
import org.apache.xtable.exception.UpdateException;
Expand Down Expand Up @@ -72,6 +75,10 @@ public class HudiTableManager {
* @return {@link HoodieTableMetaClient} if table exists, otherwise null
*/
public Optional<HoodieTableMetaClient> loadTableMetaClientIfExists(String tableDataPath) {
if (!metaFolderExists(tableDataPath, configuration)) {
log.info("Hudi table does not exist, will be created on first sync");
return Optional.empty();
}
try {
return Optional.of(
HoodieTableMetaClient.builder()
Expand All @@ -85,6 +92,20 @@ public Optional<HoodieTableMetaClient> loadTableMetaClientIfExists(String tableD
}
}

/**
* Returns whether a Hudi table exists at the path, the same check Hudi's own writers make before
* loading a meta client. The meta client alone only reports a missing table after retrying the
* read of its properties file with one-second sleeps.
*/
public static boolean metaFolderExists(String tableDataPath, Configuration configuration) {
try {
return FSUtils.isTableExists(
tableDataPath, new HoodieHadoopStorage(tableDataPath, configuration));
} catch (IOException e) {
throw new UncheckedIOException("Failed to check for Hudi table at " + tableDataPath, e);
}
}

/**
* Initializes a Hudi table with properties matching the provided {@link InternalTable}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

import org.apache.xtable.conversion.ConversionSourceProvider;
import org.apache.xtable.conversion.SourceTable;
import org.apache.xtable.hudi.HudiTableManager;
import org.apache.xtable.model.metadata.TableSyncMetadata;
import org.apache.xtable.model.schema.InternalField;
import org.apache.xtable.model.schema.InternalSchema;
Expand Down Expand Up @@ -113,6 +114,9 @@ static void checkIndexedTable(String tableLocation, SourceTable table) {
}

static HoodieTableMetaClient getMetaClient(String dataPath, Configuration configuration) {
if (!HudiTableManager.metaFolderExists(dataPath, configuration)) {
throw new TableNotFoundException(dataPath);
}
HoodieStorage storage = new HoodieHadoopStorage(dataPath, configuration);
return HoodieTableMetaClient.builder().setStorage(storage).setBasePath(dataPath).build();
}
Expand Down