-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix for trailing / #166
Fix for trailing / #166
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Copyright (C) 2019-2023 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.commons.lang3.StringUtils; | ||
|
||
/** | ||
* Attempts to normalize string representing a location of a Hive Table, could have a wide variety of schemes, s3, s3a, | ||
* hdfs etc.. | ||
*/ | ||
public class LocationNormalizer { | ||
|
||
public String normalize(String location) { | ||
//Not using File.seperator here we might not know what the location would be using. (Beekeeper might run on Windows...) | ||
location =StringUtils.stripEnd(location, "/"); | ||
return location; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/** | ||
* Copyright (C) 2019-2020 Expedia, Inc. | ||
* Copyright (C) 2019-2023 Expedia, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
|
@@ -26,7 +26,18 @@ | |
|
||
@Component | ||
public class LocationOnlyUpdateListenerEventFilter implements ListenerEventFilter { | ||
|
||
private final LocationNormalizer locationNormalizer; | ||
|
||
public LocationOnlyUpdateListenerEventFilter () { | ||
this.locationNormalizer = new LocationNormalizer(); | ||
} | ||
|
||
public LocationOnlyUpdateListenerEventFilter (LocationNormalizer locationNormaliser) { | ||
this.locationNormalizer = locationNormaliser; | ||
} | ||
|
||
|
||
@Override | ||
public boolean isFiltered(ListenerEvent listenerEvent, LifecycleEventType lifecycleEventType) { | ||
EventType eventType = listenerEvent.getEventType(); | ||
|
@@ -44,6 +55,11 @@ public boolean isFiltered(ListenerEvent listenerEvent, LifecycleEventType lifecy | |
} | ||
|
||
private boolean isLocationSame(String oldLocation, String location) { | ||
return location == null || oldLocation == null || oldLocation.equals(location); | ||
if (location == null || oldLocation == null) { | ||
return true; | ||
} | ||
String normalizedOldLocation = locationNormalizer.normalize(oldLocation); | ||
String normalizedLocation = locationNormalizer.normalize(location); | ||
return normalizedOldLocation.equals(normalizedLocation); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should expand in follow up PR to check that location doesn't start with oldLocation and vica versa. old: Should be considered same. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't say right now if it's a good idea. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's why I'm holding off, need to think about this. |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* Copyright (C) 2019-2023 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 org.junit.jupiter.api.Test; | ||
|
||
class LocationNormalizerTest { | ||
|
||
private LocationNormalizer normalizer = new LocationNormalizer(); | ||
|
||
@Test | ||
void noChange() { | ||
assertThat(normalizer.normalize("s3://bucket/prefix")).isEqualTo("s3://bucket/prefix"); | ||
assertThat(normalizer.normalize("/bucket/prefix")).isEqualTo("/bucket/prefix"); | ||
assertThat(normalizer.normalize("hdfs://bucket/prefix")).isEqualTo("hdfs://bucket/prefix"); | ||
assertThat(normalizer.normalize("")).isEqualTo(""); | ||
assertThat(normalizer.normalize(null)).isEqualTo(null); | ||
assertThat(normalizer.normalize("foo")).isEqualTo("foo"); | ||
assertThat(normalizer.normalize("foo/bar")).isEqualTo("foo/bar"); | ||
} | ||
|
||
@Test | ||
void normalizeTrailingSlash() { | ||
assertThat(normalizer.normalize("s3://bucket/prefix/")).isEqualTo("s3://bucket/prefix"); | ||
assertThat(normalizer.normalize("s3://bucket/prefix///")).isEqualTo("s3://bucket/prefix"); | ||
assertThat(normalizer.normalize("hdfs://bucket/prefix/")).isEqualTo("hdfs://bucket/prefix"); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can expand on this in follow up PR to normalize scheme s3a/s3n/s3 to s3