Skip to content

Commit

Permalink
[HUDI-8666] Revisit error message when timeline layout version cannot…
Browse files Browse the repository at this point in the history
… be read
  • Loading branch information
Vova Kolmakov committed Feb 21, 2025
1 parent 3b205d1 commit 519ef99
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public class HoodieTableConfig extends HoodieConfig {
public static final ConfigProperty<String> TIMELINE_LAYOUT_VERSION = ConfigProperty
.key("hoodie.timeline.layout.version")
.noDefaultValue()
.withDocumentation("Version of timeline used, by the table.");
.withDocumentation("Version of timeline used by the table.");

public static final ConfigProperty<RecordMergeMode> RECORD_MERGE_MODE = ConfigProperty
.key("hoodie.record.merge.mode")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import org.apache.hudi.common.util.collection.Triple;
import org.apache.hudi.exception.HoodieException;
import org.apache.hudi.exception.HoodieIOException;
import org.apache.hudi.exception.InvalidTableException;
import org.apache.hudi.exception.TableNotFoundException;
import org.apache.hudi.keygen.constant.KeyGeneratorType;
import org.apache.hudi.metadata.HoodieTableMetadata;
Expand Down Expand Up @@ -181,7 +182,7 @@ protected HoodieTableMetaClient(HoodieStorage storage, String basePath, boolean
"Layout Version defined in hoodie properties has higher version (" + tableConfigVersion.get()
+ ") than the one passed in config (" + layoutVersion.get() + ")");
} else if (layoutVersion.isEmpty() && tableConfigVersion.isEmpty()) {
throw new TableNotFoundException("Table does not exist");
throw new InvalidTableException(basePath, "timeline layout version is not set");
}
this.timelineLayoutVersion = layoutVersion.orElseGet(tableConfigVersion::get);
this.timelineLayout = TimelineLayout.fromVersion(timelineLayoutVersion);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,9 @@ private Option<Schema> getTableParquetSchemaFromDataFile() {
return Option.empty();
}
default:
LOG.error("Unknown table type {}", metaClient.getTableType());
throw new InvalidTableException(metaClient.getBasePath().toString());
String errMsg = String.format("Unknown table type %s", metaClient.getTableType());
LOG.error(errMsg);
throw new InvalidTableException(metaClient.getBasePath().toString(), errMsg);
}
} catch (IOException e) {
throw new HoodieException("Failed to read data schema", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,20 @@

package org.apache.hudi.exception;

import org.apache.hudi.common.util.StringUtils;

/**
* Exception thrown to indicate that a hoodie table is invalid.
*/
public class InvalidTableException extends HoodieException {

public InvalidTableException(String basePath) {
super(getErrorMessage(basePath));
public InvalidTableException(String basePath, String error) {
super(buildErrorMessage(basePath, error));
}

private static String getErrorMessage(String basePath) {
return "Invalid Hoodie Table. " + basePath;
private static String buildErrorMessage(String basePath, String error) {
return StringUtils.isNullOrEmpty(error)
? "Invalid Hoodie Table: " + basePath
: "Invalid Hoodie Table (" + error + "): " + basePath;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,17 @@ private void initTableNameVars(HiveSyncConfig config) {
: Option.of(tableName + SUFFIX_READ_OPTIMIZED_TABLE);
break;
default:
LOG.error("Unknown table type " + syncClient.getTableType());
throw new InvalidTableException(syncClient.getBasePath());
throwInvalidTableTypeException();
}
}
}

private void throwInvalidTableTypeException() {
String errMsg = String.format("Unknown table type %s", syncClient.getTableType());
LOG.error(errMsg);
throw new InvalidTableException(syncClient.getBasePath(), errMsg);
}

@Override
public void syncHoodieTable() {
try {
Expand Down Expand Up @@ -210,8 +215,7 @@ protected void doSync() {
}
break;
default:
LOG.error("Unknown table type " + syncClient.getTableType());
throw new InvalidTableException(syncClient.getBasePath());
throwInvalidTableTypeException();
}
}

Expand Down

0 comments on commit 519ef99

Please sign in to comment.