-
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
Showing
38 changed files
with
695 additions
and
44 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
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
63 changes: 63 additions & 0 deletions
63
...cleanup/src/main/java/com/expediagroup/beekeeper/cleanup/validation/IcebergValidator.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,63 @@ | ||
/** | ||
* 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.cleanup.validation; | ||
|
||
import static java.lang.String.format; | ||
|
||
import java.util.Map; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.expediagroup.beekeeper.cleanup.metadata.CleanerClient; | ||
import com.expediagroup.beekeeper.cleanup.metadata.CleanerClientFactory; | ||
import com.expediagroup.beekeeper.core.error.BeekeeperIcebergException; | ||
import com.expediagroup.beekeeper.core.predicate.IsIcebergTablePredicate; | ||
|
||
public class IcebergValidator { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(IcebergValidator.class); | ||
|
||
private final CleanerClientFactory cleanerClientFactory; | ||
private final IsIcebergTablePredicate isIcebergTablePredicate; | ||
|
||
public IcebergValidator(CleanerClientFactory cleanerClientFactory) { | ||
this.cleanerClientFactory = cleanerClientFactory; | ||
this.isIcebergTablePredicate = new IsIcebergTablePredicate(); | ||
} | ||
|
||
/** | ||
* Beekeeper currently does not support the Iceberg format. Iceberg tables in the Hive Metastore do not store partition information, | ||
* causing Beekeeper to attempt to clean up the entire table due to the missing information. This method checks if | ||
* the table is an Iceberg table and throws a BeekeeperIcebergException to stop the process. | ||
* | ||
* @param databaseName | ||
* @param tableName | ||
*/ | ||
public void throwExceptionIfIceberg(String databaseName, String tableName) { | ||
try (CleanerClient client = cleanerClientFactory.newInstance()) { | ||
Map<String, String> tableParameters = client.getTableProperties(databaseName, tableName); | ||
|
||
if (isIcebergTablePredicate.test(tableParameters)) { | ||
throw new BeekeeperIcebergException( | ||
format("Iceberg table %s.%s is not currently supported in Beekeeper.", databaseName, tableName)); | ||
} | ||
} catch (Exception e) { | ||
throw new BeekeeperIcebergException( | ||
format("Unexpected exception when identifying if table %s.%s is Iceberg.", databaseName, tableName), e); | ||
} | ||
} | ||
} |
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
92 changes: 92 additions & 0 deletions
92
...nup/src/test/java/com/expediagroup/beekeeper/cleanup/validation/IcebergValidatorTest.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,92 @@ | ||
/** | ||
* 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.cleanup.validation; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import com.expediagroup.beekeeper.cleanup.metadata.CleanerClient; | ||
import com.expediagroup.beekeeper.cleanup.metadata.CleanerClientFactory; | ||
import com.expediagroup.beekeeper.core.error.BeekeeperIcebergException; | ||
|
||
public class IcebergValidatorTest { | ||
|
||
private CleanerClientFactory cleanerClientFactory; | ||
private CleanerClient cleanerClient; | ||
private IcebergValidator icebergValidator; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
cleanerClientFactory = mock(CleanerClientFactory.class); | ||
cleanerClient = mock(CleanerClient.class); | ||
when(cleanerClientFactory.newInstance()).thenReturn(cleanerClient); | ||
icebergValidator = new IcebergValidator(cleanerClientFactory); | ||
} | ||
|
||
@Test(expected = BeekeeperIcebergException.class) | ||
public void shouldThrowExceptionWhenTableTypeIsIceberg() throws Exception { | ||
Map<String, String> properties = new HashMap<>(); | ||
properties.put("table_type", "ICEBERG"); | ||
|
||
when(cleanerClient.getTableProperties("db", "table")).thenReturn(properties); | ||
|
||
icebergValidator.throwExceptionIfIceberg("db", "table"); | ||
verify(cleanerClientFactory).newInstance(); | ||
verify(cleanerClient).close(); | ||
} | ||
|
||
@Test(expected = BeekeeperIcebergException.class) | ||
public void shouldThrowExceptionWhenMetadataIsIceberg() throws Exception { | ||
Map<String, String> properties = new HashMap<>(); | ||
properties.put("metadata_location", "s3://db/table/metadata/0000.json"); | ||
|
||
when(cleanerClient.getTableProperties("db", "table")).thenReturn(properties); | ||
|
||
icebergValidator.throwExceptionIfIceberg("db", "table"); | ||
} | ||
|
||
@Test | ||
public void shouldNotThrowExceptionForNonIcebergTable() throws Exception { | ||
Map<String, String> properties = new HashMap<>(); | ||
properties.put("table_type", "HIVE_TABLE"); | ||
|
||
when(cleanerClient.getTableProperties("db", "table")).thenReturn(properties); | ||
|
||
icebergValidator.throwExceptionIfIceberg("db", "table"); | ||
verify(cleanerClientFactory).newInstance(); | ||
verify(cleanerClient).close(); | ||
} | ||
|
||
@Test | ||
public void shouldThrowExceptionWhenOutputFormatIsNull() throws Exception { | ||
Map<String, String> properties = new HashMap<>(); | ||
properties.put("table_type", null); | ||
properties.put("metadata_location", null); | ||
|
||
when(cleanerClient.getTableProperties("db", "table")).thenReturn(properties); | ||
|
||
assertThatThrownBy(() -> icebergValidator.throwExceptionIfIceberg("db", "table")).isInstanceOf( | ||
BeekeeperIcebergException.class); | ||
} | ||
} |
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
Oops, something went wrong.