Skip to content

Commit

Permalink
Refactor: fix old prefix in class names (apache#402)
Browse files Browse the repository at this point in the history
The change fixes name of classes with old product-specific prefix (One), either replaces "One"
with prefix "internal", as it more accurately reflects the class's function and distinguishes
the class from classes in table format packages, or removes "One" altogether from the class name.

The following class name changes are introduced:
. OneTable is now InternalTable
. OneTableErrorCode is now ErrorCode
. OneTableException is now InternalException
. OneParseException is now OneParseException
. OneFileGroup is now PartitionFileGroup
. OneTableMetadata is now TableSyncMetadata
  • Loading branch information
ashvina committed Mar 29, 2024
1 parent 8b7c368 commit 7968e50
Show file tree
Hide file tree
Showing 60 changed files with 416 additions and 390 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import lombok.Value;

import org.apache.xtable.model.schema.SchemaCatalog;
import org.apache.xtable.model.storage.OneFileGroup;
import org.apache.xtable.model.storage.PartitionFileGroup;

/**
* Snapshot represents the view of the table at a specific point in time. Snapshot captures all the
Expand All @@ -43,11 +43,11 @@ public class InternalSnapshot {
// The instant of the Snapshot
String version;
// Table reference
OneTable table;
InternalTable table;
// Schema catalog referencing the written schema for each data file in the snapshot
SchemaCatalog schemaCatalog;
// Data files grouped by partition
List<OneFileGroup> partitionedDataFiles;
List<PartitionFileGroup> partitionedDataFiles;
// pending commits before latest commit on the table.
@Builder.Default List<Instant> pendingCommits = Collections.emptyList();
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
*/
@Value
@Builder(toBuilder = true)
public class OneTable {
public class InternalTable {
// name of the table
String name;
// table format the table currently has data in
Expand Down
4 changes: 2 additions & 2 deletions api/src/main/java/org/apache/xtable/model/TableChange.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ public class TableChange {
// Change in files at the specified instant
DataFilesDiff filesDiff;

/** The {@link OneTable} at the commit time to which this table change belongs. */
OneTable tableAsOfChange;
/** The {@link InternalTable} at the commit time to which this table change belongs. */
InternalTable tableAsOfChange;
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@
import lombok.AllArgsConstructor;
import lombok.Value;

/**
* Metadata representing the state of a table sync process. This metadata is stored in the target
* table's properties and is used to track the status of previous sync operation.
*/
@AllArgsConstructor(staticName = "of")
@Value
public class OneTableMetadata {
public class TableSyncMetadata {
/**
* Property name for the lastInstantSynced field from SyncResult, used for persisting
* lastInstantSynced in the table metadata/properties
Expand All @@ -57,7 +61,7 @@ public Map<String, String> asMap() {
return map;
}

public static Optional<OneTableMetadata> fromMap(Map<String, String> properties) {
public static Optional<TableSyncMetadata> fromMap(Map<String, String> properties) {
if (properties != null) {
Instant lastInstantSynced = null;
List<Instant> instantsToConsiderForNextSync = null;
Expand All @@ -70,7 +74,7 @@ public static Optional<OneTableMetadata> fromMap(Map<String, String> properties)
properties.get(INFLIGHT_COMMITS_TO_CONSIDER_FOR_NEXT_SYNC_PROP));
}
return Optional.ofNullable(
OneTableMetadata.of(lastInstantSynced, instantsToConsiderForNextSync));
TableSyncMetadata.of(lastInstantSynced, instantsToConsiderForNextSync));
}
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@

package org.apache.xtable.model.exception;

public enum OneTableErrorCode {
import lombok.Getter;

@Getter
public enum ErrorCode {
INVALID_CONFIGURATION(10001),
INVALID_PARTITION_SPEC(10002),
INVALID_PARTITION_VALUE(10003),
Expand All @@ -30,11 +33,7 @@ public enum OneTableErrorCode {

private final int errorCode;

OneTableErrorCode(int errorCode) {
ErrorCode(int errorCode) {
this.errorCode = errorCode;
}

public int getErrorCode() {
return errorCode;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
import lombok.ToString;

@ToString
public class OneTableException extends RuntimeException {
private final OneTableErrorCode errorCode;
public class InternalException extends RuntimeException {
private final ErrorCode errorCode;

protected OneTableException(OneTableErrorCode errorCode, String message, Throwable e) {
protected InternalException(ErrorCode errorCode, String message, Throwable e) {
super(message, e);
this.errorCode = errorCode;
}

protected OneTableException(OneTableErrorCode errorCode, String message) {
protected InternalException(ErrorCode errorCode, String message) {
super(message);
this.errorCode = errorCode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@

package org.apache.xtable.model.exception;

public class OneParseException extends OneTableException {
public OneParseException(String message, Throwable e) {
super(OneTableErrorCode.PARSE_EXCEPTION, message, e);
/** Exception thrown when there is a parsing error, for e.g. parsing a date string. */
public class ParseException extends InternalException {
public ParseException(String message, Throwable e) {
super(ErrorCode.PARSE_EXCEPTION, message, e);
}

public OneParseException(String message) {
super(OneTableErrorCode.PARSE_EXCEPTION, message);
public ParseException(String message) {
super(ErrorCode.PARSE_EXCEPTION, message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public static <L, P> FilesDiff<L, P> findNewAndRemovedFiles(
* @return the set of files that are added
*/
public static <P> FilesDiff<InternalDataFile, P> findNewAndRemovedFiles(
List<OneFileGroup> latestFileGroups, Map<String, P> previousFiles) {
List<PartitionFileGroup> latestFileGroups, Map<String, P> previousFiles) {
Map<String, InternalDataFile> latestFiles =
latestFileGroups.stream()
.flatMap(group -> group.getFiles().stream())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@
/** Represents a grouping of {@link InternalDataFile} with the same partition values. */
@Value
@Builder
public class OneFileGroup {
public class PartitionFileGroup {
List<PartitionValue> partitionValues;
List<InternalDataFile> files;

public static List<OneFileGroup> fromFiles(List<InternalDataFile> files) {
public static List<PartitionFileGroup> fromFiles(List<InternalDataFile> files) {
return fromFiles(files.stream());
}

public static List<OneFileGroup> fromFiles(Stream<InternalDataFile> files) {
public static List<PartitionFileGroup> fromFiles(Stream<InternalDataFile> files) {
Map<List<PartitionValue>, List<InternalDataFile>> filesGrouped =
files.collect(Collectors.groupingBy(InternalDataFile::getPartitionValues));
return filesGrouped.entrySet().stream()
.map(
entry ->
OneFileGroup.builder()
PartitionFileGroup.builder()
.partitionValues(entry.getKey())
.files(entry.getValue())
.build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@

import java.util.Map;

import org.apache.xtable.model.OneTable;
import org.apache.xtable.model.InternalTable;
import org.apache.xtable.model.storage.TableFormat;

/**
* Interface to implement a validation checker. Runs the specified list of {@link ValidationCheck}
* on the {@link OneTable} using the specified {@link TableFormat}
* on the {@link InternalTable} using the specified {@link TableFormat}
*
* @since 0.1
*/
public interface ValidationChecker {
Map<ValidationCheck, ValidationResult> validate(
OneTable table, TableFormat tableFormat, ValidationCheck[] checks);
InternalTable table, TableFormat tableFormat, ValidationCheck[] checks);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.apache.xtable.model.CommitsBacklog;
import org.apache.xtable.model.InstantsForIncrementalSync;
import org.apache.xtable.model.InternalSnapshot;
import org.apache.xtable.model.OneTable;
import org.apache.xtable.model.InternalTable;
import org.apache.xtable.model.TableChange;
import org.apache.xtable.model.schema.SchemaCatalog;

Expand All @@ -35,12 +35,12 @@
*/
public interface SourceClient<COMMIT> extends Closeable {
/**
* Extracts the {@link OneTable} definition as of the provided commit.
* Extracts the {@link InternalTable} definition as of the provided commit.
*
* @param commit the commit to consider for reading the table state
* @return the table definition
*/
OneTable getTable(COMMIT commit);
InternalTable getTable(COMMIT commit);

/**
* Extracts the {@link SchemaCatalog} as of the provided instant.
Expand All @@ -49,7 +49,7 @@ public interface SourceClient<COMMIT> extends Closeable {
* @param commit the commit to consider for reading the schema catalog
* @return the schema catalog
*/
SchemaCatalog getSchemaCatalog(OneTable table, COMMIT commit);
SchemaCatalog getSchemaCatalog(InternalTable table, COMMIT commit);

/**
* Extracts the {@link InternalSnapshot} as of latest state.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@

package org.apache.xtable.spi.extractor;

import org.apache.xtable.model.OneTable;
import org.apache.xtable.model.InternalTable;

/**
* Extracts {@link OneTable} from given {@link CLIENT}.
* Extracts {@link InternalTable} from given {@link CLIENT}.
*
* @param <CLIENT> Extracts canonical table model from table client.
*/
public interface TableExtractor<CLIENT> {
OneTable table(CLIENT tableServiceClient);
InternalTable table(CLIENT tableServiceClient);
}
22 changes: 11 additions & 11 deletions api/src/main/java/org/apache/xtable/spi/sync/TableFormatSync.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@

import org.apache.xtable.model.IncrementalTableChanges;
import org.apache.xtable.model.InternalSnapshot;
import org.apache.xtable.model.OneTable;
import org.apache.xtable.model.OneTableMetadata;
import org.apache.xtable.model.InternalTable;
import org.apache.xtable.model.TableChange;
import org.apache.xtable.model.TableSyncMetadata;
import org.apache.xtable.model.sync.SyncMode;
import org.apache.xtable.model.sync.SyncResult;

/** Provides the functionality to sync from the OneTable format to the target format. */
/** Provides the functionality to sync from the InternalTable format to the target format. */
@Log4j2
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class TableFormatSync {
Expand All @@ -64,13 +64,13 @@ public Map<String, SyncResult> syncSnapshot(
Map<String, SyncResult> results = new HashMap<>();
for (TargetClient targetClient : targetClients) {
try {
OneTable oneTable = snapshot.getTable();
InternalTable internalTable = snapshot.getTable();
results.put(
targetClient.getTableFormat(),
getSyncResult(
targetClient,
SyncMode.FULL,
oneTable,
internalTable,
client -> client.syncFilesForSnapshot(snapshot.getPartitionedDataFiles()),
startTime,
snapshot.getPendingCommits()));
Expand All @@ -91,7 +91,7 @@ public Map<String, SyncResult> syncSnapshot(
* @return the results of trying to sync each change
*/
public Map<String, List<SyncResult>> syncChanges(
Map<TargetClient, OneTableMetadata> targetClientWithMetadata,
Map<TargetClient, TableSyncMetadata> targetClientWithMetadata,
IncrementalTableChanges changes) {
Map<String, List<SyncResult>> results = new HashMap<>();
Set<TargetClient> clientsWithFailures = new HashSet<>();
Expand All @@ -101,7 +101,7 @@ public Map<String, List<SyncResult>> syncChanges(
targetClientWithMetadata.entrySet().stream()
.filter(
entry -> {
OneTableMetadata metadata = entry.getValue();
TableSyncMetadata metadata = entry.getValue();
return isChangeApplicableForLastSyncMetadata(change, metadata);
})
.map(Map.Entry::getKey)
Expand Down Expand Up @@ -133,7 +133,7 @@ public Map<String, List<SyncResult>> syncChanges(
}

private static boolean isChangeApplicableForLastSyncMetadata(
TableChange change, OneTableMetadata metadata) {
TableChange change, TableSyncMetadata metadata) {
return change
.getTableAsOfChange()
.getLatestCommitTime()
Expand All @@ -146,7 +146,7 @@ private static boolean isChangeApplicableForLastSyncMetadata(
private SyncResult getSyncResult(
TargetClient client,
SyncMode mode,
OneTable tableState,
InternalTable tableState,
SyncFiles fileSyncMethod,
Instant startTime,
List<Instant> pendingCommits) {
Expand All @@ -159,8 +159,8 @@ private SyncResult getSyncResult(
// Update the files in the target table
fileSyncMethod.sync(client);
// Persist the latest commit time in table properties for incremental syncs.
OneTableMetadata latestState =
OneTableMetadata.of(tableState.getLatestCommitTime(), pendingCommits);
TableSyncMetadata latestState =
TableSyncMetadata.of(tableState.getLatestCommitTime(), pendingCommits);
client.syncMetadata(latestState);
client.completeSync();

Expand Down
16 changes: 8 additions & 8 deletions api/src/main/java/org/apache/xtable/spi/sync/TargetClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
import org.apache.hadoop.conf.Configuration;

import org.apache.xtable.client.PerTableConfig;
import org.apache.xtable.model.OneTable;
import org.apache.xtable.model.OneTableMetadata;
import org.apache.xtable.model.InternalTable;
import org.apache.xtable.model.TableSyncMetadata;
import org.apache.xtable.model.schema.InternalPartitionField;
import org.apache.xtable.model.schema.InternalSchema;
import org.apache.xtable.model.storage.DataFilesDiff;
import org.apache.xtable.model.storage.OneFileGroup;
import org.apache.xtable.model.storage.PartitionFileGroup;

/** A client that provides the major functionality for syncing changes to a target system. */
public interface TargetClient {
Expand All @@ -49,20 +49,20 @@ public interface TargetClient {
void syncPartitionSpec(List<InternalPartitionField> partitionSpec);

/**
* Syncs the {@link OneTableMetadata} to the target for tracking metadata between runs. This is
* Syncs the {@link TableSyncMetadata} to the target for tracking metadata between runs. This is
* required for incremental sync.
*
* @param metadata the current metadata
*/
void syncMetadata(OneTableMetadata metadata);
void syncMetadata(TableSyncMetadata metadata);

/**
* Syncs the provided snapshot files to the target system. This method is required to both add and
* remove files.
*
* @param partitionedDataFiles the files to sync, grouped by partition
*/
void syncFilesForSnapshot(List<OneFileGroup> partitionedDataFiles);
void syncFilesForSnapshot(List<PartitionFileGroup> partitionedDataFiles);

/**
* Syncs the changes in files to the target system. This method is required to both add and remove
Expand All @@ -77,13 +77,13 @@ public interface TargetClient {
*
* @param table the table that will be synced
*/
void beginSync(OneTable table);
void beginSync(InternalTable table);

/** Completes the sync and performs any cleanup required. */
void completeSync();

/** Returns the onetable metadata persisted in the target */
Optional<OneTableMetadata> getTableMetadata();
Optional<TableSyncMetadata> getTableMetadata();

/** Returns the TableFormat name the client syncs to */
String getTableFormat();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ void findDiffFromFileGroups() {
InternalDataFile file1Group2 = InternalDataFile.builder().physicalPath("file1Group2").build();
InternalDataFile file2Group2 = InternalDataFile.builder().physicalPath("file2Group2").build();

List<OneFileGroup> latestFileGroups =
OneFileGroup.fromFiles(Arrays.asList(file1Group1, file2Group1, file1Group2, file2Group2));
List<PartitionFileGroup> latestFileGroups =
PartitionFileGroup.fromFiles(
Arrays.asList(file1Group1, file2Group1, file1Group2, file2Group2));

Map<String, File> previousFiles = new HashMap<>();
File file1 = mock(File.class);
Expand Down
Loading

0 comments on commit 7968e50

Please sign in to comment.