-
Notifications
You must be signed in to change notification settings - Fork 1k
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
[iceberg] Introduce feature to migrate table from iceberg to paimon #4639
Open
LsomeYeah
wants to merge
27
commits into
apache:master
Choose a base branch
from
LsomeYeah:migrate-iceberg
base: master
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
27 commits
Select commit
Hold shift + click to select a range
a7601c6
first version
LsomeYeah 7aef9fe
[iceberg] inherit seq num from manifest file when seq num is null in …
LsomeYeah 88cd737
[iceberg] change the type of snapshotId to long
LsomeYeah 0679c3c
support more data types
LsomeYeah 021a407
second version and test
LsomeYeah 4ee8126
fix bug for type conversion
LsomeYeah 1eb789b
add unit tests
LsomeYeah f3a9d5b
[mark] unit tests including add and rename column
LsomeYeah 4bf44e9
fix test
LsomeYeah eaf0efe
add doc and add dependency in paimon-core/pom.xml
LsomeYeah ff8db0a
resolve conflicts
LsomeYeah 1dd7925
fix check style
LsomeYeah 625b67b
[improve] get iceberg metadata from iceberg table instead from a cert…
LsomeYeah 98a4ec3
[improve] get iceberg metadata from IcebergMigrateMetadataFactory ins…
LsomeYeah 6f2fef8
[improve] allow migrate to existing database
LsomeYeah a6fdc51
[improve][core] get datatype directly if datatype in IcebergDataField…
LsomeYeah 0c0bb89
[core] change scope for iceberg dependency in paimon-core to test
LsomeYeah f73ecb5
[improve][core] remove ignore-delete conf
LsomeYeah a11769f
[core] store the iceberg field datatype when computing over
LsomeYeah 92e283a
[core] remove construct to IcebergMigrator and use Preconditions inst…
LsomeYeah ab74c4a
[core] add deleteOriginTable in IcebergMigrateMetadata and implement …
LsomeYeah 0fd196f
[core] implement 'renameTable' again for a independent commit
LsomeYeah 67ee959
[core][test] add a test which using random data
LsomeYeah 3911175
[core][hive] remove contents about iceberg hive-catalog which will be…
LsomeYeah ffe2a02
[core] throwing exception and logging better. optimize code about get…
LsomeYeah 41ded21
[core] implement rename table
LsomeYeah 1f74505
[core][fix] avoid json serializer using wrong getters
LsomeYeah 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
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
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
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
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 |
---|---|---|
|
@@ -20,13 +20,22 @@ | |
|
||
import org.apache.paimon.table.SpecialFields; | ||
import org.apache.paimon.types.ArrayType; | ||
import org.apache.paimon.types.BigIntType; | ||
import org.apache.paimon.types.BinaryType; | ||
import org.apache.paimon.types.BooleanType; | ||
import org.apache.paimon.types.DataField; | ||
import org.apache.paimon.types.DataType; | ||
import org.apache.paimon.types.DateType; | ||
import org.apache.paimon.types.DecimalType; | ||
import org.apache.paimon.types.DoubleType; | ||
import org.apache.paimon.types.FloatType; | ||
import org.apache.paimon.types.IntType; | ||
import org.apache.paimon.types.LocalZonedTimestampType; | ||
import org.apache.paimon.types.MapType; | ||
import org.apache.paimon.types.RowType; | ||
import org.apache.paimon.types.TimestampType; | ||
import org.apache.paimon.types.VarBinaryType; | ||
import org.apache.paimon.types.VarCharType; | ||
import org.apache.paimon.utils.Preconditions; | ||
|
||
import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonCreator; | ||
|
@@ -64,7 +73,7 @@ public class IcebergDataField { | |
@JsonProperty(FIELD_TYPE) | ||
private final Object type; | ||
|
||
@JsonIgnore private final DataType dataType; | ||
@JsonIgnore private DataType dataType; | ||
|
||
@JsonProperty(FIELD_DOC) | ||
private final String doc; | ||
|
@@ -190,6 +199,80 @@ private static Object toTypeObject(DataType dataType, int fieldId, int depth) { | |
} | ||
} | ||
|
||
@JsonIgnore | ||
public DataType getDataType() { | ||
if (dataType != null) { | ||
return dataType; | ||
} | ||
dataType = getDataTypeFromType(); | ||
return dataType(); | ||
} | ||
|
||
@JsonIgnore | ||
public DataType getDataTypeFromType() { | ||
String simpleType = type.toString(); | ||
String delimiter = "("; | ||
if (simpleType.contains("[")) { | ||
delimiter = "["; | ||
} | ||
String typePrefix = | ||
!simpleType.contains(delimiter) | ||
? simpleType | ||
: simpleType.substring(0, simpleType.indexOf(delimiter)); | ||
switch (typePrefix) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that you have calculated |
||
case "boolean": | ||
return new BooleanType(!required); | ||
case "int": | ||
return new IntType(!required); | ||
case "long": | ||
return new BigIntType(!required); | ||
case "float": | ||
return new FloatType(!required); | ||
case "double": | ||
return new DoubleType(!required); | ||
case "date": | ||
return new DateType(!required); | ||
case "string": | ||
return new VarCharType(!required, VarCharType.MAX_LENGTH); | ||
case "binary": | ||
return new VarBinaryType(!required, VarBinaryType.MAX_LENGTH); | ||
case "fixed": | ||
int fixedLength = | ||
Integer.parseInt( | ||
simpleType.substring( | ||
simpleType.indexOf("[") + 1, simpleType.indexOf("]"))); | ||
return new BinaryType(!required, fixedLength); | ||
case "uuid": | ||
// https://iceberg.apache.org/spec/?h=vector#primitive-types | ||
// uuid should use 16-byte fixed | ||
return new BinaryType(!required, 16); | ||
case "decimal": | ||
int precision = | ||
Integer.parseInt( | ||
simpleType.substring( | ||
simpleType.indexOf("(") + 1, simpleType.indexOf(","))); | ||
int scale = | ||
Integer.parseInt( | ||
simpleType.substring( | ||
simpleType.indexOf(",") + 2, simpleType.indexOf(")"))); | ||
return new DecimalType(!required, precision, scale); | ||
case "timestamp": | ||
return new TimestampType(!required, 6); | ||
case "timestamptz": | ||
return new LocalZonedTimestampType(!required, 6); | ||
case "timestamp_ns": // iceberg v3 format | ||
return new TimestampType(!required, 9); | ||
case "timestamptz_ns": // iceberg v3 format | ||
return new LocalZonedTimestampType(!required, 9); | ||
default: | ||
throw new UnsupportedOperationException("Unsupported data type: " + type); | ||
} | ||
} | ||
|
||
public DataField toDatafield() { | ||
return new DataField(id, name, getDataType(), doc); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(id, name, required, type, doc); | ||
|
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
110 changes: 110 additions & 0 deletions
110
...on-core/src/main/java/org/apache/paimon/iceberg/migrate/IcebergMigrateHadoopMetadata.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,110 @@ | ||
/* | ||
* 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.paimon.iceberg.migrate; | ||
|
||
import org.apache.paimon.catalog.Identifier; | ||
import org.apache.paimon.fs.FileIO; | ||
import org.apache.paimon.fs.Path; | ||
import org.apache.paimon.iceberg.IcebergPathFactory; | ||
import org.apache.paimon.iceberg.metadata.IcebergMetadata; | ||
import org.apache.paimon.options.Options; | ||
import org.apache.paimon.utils.Preconditions; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.IOException; | ||
|
||
/** Get iceberg table latest snapshot metadata in hadoop. */ | ||
public class IcebergMigrateHadoopMetadata implements IcebergMigrateMetadata { | ||
private static final Logger LOG = LoggerFactory.getLogger(IcebergMigrateHadoopMetadata.class); | ||
|
||
private static final String VERSION_HINT_FILENAME = "version-hint.text"; | ||
private static final String ICEBERG_WAREHOUSE = "iceberg_warehouse"; | ||
|
||
private final FileIO fileIO; | ||
private final Identifier icebergIdentifier; | ||
private final Options icebergOptions; | ||
|
||
private Path icebergLatestMetaVersionPath; | ||
private IcebergPathFactory icebergMetaPathFactory; | ||
|
||
public IcebergMigrateHadoopMetadata( | ||
Identifier icebergIdentifier, FileIO fileIO, Options icebergOptions) { | ||
this.fileIO = fileIO; | ||
this.icebergIdentifier = icebergIdentifier; | ||
this.icebergOptions = icebergOptions; | ||
} | ||
|
||
@Override | ||
public IcebergMetadata icebergMetadata() { | ||
Preconditions.checkArgument( | ||
icebergOptions.get(ICEBERG_WAREHOUSE) != null, | ||
"'iceberg_warehouse' is null. " | ||
+ "In hadoop-catalog, you should explicitly set this argument for finding iceberg metadata."); | ||
this.icebergMetaPathFactory = | ||
new IcebergPathFactory( | ||
new Path( | ||
icebergOptions.get(ICEBERG_WAREHOUSE), | ||
new Path( | ||
String.format( | ||
"%s/%s/metadata", | ||
icebergIdentifier.getDatabaseName(), | ||
icebergIdentifier.getTableName())))); | ||
long icebergLatestMetaVersion = getIcebergLatestMetaVersion(); | ||
|
||
this.icebergLatestMetaVersionPath = | ||
icebergMetaPathFactory.toMetadataPath(icebergLatestMetaVersion); | ||
LOG.info( | ||
"iceberg latest snapshot metadata file location: {}", icebergLatestMetaVersionPath); | ||
|
||
return IcebergMetadata.fromPath(fileIO, icebergLatestMetaVersionPath); | ||
} | ||
|
||
@Override | ||
public String icebergLatestMetadataLocation() { | ||
return icebergLatestMetaVersionPath.toString(); | ||
} | ||
|
||
@Override | ||
public void deleteOriginTable() { | ||
Path tablePath = icebergMetaPathFactory.metadataDirectory().getParent(); | ||
LOG.info("Iceberg table path to be deleted:{}", tablePath); | ||
try { | ||
if (fileIO.isDir(tablePath)) { | ||
fileIO.deleteDirectoryQuietly(tablePath); | ||
} | ||
} catch (IOException e) { | ||
LOG.warn("exception occurred when deleting origin table.", e); | ||
} | ||
} | ||
|
||
private long getIcebergLatestMetaVersion() { | ||
Path versionHintPath = | ||
new Path(icebergMetaPathFactory.metadataDirectory(), VERSION_HINT_FILENAME); | ||
try { | ||
return Integer.parseInt(fileIO.readFileUtf8(versionHintPath)); | ||
} catch (IOException e) { | ||
throw new RuntimeException( | ||
"read iceberg version-hint.text failed. Iceberg metadata path: " | ||
+ icebergMetaPathFactory.metadataDirectory(), | ||
e); | ||
} | ||
} | ||
} |
Oops, something went wrong.
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.
This class already has a
dataType
member. Check ifdataType
is null, if not just return that object, otherwise calculate data type fromtype
string.