-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Normalize basePath in targetTables in ConversionController
- Loading branch information
1 parent
f676788
commit 6a5f2b4
Showing
4 changed files
with
170 additions
and
3 deletions.
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
57 changes: 57 additions & 0 deletions
57
xtable-core/src/main/java/org/apache/xtable/conversion/ConversionUtils.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,57 @@ | ||
/* | ||
* 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.xtable.conversion; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import org.apache.xtable.model.storage.TableFormat; | ||
|
||
public class ConversionUtils { | ||
|
||
/** | ||
* Few table formats need the metadata to be located at the root level of the data files. Eg: An | ||
* iceberg table generated through spark will have two directories basePath/data and | ||
* basePath/metadata For synchronising the iceberg metadata to hudi and delta, they need to be | ||
* present in basePath/data/.hoodie and basePath/data/_delta_log. | ||
* | ||
* @param config conversion config for synchronizing source and target tables | ||
* @return updated table config. | ||
*/ | ||
public static ConversionConfig normalizeTargetPaths(ConversionConfig config) { | ||
if (!config.getSourceTable().getDataPath().equals(config.getSourceTable().getBasePath()) | ||
&& config.getSourceTable().getFormatName().equals(TableFormat.ICEBERG)) { | ||
List<TargetTable> updatedTargetTables = | ||
config.getTargetTables().stream() | ||
.filter( | ||
targetTable -> | ||
targetTable.getFormatName().equals(TableFormat.HUDI) | ||
|| targetTable.getFormatName().equals(TableFormat.DELTA)) | ||
.map( | ||
targetTable -> | ||
targetTable.toBuilder() | ||
.basePath(config.getSourceTable().getDataPath()) | ||
.build()) | ||
.collect(Collectors.toList()); | ||
return new ConversionConfig( | ||
config.getSourceTable(), updatedTargetTables, config.getSyncMode()); | ||
} | ||
return config; | ||
} | ||
} |
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
111 changes: 111 additions & 0 deletions
111
xtable-core/src/test/java/org/apache/xtable/conversion/TestConversionUtils.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,111 @@ | ||
/* | ||
* 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.xtable.conversion; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import java.util.Arrays; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import org.apache.xtable.model.storage.TableFormat; | ||
import org.apache.xtable.model.sync.SyncMode; | ||
|
||
class TestConversionUtils { | ||
|
||
@Test | ||
void testNormalizeTargetPaths() { | ||
ConversionConfig config = | ||
ConversionConfig.builder() | ||
.sourceTable( | ||
SourceTable.builder() | ||
.name("table_name") | ||
.formatName(TableFormat.ICEBERG) | ||
.basePath("/tmp/basePath") | ||
.dataPath("/tmp/basePath/data") | ||
.build()) | ||
.syncMode(SyncMode.FULL) | ||
.targetTables( | ||
Arrays.asList( | ||
TargetTable.builder() | ||
.name("table_name") | ||
.basePath("/tmp/basePath") | ||
.formatName(TableFormat.DELTA) | ||
.build(), | ||
TargetTable.builder() | ||
.name("table_name") | ||
.basePath("/tmp/basePath") | ||
.formatName(TableFormat.HUDI) | ||
.build())) | ||
.build(); | ||
ConversionConfig expectedNormalizedConfig = | ||
ConversionConfig.builder() | ||
.sourceTable( | ||
SourceTable.builder() | ||
.name("table_name") | ||
.formatName(TableFormat.ICEBERG) | ||
.basePath("/tmp/basePath") | ||
.dataPath("/tmp/basePath/data") | ||
.build()) | ||
.syncMode(SyncMode.FULL) | ||
.targetTables( | ||
Arrays.asList( | ||
TargetTable.builder() | ||
.name("table_name") | ||
.basePath("/tmp/basePath/data") | ||
.formatName(TableFormat.DELTA) | ||
.build(), | ||
TargetTable.builder() | ||
.name("table_name") | ||
.basePath("/tmp/basePath/data") | ||
.formatName(TableFormat.HUDI) | ||
.build())) | ||
.build(); | ||
ConversionConfig actualConfig = ConversionUtils.normalizeTargetPaths(config); | ||
assertEquals(expectedNormalizedConfig, actualConfig); | ||
} | ||
|
||
@Test | ||
void testNormalizeTargetPathsNoOp() { | ||
ConversionConfig config = | ||
ConversionConfig.builder() | ||
.sourceTable( | ||
SourceTable.builder() | ||
.name("table_name") | ||
.formatName(TableFormat.HUDI) | ||
.basePath("/tmp/basePath") | ||
.build()) | ||
.syncMode(SyncMode.FULL) | ||
.targetTables( | ||
Arrays.asList( | ||
TargetTable.builder() | ||
.name("table_name") | ||
.basePath("/tmp/basePath") | ||
.formatName(TableFormat.ICEBERG) | ||
.build(), | ||
TargetTable.builder() | ||
.name("table_name") | ||
.basePath("/tmp/basePath") | ||
.formatName(TableFormat.DELTA) | ||
.build())) | ||
.build(); | ||
ConversionConfig actualConfig = ConversionUtils.normalizeTargetPaths(config); | ||
assertEquals(config, actualConfig); | ||
} | ||
} |