-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Core: Parsing and Writing Tests for V3 Metadata #11947
Open
HonahX
wants to merge
13
commits into
apache:main
Choose a base branch
from
HonahX:honahx_table_metadata_v3_parse_and_test_2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
063b7f5
Add row-lineage fields and next-row-id
HonahX 92c616b
remove unnecessary test
HonahX 74bc724
add unit tests for new fields
HonahX baf6e0b
add v3 test metadata json
HonahX 4786fbe
add tests for v3 row lineage parsing
HonahX 4d5c87d
Merge branch 'main' into honahx_table_metadata_v3_parse_and_test_2
HonahX 8f667de
Merge branch 'main' into honahx_table_metadata_v3_parse_and_test_2
HonahX 4f50370
Fix Compilation error
HonahX 2551587
remove fields for row lineage
HonahX 20c72d0
First try: Add Metadata Builder for tests
HonahX 4adb693
fix style issue
HonahX 32ffbfd
simplify construction of table metadata in tests
HonahX 4aa3158
Add BaseSnapshotBuilder
HonahX File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
336 changes: 336 additions & 0 deletions
336
core/src/test/java/org/apache/iceberg/MetadataTestUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,336 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.iceberg; | ||
|
||
import static org.apache.iceberg.TableMetadata.INITIAL_SEQUENCE_NUMBER; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
import org.apache.iceberg.relocated.com.google.common.base.Preconditions; | ||
import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList; | ||
import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap; | ||
import org.apache.iceberg.relocated.com.google.common.collect.Lists; | ||
import org.apache.iceberg.relocated.com.google.common.collect.Maps; | ||
import org.apache.iceberg.util.SerializableSupplier; | ||
|
||
public class MetadataTestUtils { | ||
|
||
private MetadataTestUtils() {} | ||
|
||
public static TableMetadataBuilder buildTestTableMetadata(int formatVersion) { | ||
return new TableMetadataBuilder(formatVersion); | ||
} | ||
|
||
public static class TableMetadataBuilder { | ||
private String metadataLocation; | ||
private int formatVersion; | ||
private String uuid; | ||
private String location; | ||
private long lastSequenceNumber; | ||
private Long lastUpdatedMillis; | ||
private int lastColumnId; | ||
private int currentSchemaId; | ||
private List<Schema> schemas; | ||
private int defaultSpecId; | ||
private List<PartitionSpec> specs; | ||
private int lastAssignedPartitionId; | ||
private int defaultSortOrderId; | ||
private List<SortOrder> sortOrders; | ||
private Map<String, String> properties; | ||
private long currentSnapshotId; | ||
private List<HistoryEntry> snapshotLog; | ||
private List<TableMetadata.MetadataLogEntry> previousFiles; | ||
private List<StatisticsFile> statisticsFiles; | ||
private List<PartitionStatisticsFile> partitionStatisticsFiles; | ||
private List<MetadataUpdate> changes; | ||
private SerializableSupplier<List<Snapshot>> snapshotsSupplier; | ||
private List<Snapshot> snapshots; | ||
private Map<String, SnapshotRef> refs; | ||
|
||
private TableMetadataBuilder(int formatVersion) { | ||
this.formatVersion = formatVersion; | ||
this.uuid = UUID.randomUUID().toString(); | ||
this.lastSequenceNumber = INITIAL_SEQUENCE_NUMBER; | ||
this.lastUpdatedMillis = System.currentTimeMillis(); | ||
this.lastColumnId = -1; | ||
this.currentSchemaId = -1; | ||
this.schemas = Lists.newArrayList(); | ||
this.defaultSpecId = -1; | ||
this.specs = Lists.newArrayList(); | ||
this.lastAssignedPartitionId = 999; | ||
this.defaultSortOrderId = -1; | ||
this.sortOrders = Lists.newArrayList(); | ||
this.properties = Maps.newHashMap(); | ||
this.snapshots = Lists.newArrayList(); | ||
this.currentSnapshotId = -1; | ||
this.changes = Lists.newArrayList(); | ||
this.snapshotLog = Lists.newArrayList(); | ||
this.previousFiles = Lists.newArrayList(); | ||
this.refs = Maps.newHashMap(); | ||
this.statisticsFiles = Lists.newArrayList(); | ||
this.partitionStatisticsFiles = Lists.newArrayList(); | ||
} | ||
|
||
public TableMetadataBuilder setMetadataLocation(String metadataFileLocation) { | ||
this.metadataLocation = metadataFileLocation; | ||
return this; | ||
} | ||
|
||
public TableMetadataBuilder setFormatVersion(int formatVersion) { | ||
this.formatVersion = formatVersion; | ||
return this; | ||
} | ||
|
||
public TableMetadataBuilder setUuid(String uuid) { | ||
this.uuid = uuid; | ||
return this; | ||
} | ||
|
||
public TableMetadataBuilder setLocation(String location) { | ||
this.location = location; | ||
return this; | ||
} | ||
|
||
public TableMetadataBuilder setLastSequenceNumber(long lastSequenceNumber) { | ||
this.lastSequenceNumber = lastSequenceNumber; | ||
return this; | ||
} | ||
|
||
public TableMetadataBuilder setLastUpdatedMillis(long lastUpdatedMillis) { | ||
this.lastUpdatedMillis = lastUpdatedMillis; | ||
return this; | ||
} | ||
|
||
public TableMetadataBuilder setLastColumnId(int lastColumnId) { | ||
this.lastColumnId = lastColumnId; | ||
return this; | ||
} | ||
|
||
public TableMetadataBuilder setCurrentSchemaId(int currentSchemaId) { | ||
this.currentSchemaId = currentSchemaId; | ||
return this; | ||
} | ||
|
||
public TableMetadataBuilder setSchemas(List<Schema> schemas) { | ||
this.schemas = schemas; | ||
return this; | ||
} | ||
|
||
public TableMetadataBuilder setDefaultSpecId(int defaultSpecId) { | ||
this.defaultSpecId = defaultSpecId; | ||
return this; | ||
} | ||
|
||
public TableMetadataBuilder setSpecs(List<PartitionSpec> specs) { | ||
this.specs = specs; | ||
return this; | ||
} | ||
|
||
public TableMetadataBuilder setLastAssignedPartitionId(int lastAssignedPartitionId) { | ||
this.lastAssignedPartitionId = lastAssignedPartitionId; | ||
return this; | ||
} | ||
|
||
public TableMetadataBuilder setDefaultSortOrderId(int defaultSortOrderId) { | ||
this.defaultSortOrderId = defaultSortOrderId; | ||
return this; | ||
} | ||
|
||
public TableMetadataBuilder setSortOrders(List<SortOrder> sortOrders) { | ||
this.sortOrders = sortOrders; | ||
return this; | ||
} | ||
|
||
public TableMetadataBuilder setProperties(Map<String, String> properties) { | ||
this.properties = properties; | ||
return this; | ||
} | ||
|
||
public TableMetadataBuilder setCurrentSnapshotId(long snapshotId) { | ||
this.currentSnapshotId = snapshotId; | ||
return this; | ||
} | ||
|
||
public TableMetadataBuilder setSnapshotsSupplier( | ||
SerializableSupplier<List<Snapshot>> snapshotsSupplier) { | ||
this.snapshotsSupplier = snapshotsSupplier; | ||
return this; | ||
} | ||
|
||
public TableMetadataBuilder setSnapshots(List<Snapshot> snapshots) { | ||
this.snapshots = snapshots; | ||
return this; | ||
} | ||
|
||
public TableMetadataBuilder setSnapshotLog(List<HistoryEntry> snapshotLog) { | ||
this.snapshotLog = snapshotLog; | ||
return this; | ||
} | ||
|
||
public TableMetadataBuilder setMetadataHistory( | ||
List<TableMetadata.MetadataLogEntry> metadataHistory) { | ||
this.previousFiles = metadataHistory; | ||
return this; | ||
} | ||
|
||
public TableMetadataBuilder setRefs(Map<String, SnapshotRef> refs) { | ||
this.refs = refs; | ||
return this; | ||
} | ||
|
||
public TableMetadataBuilder setChanges(List<MetadataUpdate> changes) { | ||
this.changes = changes; | ||
return this; | ||
} | ||
|
||
public TableMetadataBuilder setStatisticsFiles(List<StatisticsFile> statisticsFiles) { | ||
this.statisticsFiles = statisticsFiles; | ||
return this; | ||
} | ||
|
||
public TableMetadataBuilder setPartitionStatisticsFiles( | ||
List<PartitionStatisticsFile> partitionStatisticsFiles) { | ||
this.partitionStatisticsFiles = partitionStatisticsFiles; | ||
return this; | ||
} | ||
|
||
public TableMetadata build() { | ||
return new TableMetadata( | ||
metadataLocation, | ||
formatVersion, | ||
uuid, | ||
location, | ||
lastSequenceNumber, | ||
lastUpdatedMillis, | ||
lastColumnId, | ||
currentSchemaId, | ||
ImmutableList.copyOf(schemas), | ||
defaultSpecId, | ||
ImmutableList.copyOf(specs), | ||
lastAssignedPartitionId, | ||
defaultSortOrderId, | ||
ImmutableList.copyOf(sortOrders), | ||
ImmutableMap.copyOf(properties), | ||
currentSnapshotId, | ||
ImmutableList.copyOf(snapshots), | ||
snapshotsSupplier, | ||
ImmutableList.copyOf(snapshotLog), | ||
ImmutableList.copyOf(previousFiles), | ||
ImmutableMap.copyOf(refs), | ||
ImmutableList.copyOf(statisticsFiles), | ||
ImmutableList.copyOf(partitionStatisticsFiles), | ||
ImmutableList.copyOf(changes)); | ||
} | ||
} | ||
|
||
public static BaseSnapshotBuilder buildTestSnapshot() { | ||
return new BaseSnapshotBuilder(); | ||
} | ||
|
||
public static class BaseSnapshotBuilder { | ||
private long snapshotId; | ||
private Long parentId; | ||
private long sequenceNumber; | ||
private long timestampMillis; | ||
private String manifestListLocation; | ||
private String operation; | ||
private Map<String, String> summary; | ||
private Integer schemaId; | ||
private String[] v1ManifestLocations; | ||
|
||
private BaseSnapshotBuilder() { | ||
this.snapshotId = -1L; | ||
this.sequenceNumber = -1L; | ||
this.timestampMillis = System.currentTimeMillis(); | ||
this.summary = ImmutableMap.of(); | ||
} | ||
|
||
public BaseSnapshotBuilder setSnapshotId(long snapshotId) { | ||
this.snapshotId = snapshotId; | ||
return this; | ||
} | ||
|
||
public BaseSnapshotBuilder setParentId(Long parentId) { | ||
this.parentId = parentId; | ||
return this; | ||
} | ||
|
||
public BaseSnapshotBuilder setSequenceNumber(long sequenceNumber) { | ||
this.sequenceNumber = sequenceNumber; | ||
return this; | ||
} | ||
|
||
public BaseSnapshotBuilder setTimestampMillis(long timestampMillis) { | ||
this.timestampMillis = timestampMillis; | ||
return this; | ||
} | ||
|
||
public BaseSnapshotBuilder setManifestListLocation(String manifestListLocation) { | ||
this.manifestListLocation = manifestListLocation; | ||
return this; | ||
} | ||
|
||
public BaseSnapshotBuilder setOperation(String operation) { | ||
this.operation = operation; | ||
return this; | ||
} | ||
|
||
public BaseSnapshotBuilder setSummary(Map<String, String> summary) { | ||
this.summary = summary; | ||
return this; | ||
} | ||
|
||
public BaseSnapshotBuilder setSchemaId(Integer schemaId) { | ||
this.schemaId = schemaId; | ||
return this; | ||
} | ||
|
||
public BaseSnapshotBuilder setV1ManifestLocations(String[] v1ManifestLocations) { | ||
this.v1ManifestLocations = v1ManifestLocations; | ||
return this; | ||
} | ||
|
||
public Snapshot build() { | ||
Preconditions.checkArgument( | ||
manifestListLocation != null || v1ManifestLocations != null, | ||
"Cannot set both ManifestListLocation and V1ManifestLocations"); | ||
if (v1ManifestLocations != null) { | ||
return new BaseSnapshot( | ||
sequenceNumber, | ||
snapshotId, | ||
parentId, | ||
timestampMillis, | ||
operation, | ||
summary, | ||
schemaId, | ||
v1ManifestLocations); | ||
} | ||
return new BaseSnapshot( | ||
sequenceNumber, | ||
snapshotId, | ||
parentId, | ||
timestampMillis, | ||
operation, | ||
summary, | ||
schemaId, | ||
manifestListLocation); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added test-only builders for TableMetadata and BaseSnapshot. This shall reduce the amount of code changes in tests when adding new fields.
cc: @RussellSpitzer