-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Hamza Jugon
committed
Nov 27, 2024
1 parent
1206eb8
commit 5517c7f
Showing
4 changed files
with
143 additions
and
23 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
41 changes: 41 additions & 0 deletions
41
...core/src/main/java/com/expediagroup/beekeeper/core/predicate/IsIcebergTablePredicate.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,41 @@ | ||
/** | ||
* Copyright (C) 2019-2024 Expedia, Inc. | ||
* | ||
* Licensed 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 com.expediagroup.beekeeper.core.predicate; | ||
|
||
import java.util.Map; | ||
import java.util.function.Predicate; | ||
|
||
public class IsIcebergTablePredicate implements Predicate<Map<String, String>> { | ||
|
||
private static final String METADATA_LOCATION_KEY = "metadata_location"; | ||
private static final String TABLE_TYPE_KEY = "table_type"; | ||
private static final String TABLE_TYPE_ICEBERG_VALUE = "iceberg"; | ||
|
||
@Override | ||
public boolean test(Map<String, String> tableParameters) { | ||
if (tableParameters == null) { | ||
return false; | ||
} | ||
|
||
String metadataLocation = tableParameters.getOrDefault(METADATA_LOCATION_KEY, "").trim(); | ||
String tableType = tableParameters.getOrDefault(TABLE_TYPE_KEY, ""); | ||
|
||
boolean hasMetadataLocation = !metadataLocation.isEmpty(); | ||
boolean isIcebergType = tableType.toLowerCase().contains(TABLE_TYPE_ICEBERG_VALUE); | ||
|
||
return hasMetadataLocation || isIcebergType; | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
.../src/test/java/com/expediagroup/beekeeper/core/predicate/IsIcebergTablePredicateTest.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,90 @@ | ||
/** | ||
* Copyright (C) 2019-2024 Expedia, Inc. | ||
* | ||
* Licensed 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 com.expediagroup.beekeeper.core.predicate; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class IsIcebergTablePredicateTest { | ||
|
||
private IsIcebergTablePredicate predicate; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
predicate = new IsIcebergTablePredicate(); | ||
} | ||
|
||
@Test | ||
void testNullTableParameters() { | ||
assertFalse(predicate.test(null)); | ||
} | ||
|
||
@Test | ||
void testEmptyTableParameters() { | ||
Map<String, String> tableParameters = new HashMap<>(); | ||
assertFalse(predicate.test(tableParameters)); | ||
} | ||
|
||
@Test | ||
void testNoMetadataLocationOrTableType() { | ||
Map<String, String> tableParameters = Map.of("some_key", "some_value"); | ||
assertFalse(predicate.test(tableParameters)); | ||
} | ||
|
||
@Test | ||
void testHasMetadataLocation() { | ||
Map<String, String> tableParameters = Map.of("metadata_location", "some/location/path"); | ||
assertTrue(predicate.test(tableParameters)); | ||
} | ||
|
||
@Test | ||
void testHasIcebergTableType() { | ||
Map<String, String> tableParameters = Map.of("table_type", "ICEBERG"); | ||
assertTrue(predicate.test(tableParameters)); | ||
} | ||
|
||
@Test | ||
void testBothMetadataLocationAndTableType() { | ||
Map<String, String> tableParameters = Map.of( | ||
"metadata_location", "some/location/path", | ||
"table_type", "iceberg"); | ||
assertTrue(predicate.test(tableParameters)); | ||
} | ||
|
||
@Test | ||
void testCaseInsensitiveIcebergType() { | ||
Map<String, String> tableParameters = Map.of("table_type", "IcEbErG"); | ||
assertTrue(predicate.test(tableParameters)); | ||
} | ||
|
||
@Test | ||
void testWhitespaceInMetadataLocation() { | ||
Map<String, String> tableParameters = Map.of("metadata_location", " "); | ||
assertFalse(predicate.test(tableParameters)); | ||
} | ||
|
||
@Test | ||
void testIrrelevantTableType() { | ||
Map<String, String> tableParameters = Map.of("table_type", "hive"); | ||
assertFalse(predicate.test(tableParameters)); | ||
} | ||
} |
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