diff --git a/plugin/trino-hudi/src/main/java/io/trino/plugin/hudi/HudiMetadata.java b/plugin/trino-hudi/src/main/java/io/trino/plugin/hudi/HudiMetadata.java index f86182de78ad3..97b94cb8c93b2 100644 --- a/plugin/trino-hudi/src/main/java/io/trino/plugin/hudi/HudiMetadata.java +++ b/plugin/trino-hudi/src/main/java/io/trino/plugin/hudi/HudiMetadata.java @@ -143,23 +143,23 @@ public Optional getSystemTable(ConnectorSession session, SchemaTabl private Optional getRawSystemTable(SchemaTableName tableName, ConnectorSession session) { HudiTableName name = HudiTableName.from(tableName.getTableName()); - if (name.getTableType() == TableType.DATA) { + if (name.tableType() == TableType.DATA) { return Optional.empty(); } - Optional tableOptional = metastore.getTable(tableName.getSchemaName(), name.getTableName()); + Optional
tableOptional = metastore.getTable(tableName.getSchemaName(), name.tableName()); if (tableOptional.isEmpty()) { return Optional.empty(); } if (!isHudiTable(tableOptional.get())) { return Optional.empty(); } - return switch (name.getTableType()) { + return switch (name.tableType()) { case DATA -> // TODO (https://github.com/trinodb/trino/issues/17973) remove DATA table type Optional.empty(); case TIMELINE -> { - SchemaTableName systemTableName = new SchemaTableName(tableName.getSchemaName(), name.getTableNameWithType()); + SchemaTableName systemTableName = new SchemaTableName(tableName.getSchemaName(), name.tableNameWithType()); yield Optional.of(new TimelineTable(fileSystemFactory.create(session), systemTableName, tableOptional.get())); } }; @@ -228,9 +228,10 @@ public ColumnMetadata getColumnMetadata(ConnectorSession session, ConnectorTable } @Override - public Optional getInfo(ConnectorTableHandle table) + public Optional getInfo(ConnectorTableHandle tableHandle) { - return Optional.of(HudiTableInfo.from((HudiTableHandle) table)); + HudiTableHandle table = (HudiTableHandle) tableHandle; + return Optional.of(new HudiTableInfo(table.getSchemaTableName(), table.getTableType().name(), table.getBasePath())); } @Override diff --git a/plugin/trino-hudi/src/main/java/io/trino/plugin/hudi/HudiTableInfo.java b/plugin/trino-hudi/src/main/java/io/trino/plugin/hudi/HudiTableInfo.java index cdffb35b59a52..1a7d6984e16f8 100644 --- a/plugin/trino-hudi/src/main/java/io/trino/plugin/hudi/HudiTableInfo.java +++ b/plugin/trino-hudi/src/main/java/io/trino/plugin/hudi/HudiTableInfo.java @@ -13,53 +13,16 @@ */ package io.trino.plugin.hudi; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; import io.trino.spi.connector.SchemaTableName; import static java.util.Objects.requireNonNull; -public class HudiTableInfo +public record HudiTableInfo(SchemaTableName table, String tableType, String basePath) { - private final SchemaTableName table; - private final String tableType; - private final String basePath; - - @JsonCreator - public HudiTableInfo( - @JsonProperty("table") SchemaTableName table, - @JsonProperty("tableType") String tableType, - @JsonProperty("basePath") String basePath) - { - this.table = requireNonNull(table, "table is null"); - this.tableType = requireNonNull(tableType, "tableType is null"); - this.basePath = requireNonNull(basePath, "basePath is null"); - } - - @JsonProperty - public SchemaTableName getTable() - { - return table; - } - - @JsonProperty - public String getTableType() - { - return tableType; - } - - @JsonProperty - public String getBasePath() - { - return basePath; - } - - public static HudiTableInfo from(HudiTableHandle tableHandle) + public HudiTableInfo { - requireNonNull(tableHandle, "tableHandle is null"); - return new HudiTableInfo( - tableHandle.getSchemaTableName(), - tableHandle.getTableType().name(), - tableHandle.getBasePath()); + requireNonNull(table, "table is null"); + requireNonNull(tableType, "tableType is null"); + requireNonNull(basePath, "basePath is null"); } } diff --git a/plugin/trino-hudi/src/main/java/io/trino/plugin/hudi/HudiTableName.java b/plugin/trino-hudi/src/main/java/io/trino/plugin/hudi/HudiTableName.java index e996b12c3a4ae..84d9dfe690546 100644 --- a/plugin/trino-hudi/src/main/java/io/trino/plugin/hudi/HudiTableName.java +++ b/plugin/trino-hudi/src/main/java/io/trino/plugin/hudi/HudiTableName.java @@ -23,32 +23,19 @@ import static java.util.Locale.ENGLISH; import static java.util.Objects.requireNonNull; -public class HudiTableName +public record HudiTableName(String tableName, TableType tableType) { private static final Pattern TABLE_PATTERN = Pattern.compile("" + "(?
[^$@]+)" + "(?:\\$(?[^@]+))?"); - private final String tableName; - private final TableType tableType; - public HudiTableName(String tableName, TableType tableType) { this.tableName = requireNonNull(tableName, "tableName is null"); this.tableType = requireNonNull(tableType, "tableType is null"); } - public String getTableName() - { - return tableName; - } - - public TableType getTableType() - { - return tableType; - } - - public String getTableNameWithType() + public String tableNameWithType() { return tableName + "$" + tableType.name().toLowerCase(ENGLISH); } @@ -56,7 +43,7 @@ public String getTableNameWithType() @Override public String toString() { - return getTableNameWithType(); + return tableNameWithType(); } public static HudiTableName from(String name) diff --git a/plugin/trino-hudi/src/main/java/io/trino/plugin/hudi/TableType.java b/plugin/trino-hudi/src/main/java/io/trino/plugin/hudi/TableType.java index 676d8b738c41b..2a8238c77f87b 100644 --- a/plugin/trino-hudi/src/main/java/io/trino/plugin/hudi/TableType.java +++ b/plugin/trino-hudi/src/main/java/io/trino/plugin/hudi/TableType.java @@ -16,5 +16,5 @@ public enum TableType { DATA, - TIMELINE; + TIMELINE } diff --git a/plugin/trino-hudi/src/main/java/io/trino/plugin/hudi/compaction/CompactionOperation.java b/plugin/trino-hudi/src/main/java/io/trino/plugin/hudi/compaction/CompactionOperation.java index 7ad99809fce69..87a29c9d565be 100644 --- a/plugin/trino-hudi/src/main/java/io/trino/plugin/hudi/compaction/CompactionOperation.java +++ b/plugin/trino-hudi/src/main/java/io/trino/plugin/hudi/compaction/CompactionOperation.java @@ -54,14 +54,9 @@ public CompactionOperation( this.bootstrapFilePath = requireNonNull(bootstrapFilePath, "bootstrapFilePath is null"); } - public String getFileId() - { - return id.getFileId(); - } - public String getPartitionPath() { - return id.getPartitionPath(); + return id.partitionPath(); } public HudiFileGroupId getFileGroupId() diff --git a/plugin/trino-hudi/src/main/java/io/trino/plugin/hudi/files/FileSlice.java b/plugin/trino-hudi/src/main/java/io/trino/plugin/hudi/files/FileSlice.java index 3956bd2f6064f..d40d01612d4c4 100644 --- a/plugin/trino-hudi/src/main/java/io/trino/plugin/hudi/files/FileSlice.java +++ b/plugin/trino-hudi/src/main/java/io/trino/plugin/hudi/files/FileSlice.java @@ -54,11 +54,6 @@ public Optional getBaseFile() return baseFile; } - public boolean isEmpty() - { - return (baseFile == null) && logFiles.isEmpty(); - } - @Override public String toString() { diff --git a/plugin/trino-hudi/src/main/java/io/trino/plugin/hudi/files/HudiFileGroup.java b/plugin/trino-hudi/src/main/java/io/trino/plugin/hudi/files/HudiFileGroup.java index 23d4eb2e3ac49..37e25f333a723 100644 --- a/plugin/trino-hudi/src/main/java/io/trino/plugin/hudi/files/HudiFileGroup.java +++ b/plugin/trino-hudi/src/main/java/io/trino/plugin/hudi/files/HudiFileGroup.java @@ -79,7 +79,7 @@ public void addLogFile(HudiLogFile logFile) public String getPartitionPath() { - return fileGroupId.getPartitionPath(); + return fileGroupId.partitionPath(); } public HudiFileGroupId getFileGroupId() diff --git a/plugin/trino-hudi/src/main/java/io/trino/plugin/hudi/files/HudiFileGroupId.java b/plugin/trino-hudi/src/main/java/io/trino/plugin/hudi/files/HudiFileGroupId.java index 2470b3093fd35..e978bf53280d9 100644 --- a/plugin/trino-hudi/src/main/java/io/trino/plugin/hudi/files/HudiFileGroupId.java +++ b/plugin/trino-hudi/src/main/java/io/trino/plugin/hudi/files/HudiFileGroupId.java @@ -13,50 +13,15 @@ */ package io.trino.plugin.hudi.files; -import java.util.Objects; - import static java.util.Objects.requireNonNull; -public class HudiFileGroupId +public record HudiFileGroupId(String partitionPath, String fileId) implements Comparable { - private final String partitionPath; - - private final String fileId; - - public HudiFileGroupId(String partitionPath, String fileId) - { - this.partitionPath = requireNonNull(partitionPath, "partitionPath is null"); - this.fileId = requireNonNull(fileId, "partitionPath is null"); - } - - public String getPartitionPath() - { - return partitionPath; - } - - public String getFileId() - { - return fileId; - } - - @Override - public boolean equals(Object o) - { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - HudiFileGroupId that = (HudiFileGroupId) o; - return Objects.equals(partitionPath, that.partitionPath) && Objects.equals(fileId, that.fileId); - } - - @Override - public int hashCode() + public HudiFileGroupId { - return Objects.hash(partitionPath, fileId); + requireNonNull(partitionPath, "partitionPath is null"); + requireNonNull(fileId, "partitionPath is null"); } @Override diff --git a/plugin/trino-hudi/src/main/java/io/trino/plugin/hudi/model/HudiInstant.java b/plugin/trino-hudi/src/main/java/io/trino/plugin/hudi/model/HudiInstant.java index ea496d011d63d..126fe3001c347 100644 --- a/plugin/trino-hudi/src/main/java/io/trino/plugin/hudi/model/HudiInstant.java +++ b/plugin/trino-hudi/src/main/java/io/trino/plugin/hudi/model/HudiInstant.java @@ -132,52 +132,50 @@ public String getFileName() : isRequested() ? HudiTimeline.makeRequestedCommitFileName(timestamp) : HudiTimeline.makeCommitFileName(timestamp); } - else if (HudiTimeline.CLEAN_ACTION.equals(action)) { + if (HudiTimeline.CLEAN_ACTION.equals(action)) { return isInflight() ? HudiTimeline.makeInflightCleanerFileName(timestamp) : isRequested() ? HudiTimeline.makeRequestedCleanerFileName(timestamp) : HudiTimeline.makeCleanerFileName(timestamp); } - else if (HudiTimeline.ROLLBACK_ACTION.equals(action)) { + if (HudiTimeline.ROLLBACK_ACTION.equals(action)) { return isInflight() ? HudiTimeline.makeInflightRollbackFileName(timestamp) : isRequested() ? HudiTimeline.makeRequestedRollbackFileName(timestamp) : HudiTimeline.makeRollbackFileName(timestamp); } - else if (HudiTimeline.SAVEPOINT_ACTION.equals(action)) { + if (HudiTimeline.SAVEPOINT_ACTION.equals(action)) { return isInflight() ? HudiTimeline.makeInflightSavePointFileName(timestamp) : HudiTimeline.makeSavePointFileName(timestamp); } - else if (HudiTimeline.DELTA_COMMIT_ACTION.equals(action)) { + if (HudiTimeline.DELTA_COMMIT_ACTION.equals(action)) { return isInflight() ? HudiTimeline.makeInflightDeltaFileName(timestamp) : isRequested() ? HudiTimeline.makeRequestedDeltaFileName(timestamp) : HudiTimeline.makeDeltaFileName(timestamp); } - else if (HudiTimeline.COMPACTION_ACTION.equals(action)) { + if (HudiTimeline.COMPACTION_ACTION.equals(action)) { if (isInflight()) { return HudiTimeline.makeInflightCompactionFileName(timestamp); } - else if (isRequested()) { + if (isRequested()) { return HudiTimeline.makeRequestedCompactionFileName(timestamp); } - else { - return HudiTimeline.makeCommitFileName(timestamp); - } + return HudiTimeline.makeCommitFileName(timestamp); } - else if (HudiTimeline.RESTORE_ACTION.equals(action)) { + if (HudiTimeline.RESTORE_ACTION.equals(action)) { return isInflight() ? HudiTimeline.makeInflightRestoreFileName(timestamp) : isRequested() ? HudiTimeline.makeRequestedRestoreFileName(timestamp) : HudiTimeline.makeRestoreFileName(timestamp); } - else if (HudiTimeline.REPLACE_COMMIT_ACTION.equals(action)) { + if (HudiTimeline.REPLACE_COMMIT_ACTION.equals(action)) { return isInflight() ? HudiTimeline.makeInflightReplaceFileName(timestamp) : isRequested() ? HudiTimeline.makeRequestedReplaceFileName(timestamp) : HudiTimeline.makeReplaceFileName(timestamp); } - else if (HudiTimeline.INDEXING_ACTION.equals(action)) { + if (HudiTimeline.INDEXING_ACTION.equals(action)) { return isInflight() ? HudiTimeline.makeInflightIndexFileName(timestamp) : isRequested() ? HudiTimeline.makeRequestedIndexFileName(timestamp) : HudiTimeline.makeIndexCommitFileName(timestamp); } - else if (HudiTimeline.SCHEMA_COMMIT_ACTION.equals(action)) { + if (HudiTimeline.SCHEMA_COMMIT_ACTION.equals(action)) { return isInflight() ? HudiTimeline.makeInflightSchemaFileName(timestamp) : isRequested() ? HudiTimeline.makeRequestSchemaFileName(timestamp) : HudiTimeline.makeSchemaFileName(timestamp); diff --git a/plugin/trino-hudi/src/main/java/io/trino/plugin/hudi/timeline/TimelineLayoutVersion.java b/plugin/trino-hudi/src/main/java/io/trino/plugin/hudi/timeline/TimelineLayoutVersion.java index a6e95dd87c496..6a71d20139916 100644 --- a/plugin/trino-hudi/src/main/java/io/trino/plugin/hudi/timeline/TimelineLayoutVersion.java +++ b/plugin/trino-hudi/src/main/java/io/trino/plugin/hudi/timeline/TimelineLayoutVersion.java @@ -13,11 +13,9 @@ */ package io.trino.plugin.hudi.timeline; -import java.util.Objects; - import static com.google.common.base.Preconditions.checkArgument; -public class TimelineLayoutVersion +public record TimelineLayoutVersion(Integer version) implements Comparable { public static final Integer VERSION_0 = 0; // pre 0.5.1 version format @@ -26,37 +24,10 @@ public class TimelineLayoutVersion private static final Integer CURRENT_VERSION = VERSION_1; public static final TimelineLayoutVersion CURRENT_LAYOUT_VERSION = new TimelineLayoutVersion(CURRENT_VERSION); - private final Integer version; - - public TimelineLayoutVersion(Integer version) + public TimelineLayoutVersion { checkArgument(version <= CURRENT_VERSION); checkArgument(version >= VERSION_0); - this.version = version; - } - - public Integer getVersion() - { - return version; - } - - @Override - public boolean equals(Object o) - { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - TimelineLayoutVersion that = (TimelineLayoutVersion) o; - return Objects.equals(version, that.version); - } - - @Override - public int hashCode() - { - return Objects.hash(version); } @Override