-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Adding Presto Version Class and version checks for session properties #17760
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
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,121 @@ | ||
| /* | ||
| * 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.facebook.presto.common; | ||
|
|
||
| import java.util.Objects; | ||
| import java.util.Optional; | ||
| import java.util.regex.Matcher; | ||
| import java.util.regex.Pattern; | ||
|
|
||
| import static java.util.Objects.requireNonNull; | ||
|
|
||
| public class PrestoVersion | ||
| implements Comparable<PrestoVersion> | ||
| { | ||
| private static final Pattern VERSION_REGEX = Pattern.compile("^(?<major>0|[1-9]\\d*)\\.(?<minor>0|[1-9]\\d*)(\\.(?<patch>0|[1-9]\\d*))?(?:-(?<prerelease>(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+(?<buildmetadata>[0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$"); | ||
|
|
||
| private int majorVersion; | ||
| private int minorVersion; | ||
| private int patchVersion; | ||
| private String prereleaseVersion = ""; | ||
| private String version; | ||
|
|
||
| public PrestoVersion(String version) | ||
| { | ||
| this.version = requireNonNull(version, "version string is null"); | ||
|
vaishnavibatni marked this conversation as resolved.
Outdated
|
||
| Matcher matcher = VERSION_REGEX.matcher(version); | ||
| if (matcher.find()) { | ||
|
vaishnavibatni marked this conversation as resolved.
Outdated
|
||
| this.majorVersion = Integer.parseInt(Optional.ofNullable(matcher.group("major")).orElse("0")); | ||
| this.minorVersion = Integer.parseInt(Optional.ofNullable(matcher.group("minor")).orElse("0")); | ||
| this.patchVersion = Integer.parseInt(Optional.ofNullable(matcher.group("patch")).orElse("0")); | ||
| this.prereleaseVersion = Optional.ofNullable(matcher.group("prerelease")).orElse(""); | ||
| } | ||
| } | ||
|
|
||
| public String getVersion() | ||
| { | ||
| return version; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() | ||
| { | ||
| return Objects.hash(this.majorVersion, this.minorVersion, this.patchVersion, this.prereleaseVersion); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object version) | ||
|
vaishnavibatni marked this conversation as resolved.
Outdated
|
||
| { | ||
| if (this == version) { | ||
| return true; | ||
| } | ||
| if (version == null || !(version instanceof PrestoVersion)) { | ||
| return false; | ||
| } | ||
| PrestoVersion prestoVersion = (PrestoVersion) version; | ||
| return (Objects.equals(this.majorVersion, prestoVersion.majorVersion) | ||
| && Objects.equals(this.minorVersion, prestoVersion.minorVersion) | ||
| && Objects.equals(this.patchVersion, prestoVersion.patchVersion) | ||
| && Objects.equals(this.prereleaseVersion, prestoVersion.prereleaseVersion)); | ||
| } | ||
|
|
||
| @Override | ||
| public int compareTo(PrestoVersion prestoVersion) | ||
| { | ||
| if (this.majorVersion != prestoVersion.majorVersion) { | ||
| return Integer.compare(this.majorVersion, prestoVersion.majorVersion); | ||
| } | ||
| if (this.minorVersion != prestoVersion.minorVersion) { | ||
| return Integer.compare(this.minorVersion, prestoVersion.minorVersion); | ||
| } | ||
| if (this.patchVersion != prestoVersion.patchVersion) { | ||
| return Integer.compare(this.patchVersion, prestoVersion.patchVersion); | ||
| } | ||
| if (!(this.prereleaseVersion.equals(prestoVersion.prereleaseVersion))) { | ||
| if (prestoVersion.prereleaseVersion.isEmpty()) { | ||
| return -1; | ||
| } | ||
| if (this.prereleaseVersion.isEmpty()) { | ||
| return 1; | ||
| } | ||
| return this.prereleaseVersion.compareTo(prestoVersion.prereleaseVersion); | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
| public boolean equalTo(PrestoVersion prestoVersion) | ||
| { | ||
| return this.compareTo(prestoVersion) == 0; | ||
| } | ||
|
|
||
| public boolean greaterThan(PrestoVersion prestoVersion) | ||
| { | ||
| return this.compareTo(prestoVersion) > 0; | ||
| } | ||
|
|
||
| public boolean lessThan(PrestoVersion prestoVersion) | ||
| { | ||
| return this.compareTo(prestoVersion) < 0; | ||
| } | ||
|
|
||
| public boolean greaterThanOrEqualTo(PrestoVersion prestoVersion) | ||
| { | ||
| return this.compareTo(prestoVersion) >= 0; | ||
| } | ||
|
|
||
| public boolean lessThanOrEqualTo(PrestoVersion prestoVersion) | ||
| { | ||
| return this.compareTo(prestoVersion) <= 0; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| /* | ||
| * 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.facebook.presto.common; | ||
|
|
||
| import org.testng.annotations.Test; | ||
|
|
||
| import static org.testng.Assert.assertFalse; | ||
| import static org.testng.Assert.assertTrue; | ||
|
|
||
| public class TestPrestoVersion | ||
| { | ||
| private static final PrestoVersion VERSION_274_20220517_171619_22 = new PrestoVersion("0.274-20220517.171619-22"); | ||
| private static final PrestoVersion VERSION_274_20220518_025123_29 = new PrestoVersion("0.274-20220518.025123-29"); | ||
| private static final PrestoVersion VERSION_274_SNAPSHOT_5d0ba93 = new PrestoVersion("0.274-SNAPSHOT-5d0ba93"); | ||
| private static final PrestoVersion VERSION_273 = new PrestoVersion("0.273"); | ||
| private static final PrestoVersion VERSION_274 = new PrestoVersion("0.274"); | ||
| private static final PrestoVersion VERSION_274_1 = new PrestoVersion("0.274.1"); | ||
| private static final PrestoVersion VERSION_274_2 = new PrestoVersion("0.274.2"); | ||
|
|
||
| @Test | ||
| public void testPrestoEquals() | ||
| { | ||
| assertTrue(VERSION_274_20220517_171619_22.equals(VERSION_274_20220517_171619_22)); | ||
| assertTrue(VERSION_274_1.equals(new PrestoVersion("0.274.1"))); | ||
| assertFalse(VERSION_274_1.equals(VERSION_274)); | ||
| assertFalse(VERSION_274_20220517_171619_22.equals(null)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testLessThan() | ||
| { | ||
| //Comparing major versions | ||
| assertFalse(VERSION_274_1.lessThan(VERSION_273)); | ||
|
|
||
| // Comparing Snapshot and non-Snapshot versions | ||
| assertTrue(VERSION_274_20220517_171619_22.lessThan(VERSION_274)); | ||
| assertTrue(VERSION_274_SNAPSHOT_5d0ba93.lessThan(VERSION_274)); | ||
| assertTrue(VERSION_274_SNAPSHOT_5d0ba93.lessThan(VERSION_274_1)); | ||
|
|
||
| //Comparing snapshot versions | ||
| assertFalse(VERSION_274_20220518_025123_29.lessThan(VERSION_274_20220517_171619_22)); | ||
|
|
||
| // Comparing equal versions | ||
| assertFalse(VERSION_274_SNAPSHOT_5d0ba93.lessThan(VERSION_274_SNAPSHOT_5d0ba93)); | ||
|
|
||
| // Comparing major and minor versions | ||
| assertTrue(VERSION_274.lessThan(VERSION_274_1)); | ||
| assertFalse(VERSION_274_1.lessThan(VERSION_274)); | ||
|
|
||
| //comparing minor versions | ||
| assertFalse(VERSION_274_2.lessThan(VERSION_274_1)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testLessThanOrEqualTo() | ||
| { | ||
| assertTrue(VERSION_274_20220517_171619_22.lessThanOrEqualTo(VERSION_274)); | ||
| assertTrue(VERSION_274_SNAPSHOT_5d0ba93.lessThanOrEqualTo(VERSION_274)); | ||
| assertTrue(VERSION_274.lessThanOrEqualTo(VERSION_274_1)); | ||
| assertTrue(VERSION_274_SNAPSHOT_5d0ba93.lessThanOrEqualTo(VERSION_274_1)); | ||
|
|
||
| //The following values should be equal | ||
| assertTrue(VERSION_274_SNAPSHOT_5d0ba93.lessThanOrEqualTo(VERSION_274_SNAPSHOT_5d0ba93)); | ||
| assertTrue(VERSION_274.lessThanOrEqualTo(VERSION_274)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testGreaterThanOrEqualTo() | ||
| { | ||
| assertTrue(VERSION_274.greaterThanOrEqualTo(VERSION_274_20220517_171619_22)); | ||
| assertTrue(VERSION_274.greaterThanOrEqualTo(VERSION_274_SNAPSHOT_5d0ba93)); | ||
| assertTrue(VERSION_274_1.greaterThanOrEqualTo(VERSION_274)); | ||
| assertTrue(VERSION_274_1.greaterThanOrEqualTo(VERSION_274_SNAPSHOT_5d0ba93)); | ||
|
|
||
| //The following values should be equal | ||
| assertTrue(VERSION_274_SNAPSHOT_5d0ba93.greaterThanOrEqualTo(VERSION_274_SNAPSHOT_5d0ba93)); | ||
| assertTrue(VERSION_274.greaterThanOrEqualTo(VERSION_274)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testGreaterThan() | ||
| { | ||
| //Comparing major versions | ||
| assertTrue(VERSION_274_1.greaterThan(VERSION_273)); | ||
|
|
||
| // Comparing Snapshot and non-Snapshot versions | ||
| assertTrue(VERSION_274.greaterThan(VERSION_274_20220517_171619_22)); | ||
| assertFalse(VERSION_274_20220517_171619_22.greaterThan(VERSION_274)); | ||
| assertFalse(VERSION_274_SNAPSHOT_5d0ba93.greaterThan(VERSION_274)); | ||
| assertFalse(VERSION_274_SNAPSHOT_5d0ba93.greaterThan(VERSION_274_1)); | ||
|
|
||
| //Comparing snapshot versions | ||
| assertFalse(VERSION_274_20220517_171619_22.greaterThan(VERSION_274_20220518_025123_29)); | ||
| assertTrue(VERSION_274_20220518_025123_29.greaterThan(VERSION_274_20220517_171619_22)); | ||
|
|
||
| // Comparing equal versions | ||
| assertFalse(VERSION_274_SNAPSHOT_5d0ba93.greaterThan(VERSION_274_SNAPSHOT_5d0ba93)); | ||
|
|
||
| // Comparing major and minor versions | ||
| assertFalse(VERSION_274.greaterThan(VERSION_274_1)); | ||
| assertTrue(VERSION_274_1.greaterThan(VERSION_274)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testVersionValidity() | ||
| { | ||
| PrestoVersion minVersion = new PrestoVersion("0.282"); | ||
| PrestoVersion maxVersion = new PrestoVersion("0.292"); | ||
| assertFalse(minVersion.lessThanOrEqualTo(VERSION_274_20220517_171619_22) && maxVersion.greaterThanOrEqualTo(VERSION_274_20220517_171619_22)); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,18 +75,41 @@ | |
| <scope>provided</scope> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>com.facebook.presto</groupId> | ||
| <artifactId>presto-client</artifactId> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>com.facebook.drift</groupId> | ||
| <artifactId>drift-api</artifactId> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
|
vaishnavibatni marked this conversation as resolved.
Outdated
|
||
|
|
||
| <dependency> | ||
| <groupId>io.airlift</groupId> | ||
| <artifactId>units</artifactId> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
|
Contributor
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. don't see it being used anywhere.
Contributor
Author
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 get this maven error when I remove them: |
||
| <groupId>io.airlift</groupId> | ||
| <artifactId>slice</artifactId> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>com.fasterxml.jackson.core</groupId> | ||
| <artifactId>jackson-annotations</artifactId> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
|
Contributor
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. where do we need this dependency? |
||
| <groupId>org.openjdk.jol</groupId> | ||
| <artifactId>jol-core</artifactId> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
|
|
||
| <!-- for testing --> | ||
| <dependency> | ||
| <groupId>com.facebook.presto</groupId> | ||
|
|
@@ -105,5 +128,9 @@ | |
| <artifactId>testing</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.facebook.presto</groupId> | ||
| <artifactId>presto-main</artifactId> | ||
| </dependency> | ||
| </dependencies> | ||
| </project> | ||
Uh oh!
There was an error while loading. Please reload this page.