-
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
58c6e65
commit a32e9d0
Showing
5 changed files
with
195 additions
and
2 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
58 changes: 58 additions & 0 deletions
58
...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,58 @@ | ||
/** | ||
* 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 org.springframework.stereotype.Component; | ||
|
||
import com.expedia.apiary.extensions.receiver.common.event.ListenerEvent; | ||
import com.expediagroup.beekeeper.core.model.LifecycleEventType; | ||
|
||
import java.util.Locale; | ||
import java.util.Map; | ||
|
||
@Component | ||
public class IcebergTableListenerEventFilter implements ListenerEventFilter { | ||
|
||
private static final Logger log = LogManager.getLogger(IcebergTableListenerEventFilter.class); | ||
|
||
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 isFiltered(ListenerEvent event, LifecycleEventType type) { | ||
Map<String, String> tableParameters = event.getTableParameters(); | ||
|
||
if (tableParameters != null) { | ||
String metadataLocation = tableParameters.getOrDefault(METADATA_LOCATION_KEY,null); | ||
String tableType = tableParameters.getOrDefault(TABLE_TYPE_KEY,null); | ||
|
||
boolean hasMetadataLocation = metadataLocation != null && !metadataLocation.trim().isEmpty(); | ||
boolean isIcebergType = tableType != null && tableType.toLowerCase().contains(TABLE_TYPE_ICEBERG_VALUE); | ||
|
||
if (hasMetadataLocation || isIcebergType) { | ||
log.info("Iceberg table '{}.{}' is not currently supported in Beekeeper.", | ||
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
111 changes: 111 additions & 0 deletions
111
...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,111 @@ | ||
/** | ||
* 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 shouldNotFilterWhenTableTypeIsNotIceberg() { | ||
ListenerEvent event = createListenerEventWithTableType("HIVE"); | ||
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 shouldFilterWhenMetadataLocationIsPresent() { | ||
ListenerEvent event = createListenerEventWithMetadataLocation("s3://example/path/to/metadata"); | ||
boolean isFiltered = filter.isFiltered(event, LifecycleEventType.EXPIRED); | ||
assertThat(isFiltered).isTrue(); | ||
} | ||
|
||
@Test | ||
public void shouldNotFilterWhenMetadataLocationIsEmpty() { | ||
ListenerEvent event = createListenerEventWithMetadataLocation(""); | ||
boolean isFiltered = filter.isFiltered(event, LifecycleEventType.EXPIRED); | ||
assertThat(isFiltered).isFalse(); | ||
} | ||
|
||
@Test | ||
public void shouldNotFilterWhenMetadataLocationIsNull() { | ||
ListenerEvent event = createListenerEventWithMetadataLocation(null); | ||
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(); | ||
} | ||
|
||
private ListenerEvent createListenerEventWithTableType(String tableType) { | ||
Map<String, String> tableParameters = new HashMap<>(); | ||
tableParameters.put("table_type", tableType); | ||
return createListenerEventWithTableParameters(tableParameters); | ||
} | ||
|
||
private ListenerEvent createListenerEventWithMetadataLocation(String metadataLocation) { | ||
Map<String, String> tableParameters = new HashMap<>(); | ||
tableParameters.put("metadata_location", metadataLocation); | ||
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; | ||
} | ||
}; | ||
} | ||
} |