-
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.
Ignore iceberg tables using filter and updating commonBeans
- Loading branch information
Hamza Jugon
committed
Nov 11, 2024
1 parent
fdd37b5
commit 44d7268
Showing
5 changed files
with
199 additions
and
6 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
55 changes: 55 additions & 0 deletions
55
...a/com/expediagroup/beekeeper/scheduler/apiary/filter/IcebergTableListenerEventFilter.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,55 @@ | ||
/** | ||
* 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.scheduler.apiary.filter; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
import com.expedia.apiary.extensions.receiver.common.event.ListenerEvent; | ||
import com.expediagroup.beekeeper.core.model.LifecycleEventType; | ||
|
||
import java.util.Map; | ||
|
||
public class IcebergTableListenerEventFilter implements ListenerEventFilter { | ||
|
||
private static final Logger log = LogManager.getLogger(IcebergTableListenerEventFilter.class); | ||
|
||
private static final String TABLE_TYPE_KEY = "table_type"; | ||
private static final String TABLE_TYPE_ICEBERG_VALUE = "ICEBERG"; | ||
|
||
@Override | ||
public boolean isFiltered(ListenerEvent event, LifecycleEventType type) { | ||
Map<String, String> tableParameters = event.getTableParameters(); | ||
|
||
// Check if the table_type parameter indicates an Iceberg table | ||
if (tableParameters != null) { | ||
String tableType = tableParameters.get(TABLE_TYPE_KEY); | ||
if (TABLE_TYPE_ICEBERG_VALUE.equalsIgnoreCase(tableType)) { | ||
log.info("Ignoring Iceberg table '{}.{}'.", event.getDbName(), event.getTableName()); | ||
return true; | ||
} | ||
} | ||
|
||
// Check if the output_format indicates an Iceberg table | ||
String outputFormat = (tableParameters != null) ? tableParameters.get("output_format") : null; | ||
if (outputFormat != null && outputFormat.toLowerCase().contains("iceberg")) { | ||
log.info("Ignoring Iceberg table '{}.{}'.", event.getDbName(), event.getTableName()); | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} |
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
112 changes: 112 additions & 0 deletions
112
...m/expediagroup/beekeeper/scheduler/apiary/filter/IcebergTableListenerEventFilterTest.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,112 @@ | ||
/** | ||
* 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.scheduler.apiary.filter; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import com.expedia.apiary.extensions.receiver.common.event.ListenerEvent; | ||
import com.expediagroup.beekeeper.core.model.LifecycleEventType; | ||
|
||
public class IcebergTableListenerEventFilterTest { | ||
|
||
private final IcebergTableListenerEventFilter filter = new IcebergTableListenerEventFilter(); | ||
|
||
@Test | ||
public void shouldFilterWhenTableTypeIsIceberg() { | ||
ListenerEvent event = createListenerEventWithTableType("ICEBERG"); | ||
boolean isFiltered = filter.isFiltered(event, LifecycleEventType.EXPIRED); | ||
assertThat(isFiltered).isTrue(); | ||
} | ||
|
||
@Test | ||
public void shouldFilterWhenOutputFormatContainsIceberg() { | ||
ListenerEvent event = createListenerEventWithOutputFormat("org.apache.iceberg.mr.hive.HiveIcebergOutputFormat"); | ||
boolean isFiltered = filter.isFiltered(event, LifecycleEventType.EXPIRED); | ||
assertThat(isFiltered).isTrue(); | ||
} | ||
|
||
@Test | ||
public void shouldNotFilterWhenTableIsNotIceberg() { | ||
ListenerEvent event = createListenerEventWithTableType("MANAGED_TABLE"); | ||
boolean isFiltered = filter.isFiltered(event, LifecycleEventType.EXPIRED); | ||
assertThat(isFiltered).isFalse(); | ||
} | ||
|
||
@Test | ||
public void shouldNotFilterWhenOutputFormatDoesNotContainIceberg() { | ||
ListenerEvent event = createListenerEventWithOutputFormat("org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat"); | ||
boolean isFiltered = filter.isFiltered(event, LifecycleEventType.EXPIRED); | ||
assertThat(isFiltered).isFalse(); | ||
} | ||
|
||
@Test | ||
public void shouldHandleNullTableParameters() { | ||
ListenerEvent event = createListenerEventWithTableParameters(null); | ||
boolean isFiltered = filter.isFiltered(event, LifecycleEventType.EXPIRED); | ||
assertThat(isFiltered).isFalse(); | ||
} | ||
|
||
@Test | ||
public void shouldFilterWhenTableTypeIsIcebergIgnoreCase() { | ||
ListenerEvent event = createListenerEventWithTableType("iceberg"); | ||
boolean isFiltered = filter.isFiltered(event, LifecycleEventType.EXPIRED); | ||
assertThat(isFiltered).isTrue(); | ||
} | ||
|
||
@Test | ||
public void shouldFilterWhenOutputFormatContainsIcebergIgnoreCase() { | ||
ListenerEvent event = createListenerEventWithOutputFormat("org.apache.ICEBERG.mr.hive.HiveIcebergOutputFormat"); | ||
boolean isFiltered = filter.isFiltered(event, LifecycleEventType.EXPIRED); | ||
assertThat(isFiltered).isTrue(); | ||
} | ||
|
||
// Helper methods to create ListenerEvent instances with the necessary table parameters | ||
private ListenerEvent createListenerEventWithTableType(String tableType) { | ||
Map<String, String> tableParameters = new HashMap<>(); | ||
tableParameters.put("table_type", tableType); | ||
return createListenerEventWithTableParameters(tableParameters); | ||
} | ||
|
||
private ListenerEvent createListenerEventWithOutputFormat(String outputFormat) { | ||
Map<String, String> tableParameters = new HashMap<>(); | ||
tableParameters.put("output_format", outputFormat); | ||
return createListenerEventWithTableParameters(tableParameters); | ||
} | ||
|
||
private ListenerEvent createListenerEventWithTableParameters(Map<String, String> tableParameters) { | ||
return new ListenerEvent() { | ||
@Override | ||
public String getDbName() { | ||
return "test_db"; | ||
} | ||
|
||
@Override | ||
public String getTableName() { | ||
return "test_table"; | ||
} | ||
|
||
@Override | ||
public Map<String, String> getTableParameters() { | ||
return tableParameters; | ||
} | ||
}; | ||
} | ||
} |