Skip to content
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

[GOBBLIN-2159] Adding support for partition level copy in Iceberg distcp #4058

Merged
merged 33 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
02ae2fc
initial changes for iceberg distcp partition copy
Blazer-007 Sep 12, 2024
981357c
added datetime filter predicate with unit tests
Blazer-007 Sep 16, 2024
7cd9353
changing string.class to object.class
Blazer-007 Sep 17, 2024
82d10d3
updated replace partition to use serialized data files
Blazer-007 Sep 19, 2024
c43d3e1
some code cleanup
Blazer-007 Sep 20, 2024
0cf7638
added unit test
Blazer-007 Sep 20, 2024
63bb9aa
added replace partition unit test
Blazer-007 Sep 20, 2024
6e1cf6b
refactored and added more test
Blazer-007 Sep 21, 2024
065cde3
added javadoc
Blazer-007 Sep 21, 2024
a13220d
removed extra lines
Blazer-007 Sep 21, 2024
e1d812f
some minor changes
Blazer-007 Sep 21, 2024
4364044
added retry and tests for replace partitions commit step
Blazer-007 Sep 22, 2024
66d81a3
minor test changes
Blazer-007 Sep 22, 2024
24b4823
added metadata validator
Blazer-007 Sep 23, 2024
d8356e1
removed validator class for now
Blazer-007 Sep 24, 2024
4dcc88b
addressed comments and removed some classes for now
Blazer-007 Sep 27, 2024
46bd976
fixing checkstyle bugs and disabling newly added tests to find root c…
Blazer-007 Sep 27, 2024
e1e6f57
addressed pr comments and added few extra logs
Blazer-007 Oct 8, 2024
b6163ba
refactored classes
Blazer-007 Oct 17, 2024
6c73a25
removed extra import statements
Blazer-007 Oct 17, 2024
9c35733
enabled the tests
Blazer-007 Oct 17, 2024
cdc863a
fixed iceberg table tests
Blazer-007 Oct 17, 2024
1dbe929
some refactoring
Blazer-007 Oct 22, 2024
383ed91
refactored tests as per review comments
Blazer-007 Oct 22, 2024
942ad8d
throw tablenotfoundexception in place of nosuchtableexception
Blazer-007 Oct 22, 2024
6a4cf78
fixed throwing proper exception
Blazer-007 Oct 23, 2024
2adaa8b
removed unused imports
Blazer-007 Oct 23, 2024
c948854
replcaed runtime exception with ioexception
Blazer-007 Oct 23, 2024
a55ee61
added check to avoid printing same log line
Blazer-007 Oct 23, 2024
1afc37a
fixed import order
Blazer-007 Oct 23, 2024
bb35070
added catch for CheckedExceptionFunction.WrappedIOException wrapper
Blazer-007 Oct 23, 2024
eeb8d25
fixed compile issue
Blazer-007 Oct 23, 2024
675e8bb
removing unwanted logging
Blazer-007 Oct 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.apache.hadoop.conf.Configuration;
import org.apache.iceberg.CatalogUtil;
import org.apache.iceberg.Table;
import org.apache.iceberg.TableOperations;
import org.apache.iceberg.catalog.Catalog;
import org.apache.iceberg.catalog.TableIdentifier;
Expand All @@ -43,7 +44,10 @@ protected BaseIcebergCatalog(String catalogName, Class<? extends Catalog> compan
@Override
public IcebergTable openTable(String dbName, String tableName) {
TableIdentifier tableId = TableIdentifier.of(dbName, tableName);
return new IcebergTable(tableId, calcDatasetDescriptorName(tableId), getDatasetDescriptorPlatform(), createTableOperations(tableId), this.getCatalogUri());
return new IcebergTable(tableId, calcDatasetDescriptorName(tableId), getDatasetDescriptorPlatform(),
createTableOperations(tableId),
this.getCatalogUri(),
loadTableInstance(tableId));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed a test now validating a throw of org.apache.iceberg.exceptions.NoSuchTableException. does that arise from this call to loadTableInstance?

wherever it is, let's catch it, so it exceptions from org.apache.iceberg don't bleed through. locate where and re-wrap with (our own) IcebergTable.TableNotFoundException

Copy link
Contributor Author

@Blazer-007 Blazer-007 Oct 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it arise from loadTableInstance or more specifically from catalog.loadTable(tableIdentifier) and i dont believe it will be easy to catch it and rethrow as IcebergTable.TableNotFoundException because this exception arises before creating IcebergTable instance itself as opposite to catalog.newTableOps(tableIdentifier) which doesn't throw this exception while initializing rather it throws when used for first time inside IcebergTable.

Please let me know your thoughts on this if we really want to throw IcebergTable.TableNotFoundException itself in catalog only

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's OK to raise the exception at creation time rather than upon first-use. in fact, that's arguably even better

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e.g.

public IcebergTable openTable(String dbName, String tableName) throws IcebergTable.TableNotFoundException { ... }

}

protected Catalog createCompanionCatalog(Map<String, String> properties, Configuration configuration) {
Expand All @@ -67,4 +71,6 @@ protected String getDatasetDescriptorPlatform() {
}

protected abstract TableOperations createTableOperations(TableIdentifier tableId);

protected abstract Table loadTableInstance(TableIdentifier tableId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for good measure you could also make IcebergTable.TableNotFoundException a declared/checked exception here.

I'm tempted to re-situate the exception as IcebergCatalog.TableNotFoundException, but I don't want two classes w/ the same semantics - and renaming public interfaces is probably too late... so I'll make peace with the current name

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed not throwing here instead catching NoSuchTableException in BaseIcebergCatalog::openTable and throwing IcebergTable.TableNotFoundException from there.

}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public String getConfigPrefix() {
}

protected final FileSystem sourceFs;
private final Properties properties;
protected final Properties properties;

/**
* Finds all {@link IcebergDataset}s in the file system using the Iceberg Catalog.
Expand Down Expand Up @@ -170,7 +170,7 @@ protected static boolean getConfigShouldCopyMetadataPath(Properties properties)
}

/** @return property value or `null` */
protected static String getLocationQualifiedProperty(Properties properties, CatalogLocation location, String relativePropName) {
public static String getLocationQualifiedProperty(Properties properties, CatalogLocation location, String relativePropName) {
Blazer-007 marked this conversation as resolved.
Show resolved Hide resolved
return properties.getProperty(calcLocationQualifiedPropName(location, relativePropName));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.iceberg.Table;
import org.apache.iceberg.TableOperations;
import org.apache.iceberg.catalog.TableIdentifier;
import org.apache.iceberg.hive.HiveCatalog;
Expand Down Expand Up @@ -61,4 +62,9 @@ protected TableOperations createTableOperations(TableIdentifier tableId) {
public boolean tableAlreadyExists(IcebergTable icebergTable) {
return hc.tableExists(icebergTable.getTableId());
}

@Override
protected Table loadTableInstance(TableIdentifier tableId) {
return hc.loadTable(tableId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
/*
* 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.gobblin.data.management.copy.iceberg;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Properties;
import java.util.UUID;
import java.util.function.Predicate;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.iceberg.DataFile;
import org.apache.iceberg.DataFiles;
import org.apache.iceberg.PartitionSpec;
import org.apache.iceberg.StructLike;
import org.apache.iceberg.TableMetadata;
import org.apache.iceberg.TableProperties;
import org.apache.iceberg.util.SerializationUtil;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.base.Preconditions;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import org.apache.gobblin.data.management.copy.CopyConfiguration;
import org.apache.gobblin.data.management.copy.CopyEntity;
import org.apache.gobblin.data.management.copy.CopyableFile;
import org.apache.gobblin.data.management.copy.entities.PostPublishStep;
import org.apache.gobblin.data.management.copy.CopyableDataset;
import org.apache.gobblin.data.management.copy.iceberg.predicates.IcebergPartitionFilterPredicateFactory;

/**
* Iceberg Partition dataset implementing {@link CopyableDataset}
* <p>
* This class extends {@link IcebergDataset} and provides functionality to filter partitions
* and generate copy entities for partition based data movement.
* </p>
*/
@Slf4j
public class IcebergPartitionDataset extends IcebergDataset {

private static final String ICEBERG_PARTITION_NAME_KEY = "partition.name";
private final Predicate<StructLike> partitionFilterPredicate;

public IcebergPartitionDataset(IcebergTable srcIcebergTable, IcebergTable destIcebergTable, Properties properties,
FileSystem sourceFs, boolean shouldIncludeMetadataPath) throws IcebergTable.TableNotFoundException {
super(srcIcebergTable, destIcebergTable, properties, sourceFs, shouldIncludeMetadataPath);

String partitionColumnName =
IcebergDatasetFinder.getLocationQualifiedProperty(properties, IcebergDatasetFinder.CatalogLocation.SOURCE,
ICEBERG_PARTITION_NAME_KEY);
Blazer-007 marked this conversation as resolved.
Show resolved Hide resolved
Preconditions.checkArgument(StringUtils.isNotEmpty(partitionColumnName),
"Partition column name cannot be empty");

TableMetadata srcTableMetadata = getSrcIcebergTable().accessTableMetadata();
this.partitionFilterPredicate = IcebergPartitionFilterPredicateFactory.getFilterPredicate(partitionColumnName,
srcTableMetadata, properties);
}

/**
* Represents the destination file paths and the corresponding file status in source file system.
* These both properties are used in creating {@link CopyEntity}
*/
@Data
protected static final class FilePathsWithStatus {
private final Path destPath;
private final FileStatus srcFileStatus;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the base class uses Map<Path, FileStatus>. did that seem inefficient or was there another reason to deviate?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one could have been same, the reason i will mention in the reply of this comment - #4058 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT the Map<Path, FileStatus> in IcebergDataset just treats the key as a path, not specifically src vs. dest.

so that still seems worth following here, rather than inventing a new one-off type to convey equivalent info.

I'll leave the choice to you, but consistency is my recommendation.


/**
* Generates copy entities for partition based data movement.
* It finds files specific to the partition and create destination data files based on the source data files.
* Also updates the destination data files with destination table write data location and add UUID to the file path
* to avoid conflicts.
*
* @param targetFs the target file system
* @param copyConfig the copy configuration
* @return a collection of copy entities
* @throws IOException if an I/O error occurs
*/
@Override
Collection<CopyEntity> generateCopyEntities(FileSystem targetFs, CopyConfiguration copyConfig) throws IOException {
Copy link
Contributor

@phet phet Sep 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this impl is really, really similar to the one it's based on in its base class. deriving from a class and then overriding methods w/ only small changes is pretty nearly cut-and-paste code. sometimes it's inevitable, but let's avoid when we can. in this case, could we NOT override this method, but only GetFilePathsToFileStatusResult getFilePathsToFileStatus(...) so this derived class's version runs the new code instead:

    IcebergTable srcIcebergTable = getSrcIcebergTable();
    List<DataFile> srcDataFiles = srcIcebergTable.getPartitionSpecificDataFiles(this.partitionFilterPredicate);
    List<DataFile> destDataFiles = getDestDataFiles(srcDataFiles);
    Configuration defaultHadoopConfiguration = new Configuration();

    for (FilePathsWithStatus filePathsWithStatus : getFilePathsStatus(srcDataFiles, destDataFiles, this.sourceFs)) {
...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will list down my reason here -

  1. In IcebergDataset implementation it is assumed that srcPath and destPath are same which is not the case here, if you see the code we are using srcPath, srcFileStatus but here those needs to be changed to destPath & srcFileStatus for readability and maintaining the code as well.
  2. Currently I have added just ReplacePartitionStep as post publish step but IcebergRegisterStep too needs to be added based on Schema Validation scenario which I will be raising as different PR because that needs a proper validation so that we are not corrupting datafiles on dest table.
  3. I am not fully convinced on copying Ancestor Permission, whether it is even required or not, although I did tried making it work by changing ancestor path parent path but wasn't working so removing it is a must for now.
  4. If i will try to just override GetFilePathsToFileStatusResult getFilePathsToFileStatus(...) then we need to override Data class GetFilePathsToFileStatusResult too as we need datafiles too along with destPath srcFileStatus.

To conclude it -
reader should understand whether it is actually srcPath or destPath while creating copyable file
need of adding replacepartition commit step along with registerstep (based on condition)
and to remove copying permission for now.

String fileSet = this.getFileSetId();
List<CopyEntity> copyEntities = Lists.newArrayList();
IcebergTable srcIcebergTable = getSrcIcebergTable();
List<DataFile> srcDataFiles = srcIcebergTable.getPartitionSpecificDataFiles(this.partitionFilterPredicate);
List<DataFile> destDataFiles = getDestDataFiles(srcDataFiles);
Configuration defaultHadoopConfiguration = new Configuration();

for (FilePathsWithStatus filePathsWithStatus : getFilePathsStatus(srcDataFiles, destDataFiles, this.sourceFs)) {
Path destPath = filePathsWithStatus.getDestPath();
FileStatus srcFileStatus = filePathsWithStatus.getSrcFileStatus();
FileSystem actualSourceFs = getSourceFileSystemFromFileStatus(srcFileStatus, defaultHadoopConfiguration);
Blazer-007 marked this conversation as resolved.
Show resolved Hide resolved

CopyableFile fileEntity = CopyableFile.fromOriginAndDestination(
actualSourceFs, srcFileStatus, targetFs.makeQualified(destPath), copyConfig)
.fileSet(fileSet)
.datasetOutputPath(targetFs.getUri().getPath())
.build();
Comment on lines +115 to +119
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you skip first doing this, like in IcebergDataset:

      // preserving ancestor permissions till root path's child between src and dest
      List<OwnerAndPermission> ancestorOwnerAndPermissionList =
          CopyableFile.resolveReplicatedOwnerAndPermissionsRecursively(actualSourceFs,
              srcPath.getParent(), greatestAncestorPath, copyConfig);

is that intentional? do you feel it's not necessary or actually contra-indicated?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the IcebergDataset the path of tables are exactly since table UUID are same on source and destination here it can be different, so copying permissions atleast in first draft is not necessary I believe.

Even if there is need that we need to make sure ancestor path, parent path are ones we want, that's why I have removed it for now.


fileEntity.setSourceData(getSourceDataset(this.sourceFs));
fileEntity.setDestinationData(getDestinationDataset(targetFs));
copyEntities.add(fileEntity);
}

// Adding this check to avoid adding post publish step when there are no files to copy.
if (CollectionUtils.isNotEmpty(destDataFiles)) {
copyEntities.add(createPostPublishStep(destDataFiles));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree this is one difference with IcebergDataset::generateCopyEntities, which always wants to add its post-publish step. (but it shouldn't be hard to refactor to isolate this difference)


log.info("~{}~ generated {} copy--entities", fileSet, copyEntities.size());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the two dashes between copy--entities seems like a typo

return copyEntities;
}

private List<DataFile> getDestDataFiles(List<DataFile> srcDataFiles) throws IcebergTable.TableNotFoundException {
List<DataFile> destDataFiles = new ArrayList<>();
if (srcDataFiles.isEmpty()) {
return destDataFiles;
}
TableMetadata srcTableMetadata = getSrcIcebergTable().accessTableMetadata();
TableMetadata destTableMetadata = getDestIcebergTable().accessTableMetadata();
PartitionSpec partitionSpec = destTableMetadata.spec();
String srcWriteDataLocation = srcTableMetadata.property(TableProperties.WRITE_DATA_LOCATION, "");
String destWriteDataLocation = destTableMetadata.property(TableProperties.WRITE_DATA_LOCATION, "");
if (StringUtils.isEmpty(srcWriteDataLocation) || StringUtils.isEmpty(destWriteDataLocation)) {
log.warn(
String.format("Either source or destination table does not have write data location : source table write data location : {%s} , destination table write data location : {%s}",
srcWriteDataLocation,
destWriteDataLocation
)
);
Blazer-007 marked this conversation as resolved.
Show resolved Hide resolved
}
// tableMetadata.property(TableProperties.WRITE_DATA_LOCATION, "") returns null if the property is not set and
// doesn't respect passed default value, so to avoid NPE in .replace() we are setting it to empty string.
String prefixToBeReplaced = (srcWriteDataLocation != null) ? srcWriteDataLocation : "";
String prefixToReplaceWith = (destWriteDataLocation != null) ? destWriteDataLocation : "";
Blazer-007 marked this conversation as resolved.
Show resolved Hide resolved
srcDataFiles.forEach(dataFile -> {
String curDestFilePath = dataFile.path().toString();
String newDestFilePath = curDestFilePath.replace(prefixToBeReplaced, prefixToReplaceWith);
String updatedDestFilePath = addUUIDToPath(newDestFilePath);
Blazer-007 marked this conversation as resolved.
Show resolved Hide resolved
destDataFiles.add(DataFiles.builder(partitionSpec)
.copy(dataFile)
.withPath(updatedDestFilePath)
.build());
});
return destDataFiles;
}

private String addUUIDToPath(String filePathStr) {
Path filePath = new Path(filePathStr);
String fileDir = filePath.getParent().toString();
String fileName = filePath.getName();
String newFileName = UUID.randomUUID() + "-" + fileName;
return String.join("/", fileDir, newFileName);
Blazer-007 marked this conversation as resolved.
Show resolved Hide resolved
}

private List<FilePathsWithStatus> getFilePathsStatus(List<DataFile> srcDataFiles, List<DataFile> destDataFiles, FileSystem fs) throws IOException {
List<FilePathsWithStatus> filePathsStatus = new ArrayList<>();
for (int i = 0; i < srcDataFiles.size(); i++) {
Path srcPath = new Path(srcDataFiles.get(i).path().toString());
Path destPath = new Path(destDataFiles.get(i).path().toString());
FileStatus srcFileStatus = fs.getFileStatus(srcPath);
filePathsStatus.add(new FilePathsWithStatus(destPath, srcFileStatus));
}
return filePathsStatus;
}

private PostPublishStep createPostPublishStep(List<DataFile> destDataFiles) {

byte[] serializedDataFiles = SerializationUtil.serializeToBytes(destDataFiles);

IcebergReplacePartitionsStep icebergReplacePartitionsStep = new IcebergReplacePartitionsStep(
this.getDestIcebergTable().getTableId().toString(),
serializedDataFiles,
this.properties);

return new PostPublishStep(this.getFileSetId(), Maps.newHashMap(), icebergReplacePartitionsStep, 0);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* 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.gobblin.data.management.copy.iceberg;

import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Properties;

import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.fs.FileSystem;

import com.google.common.base.Preconditions;

import lombok.extern.slf4j.Slf4j;

/**
* Finder class for locating and creating partitioned Iceberg datasets.
* <p>
* This class extends {@link IcebergDatasetFinder} and provides functionality to create
* {@link IcebergPartitionDataset} instances based on the specified source and destination Iceberg catalogs.
* </p>
*/
@Slf4j
public class IcebergPartitionDatasetFinder extends IcebergDatasetFinder {
public IcebergPartitionDatasetFinder(FileSystem sourceFs, Properties properties) {
super(sourceFs, properties);
}

/**
* Finds the {@link IcebergPartitionDataset}s in the file system using the Iceberg Catalog. Both Iceberg database name and table
* name are mandatory based on current implementation.
* <p>
* Overriding this method to put a check whether source and destination db & table names are passed in the properties as separate values
* </p>
* @return List of {@link IcebergPartitionDataset}s in the file system.
* @throws IOException if there is an error while finding the datasets.
*/
@Override
public List<IcebergDataset> findDatasets() throws IOException {
String srcDbName = getLocationQualifiedProperty(this.properties, CatalogLocation.SOURCE, ICEBERG_DB_NAME_KEY);
String destDbName = getLocationQualifiedProperty(this.properties, CatalogLocation.DESTINATION, ICEBERG_DB_NAME_KEY);
String srcTableName = getLocationQualifiedProperty(this.properties, CatalogLocation.SOURCE, ICEBERG_TABLE_NAME_KEY);
String destTableName = getLocationQualifiedProperty(this.properties, CatalogLocation.DESTINATION, ICEBERG_TABLE_NAME_KEY);
Blazer-007 marked this conversation as resolved.
Show resolved Hide resolved

if (StringUtils.isBlank(srcDbName) || StringUtils.isBlank(destDbName) || StringUtils.isBlank(srcTableName)
|| StringUtils.isBlank(destTableName)) {
String errorMsg = String.format("Missing (at least some) IcebergDataset properties - source: ('%s' and '%s') and destination: ('%s' and '%s') ",
srcDbName, srcTableName, destDbName, destTableName);
log.error(errorMsg);
throw new IllegalArgumentException(errorMsg);
}

IcebergCatalog srcIcebergCatalog = createIcebergCatalog(this.properties, CatalogLocation.SOURCE);
IcebergCatalog destIcebergCatalog = createIcebergCatalog(this.properties, CatalogLocation.DESTINATION);

return Collections.singletonList(createIcebergDataset(
srcIcebergCatalog, srcDbName, srcTableName,
destIcebergCatalog, destDbName, destTableName,
this.properties, this.sourceFs
));
}

/**
* Creates an {@link IcebergPartitionDataset} instance for the specified source and destination Iceberg tables.
*/
@Override
protected IcebergDataset createIcebergDataset(IcebergCatalog sourceIcebergCatalog, String srcDbName, String srcTableName, IcebergCatalog destinationIcebergCatalog, String destDbName, String destTableName, Properties properties, FileSystem fs) throws IOException {
IcebergTable srcIcebergTable = sourceIcebergCatalog.openTable(srcDbName, srcTableName);
Preconditions.checkArgument(sourceIcebergCatalog.tableAlreadyExists(srcIcebergTable),
String.format("Missing Source Iceberg Table: {%s}.{%s}", srcDbName, srcTableName));
IcebergTable destIcebergTable = destinationIcebergCatalog.openTable(destDbName, destTableName);
Preconditions.checkArgument(destinationIcebergCatalog.tableAlreadyExists(destIcebergTable),
String.format("Missing Destination Iceberg Table: {%s}.{%s}", destDbName, destTableName));
// TODO: Add Validator for source and destination tables later
// TableMetadata srcTableMetadata = srcIcebergTable.accessTableMetadata();
// TableMetadata destTableMetadata = destIcebergTable.accessTableMetadata();
// IcebergTableMetadataValidator.validateSourceAndDestinationTablesMetadata(srcTableMetadata, destTableMetadata);
Blazer-007 marked this conversation as resolved.
Show resolved Hide resolved
return new IcebergPartitionDataset(srcIcebergTable, destIcebergTable, properties, fs, getConfigShouldCopyMetadataPath(properties));
Blazer-007 marked this conversation as resolved.
Show resolved Hide resolved
}
}
Loading
Loading