-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[spark] support CopyFilesProcedure in spark #6625
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
9f610a5
support copy data files
shyjsarah 91837b2
support copy index files
shyjsarah 6484943
add test
shyjsarah 8e4eae9
fix bug
shyjsarah cf73a05
fix bugs
shyjsarah ce5e430
fix bugs
shyjsarah e97510b
update
shyjsarah c1862b7
fix codestyle
shyjsarah 9698732
update documents
shyjsarah a2c54ec
update
shyjsarah 74c09c7
fix target path
shyjsarah c4c5f32
fix schema id in DataFileMeta
shyjsarah 37e3867
support copy to existed table
shyjsarah a217c07
update
shyjsarah 4b08d8d
fix bugs
shyjsarah e993e33
fix bug
shyjsarah 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 hidden or 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 hidden or 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 hidden or 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
87 changes: 87 additions & 0 deletions
87
...paimon-spark-common/src/main/java/org/apache/paimon/spark/copy/CopyDataFilesOperator.java
This file contains hidden or 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,87 @@ | ||
| /* | ||
| * 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.spark.copy; | ||
|
|
||
| import org.apache.paimon.catalog.Catalog; | ||
| import org.apache.paimon.catalog.Identifier; | ||
| import org.apache.paimon.fs.Path; | ||
| import org.apache.paimon.spark.utils.SparkProcedureUtils; | ||
| import org.apache.paimon.table.FileStoreTable; | ||
|
|
||
| import org.apache.commons.collections4.CollectionUtils; | ||
| import org.apache.spark.api.java.JavaRDD; | ||
| import org.apache.spark.api.java.JavaSparkContext; | ||
| import org.apache.spark.api.java.function.FlatMapFunction; | ||
| import org.apache.spark.sql.SparkSession; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Iterator; | ||
| import java.util.List; | ||
|
|
||
| /** Copy data files from source table to target table. */ | ||
| public class CopyDataFilesOperator extends CopyFilesOperator { | ||
|
|
||
| public CopyDataFilesOperator(SparkSession spark, Catalog sourceCatalog, Catalog targetCatalog) { | ||
| super(spark, sourceCatalog, targetCatalog); | ||
| } | ||
|
|
||
| public JavaRDD<CopyFileInfo> execute( | ||
| Identifier sourceIdentifier, Identifier targetIdentifier, List<CopyFileInfo> dataFiles) | ||
| throws Exception { | ||
| if (CollectionUtils.isEmpty(dataFiles)) { | ||
| return null; | ||
| } | ||
| FileStoreTable sourceTable = (FileStoreTable) sourceCatalog.getTable(sourceIdentifier); | ||
| FileStoreTable targetTable = (FileStoreTable) targetCatalog.getTable(targetIdentifier); | ||
| int readParallelism = SparkProcedureUtils.readParallelism(dataFiles, spark); | ||
| JavaSparkContext context = JavaSparkContext.fromSparkContext(spark.sparkContext()); | ||
| JavaRDD<CopyFileInfo> copyFileInfoRdd = | ||
| context.parallelize(dataFiles, readParallelism) | ||
| .mapPartitions(new DataFileProcesser(sourceTable, targetTable)); | ||
| return copyFileInfoRdd; | ||
| } | ||
|
|
||
| /** Copy data files. */ | ||
| public static class DataFileProcesser | ||
| implements FlatMapFunction<Iterator<CopyFileInfo>, CopyFileInfo> { | ||
|
|
||
| private final FileStoreTable sourceTable; | ||
| private final FileStoreTable targetTable; | ||
|
|
||
| public DataFileProcesser(FileStoreTable sourceTable, FileStoreTable targetTable) { | ||
| this.sourceTable = sourceTable; | ||
| this.targetTable = targetTable; | ||
| } | ||
|
|
||
| @Override | ||
| public Iterator<CopyFileInfo> call(Iterator<CopyFileInfo> dataFileIterator) | ||
| throws Exception { | ||
| List<CopyFileInfo> result = new ArrayList<>(); | ||
| while (dataFileIterator.hasNext()) { | ||
| CopyFileInfo file = dataFileIterator.next(); | ||
| Path sourcePath = new Path(file.sourceFilePath()); | ||
| Path targetPath = new Path(file.targetFilePath()); | ||
| CopyFilesUtil.copyFiles( | ||
| sourceTable.fileIO(), targetTable.fileIO(), sourcePath, targetPath, false); | ||
| result.add(file); | ||
| } | ||
| return result.iterator(); | ||
| } | ||
| } | ||
| } | ||
92 changes: 92 additions & 0 deletions
92
...on-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/copy/CopyFileInfo.java
This file contains hidden or 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,92 @@ | ||
| /* | ||
| * 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.spark.copy; | ||
|
|
||
| import java.io.Serializable; | ||
|
|
||
| /** The information of copy data file. */ | ||
| public class CopyFileInfo implements Serializable { | ||
|
|
||
| private static final long serialVersionUID = 1L; | ||
|
|
||
| private final String sourceFilePath; | ||
|
|
||
| private final String targetFilePath; | ||
|
|
||
| private final byte[] partition; | ||
|
|
||
| private final int bucket; | ||
|
|
||
| private final int totalBuckets; | ||
|
|
||
| private final byte[] dataFileMeta; | ||
|
|
||
| public CopyFileInfo( | ||
| String sourceFilePath, | ||
| String targetFilePath, | ||
| byte[] partition, | ||
| int bucket, | ||
| byte[] dataFileMeta) { | ||
| this.sourceFilePath = sourceFilePath; | ||
| this.targetFilePath = targetFilePath; | ||
| this.partition = partition; | ||
| this.bucket = bucket; | ||
| this.totalBuckets = 0; | ||
| this.dataFileMeta = dataFileMeta; | ||
| } | ||
|
|
||
| public CopyFileInfo( | ||
| String sourceFilePath, | ||
| String targetFilePath, | ||
| byte[] partition, | ||
| int bucket, | ||
| int totalBuckets, | ||
| byte[] dataFileMeta) { | ||
| this.sourceFilePath = sourceFilePath; | ||
| this.targetFilePath = targetFilePath; | ||
| this.partition = partition; | ||
| this.bucket = bucket; | ||
| this.totalBuckets = totalBuckets; | ||
| this.dataFileMeta = dataFileMeta; | ||
| } | ||
|
|
||
| public String sourceFilePath() { | ||
| return sourceFilePath; | ||
| } | ||
|
|
||
| public String targetFilePath() { | ||
| return targetFilePath; | ||
| } | ||
|
|
||
| public byte[] partition() { | ||
| return partition; | ||
| } | ||
|
|
||
| public int bucket() { | ||
| return bucket; | ||
| } | ||
|
|
||
| public int totalBuckets() { | ||
| return totalBuckets; | ||
| } | ||
|
|
||
| public byte[] dataFileMeta() { | ||
| return dataFileMeta; | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.