Skip to content

Commit 24e246a

Browse files
authored
SQL: Remove dependency on org.elasticsearch.Version (#112094) (#114640)
This removes SQL's use of `org.elasticsearch.Version` class and usages replaced by `SqlVersion`. All the currently considered released versions (`7.0.0` to `8.16.0`) have been declared as `SqlVersion` instances. These are still tested against. The last "known release" (`8.16.0`) is considered the "server compatibility version" and all clients at or past this release are compatible with the server; notably, they can be also on a newer version than server's. Clients released before this "server compatibility version" respect existing compatibility requirements (must/can be older up to one major lower, but past `7.7.0`). The "server compatibility version" will not be updated with newer stack releases (at least not until #112745 is addressed). Fixes #102689
1 parent feec6c7 commit 24e246a

File tree

43 files changed

+593
-295
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+593
-295
lines changed

x-pack/plugin/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/EsDataSource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
public class EsDataSource implements DataSource, Wrapper {
2626

2727
static {
28-
// invoke Version to perform classpath/jar sanity checks
28+
// invoke version to perform classpath/jar sanity checks
2929
ClientVersion.CURRENT.toString();
3030
}
3131

x-pack/plugin/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/EsDriver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class EsDriver implements Driver {
2323
private static final EsDriver INSTANCE = new EsDriver();
2424

2525
static {
26-
// invoke Version to perform classpath/jar sanity checks
26+
// invoke version to perform classpath/jar sanity checks
2727
ClientVersion.CURRENT.toString();
2828

2929
try {

x-pack/plugin/sql/jdbc/src/test/java/org/elasticsearch/xpack/sql/jdbc/DriverManagerRegistrationTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77
package org.elasticsearch.xpack.sql.jdbc;
88

9-
import org.elasticsearch.Version;
109
import org.elasticsearch.test.ESTestCase;
1110

1211
import java.security.AccessController;
@@ -27,8 +26,8 @@ public void testVersioning() throws Exception {
2726
/* This test will only work properly in gradle because in gradle we run the tests
2827
* using the jar. */
2928

30-
assertNotEquals(String.valueOf(Version.CURRENT.major), d.getMajorVersion());
31-
assertNotEquals(String.valueOf(Version.CURRENT.minor), d.getMinorVersion());
29+
assertNotEquals(String.valueOf(VersionTests.current().major), d.getMajorVersion());
30+
assertNotEquals(String.valueOf(VersionTests.current().minor), d.getMinorVersion());
3231
});
3332
}
3433

x-pack/plugin/sql/jdbc/src/test/java/org/elasticsearch/xpack/sql/jdbc/VersionParityTests.java

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,21 @@
77

88
package org.elasticsearch.xpack.sql.jdbc;
99

10-
import org.elasticsearch.Version;
1110
import org.elasticsearch.common.xcontent.XContentHelper;
1211
import org.elasticsearch.rest.root.MainResponse;
13-
import org.elasticsearch.test.VersionUtils;
1412
import org.elasticsearch.test.http.MockResponse;
1513
import org.elasticsearch.xcontent.XContentType;
1614
import org.elasticsearch.xpack.sql.client.ClientVersion;
1715
import org.elasticsearch.xpack.sql.proto.SqlVersion;
16+
import org.elasticsearch.xpack.sql.proto.SqlVersions;
1817

1918
import java.io.IOException;
2019
import java.sql.SQLException;
20+
import java.util.ArrayList;
21+
import java.util.List;
22+
import java.util.stream.Collectors;
23+
24+
import static org.elasticsearch.xpack.sql.proto.VersionCompatibility.INTRODUCING_VERSION_COMPATIBILITY;
2125

2226
/**
2327
* Test class for JDBC-ES server versions checks.
@@ -29,15 +33,11 @@ public class VersionParityTests extends WebServerTestCase {
2933

3034
public void testExceptionThrownOnIncompatibleVersions() throws IOException, SQLException {
3135
String url = JdbcConfiguration.URL_PREFIX + webServerAddress();
32-
Version firstVersion = VersionUtils.getFirstVersion();
33-
Version version = Version.V_7_7_0;
34-
do {
35-
version = VersionUtils.getPreviousVersion(version);
36+
for (var version = SqlVersions.getFirstVersion(); version.onOrAfter(INTRODUCING_VERSION_COMPATIBILITY) == false; version =
37+
SqlVersions.getNextVersion(version)) {
3638
logger.info("Checking exception is thrown for version {}", version);
3739

3840
prepareResponse(version);
39-
// Client's version is wired up to patch level, excluding the qualifier => generate the test version as the server does it.
40-
String versionString = SqlVersion.fromString(version.toString()).toString();
4141

4242
SQLException ex = expectThrows(
4343
SQLException.class,
@@ -48,27 +48,30 @@ public void testExceptionThrownOnIncompatibleVersions() throws IOException, SQLE
4848
+ ClientVersion.CURRENT.majorMinorToString()
4949
+ " or newer; attempting to connect to a server "
5050
+ "version "
51-
+ versionString,
51+
+ version,
5252
ex.getMessage()
5353
);
54-
} while (version.compareTo(firstVersion) > 0);
54+
}
5555
}
5656

5757
public void testNoExceptionThrownForCompatibleVersions() throws IOException {
5858
String url = JdbcConfiguration.URL_PREFIX + webServerAddress();
59-
Version version = Version.CURRENT;
60-
try {
61-
do {
59+
List<SqlVersion> afterVersionCompatibility = SqlVersions.getAllVersions()
60+
.stream()
61+
.filter(v -> v.onOrAfter(INTRODUCING_VERSION_COMPATIBILITY))
62+
.collect(Collectors.toCollection(ArrayList::new));
63+
afterVersionCompatibility.add(VersionTests.current());
64+
for (var version : afterVersionCompatibility) {
65+
try {
6266
prepareResponse(version);
6367
new JdbcHttpClient(new JdbcConnection(JdbcConfiguration.create(url, null, 0), false));
64-
version = VersionUtils.getPreviousVersion(version);
65-
} while (version.compareTo(Version.V_7_7_0) >= 0);
66-
} catch (SQLException sqle) {
67-
fail("JDBC driver version and Elasticsearch server version should be compatible. Error: " + sqle);
68+
} catch (SQLException sqle) {
69+
fail("JDBC driver version and Elasticsearch server version should be compatible. Error: " + sqle);
70+
}
6871
}
6972
}
7073

71-
void prepareResponse(Version version) throws IOException {
74+
void prepareResponse(SqlVersion version) throws IOException {
7275
MainResponse response = version == null ? createCurrentVersionMainResponse() : createMainResponse(version);
7376
webServer().enqueue(
7477
new MockResponse().setResponseCode(200)

x-pack/plugin/sql/jdbc/src/test/java/org/elasticsearch/xpack/sql/jdbc/VersionTests.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,20 @@
66
*/
77
package org.elasticsearch.xpack.sql.jdbc;
88

9+
import org.elasticsearch.Build;
910
import org.elasticsearch.test.ESTestCase;
1011
import org.elasticsearch.xpack.sql.client.ClientVersion;
12+
import org.elasticsearch.xpack.sql.proto.SqlVersion;
1113

1214
public class VersionTests extends ESTestCase {
1315
public void testVersionIsCurrent() {
1416
/* This test will only work properly in gradle because in gradle we run the tests
1517
* using the jar. */
16-
assertEquals(org.elasticsearch.Version.CURRENT.major, ClientVersion.CURRENT.major);
17-
assertEquals(org.elasticsearch.Version.CURRENT.minor, ClientVersion.CURRENT.minor);
18-
assertEquals(org.elasticsearch.Version.CURRENT.revision, ClientVersion.CURRENT.revision);
18+
assertEquals(current(), ClientVersion.CURRENT);
19+
}
20+
21+
/** Returns the current stack version. Can be unreleased. */
22+
public static SqlVersion current() {
23+
return SqlVersion.fromString(Build.current().version());
1924
}
2025
}

x-pack/plugin/sql/jdbc/src/test/java/org/elasticsearch/xpack/sql/jdbc/WebServerTestCase.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
package org.elasticsearch.xpack.sql.jdbc;
99

1010
import org.elasticsearch.Build;
11-
import org.elasticsearch.Version;
1211
import org.elasticsearch.cluster.ClusterName;
1312
import org.elasticsearch.index.IndexVersion;
1413
import org.elasticsearch.rest.root.MainResponse;
1514
import org.elasticsearch.test.BuildUtils;
1615
import org.elasticsearch.test.ESTestCase;
1716
import org.elasticsearch.test.http.MockWebServer;
17+
import org.elasticsearch.xpack.sql.proto.SqlVersion;
1818
import org.junit.After;
1919
import org.junit.Before;
2020

@@ -42,10 +42,10 @@ public MockWebServer webServer() {
4242
}
4343

4444
MainResponse createCurrentVersionMainResponse() {
45-
return createMainResponse(Version.CURRENT);
45+
return createMainResponse(VersionTests.current());
4646
}
4747

48-
MainResponse createMainResponse(Version version) {
48+
MainResponse createMainResponse(SqlVersion version) {
4949
// the SQL client only cares about node version,
5050
// so ignore index & transport versions here (just set them to current)
5151
String clusterUuid = randomAlphaOfLength(10);

x-pack/plugin/sql/qa/jdbc/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/ConnectionTestCase.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
*/
77
package org.elasticsearch.xpack.sql.qa.jdbc;
88

9-
import org.elasticsearch.Version;
10-
119
import java.sql.Connection;
1210
import java.sql.DatabaseMetaData;
1311
import java.sql.SQLException;
@@ -22,8 +20,8 @@ public void testConnectionProperties() throws SQLException {
2220
assertFalse(c.isClosed());
2321
assertTrue(c.isReadOnly());
2422
DatabaseMetaData md = c.getMetaData();
25-
assertEquals(Version.CURRENT.major, md.getDatabaseMajorVersion());
26-
assertEquals(Version.CURRENT.minor, md.getDatabaseMinorVersion());
23+
assertEquals(JdbcTestUtils.CURRENT.major, md.getDatabaseMajorVersion());
24+
assertEquals(JdbcTestUtils.CURRENT.minor, md.getDatabaseMinorVersion());
2725
}
2826
}
2927

x-pack/plugin/sql/qa/jdbc/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/JdbcTestUtils.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
*/
77
package org.elasticsearch.xpack.sql.qa.jdbc;
88

9-
import org.elasticsearch.Version;
9+
import org.elasticsearch.Build;
1010
import org.elasticsearch.xpack.sql.jdbc.EsType;
11+
import org.elasticsearch.xpack.sql.proto.SqlVersion;
1112
import org.elasticsearch.xpack.sql.proto.StringUtils;
1213

1314
import java.math.BigInteger;
@@ -26,10 +27,11 @@
2627
import java.util.LinkedHashMap;
2728
import java.util.Map;
2829

29-
import static org.elasticsearch.Version.V_8_2_0;
30-
import static org.elasticsearch.Version.V_8_4_0;
3130
import static org.elasticsearch.common.time.DateUtils.toMilliSeconds;
3231
import static org.elasticsearch.test.ESTestCase.randomLongBetween;
32+
import static org.elasticsearch.xpack.sql.proto.VersionCompatibility.supportsDateNanos;
33+
import static org.elasticsearch.xpack.sql.proto.VersionCompatibility.supportsUnsignedLong;
34+
import static org.elasticsearch.xpack.sql.proto.VersionCompatibility.supportsVersionType;
3335

3436
final class JdbcTestUtils {
3537

@@ -43,7 +45,9 @@ private JdbcTestUtils() {}
4345
static final LocalDate EPOCH = LocalDate.of(1970, 1, 1);
4446

4547
static final String UNSIGNED_LONG_TYPE_NAME = "UNSIGNED_LONG";
46-
static final BigInteger UNSIGNED_LONG_MAX = BigInteger.ONE.shiftLeft(Long.SIZE).subtract(BigInteger.ONE);
48+
49+
// Build's version is always a SemVer in JDBC tests
50+
public static final SqlVersion CURRENT = SqlVersion.fromString(Build.current().version());
4751

4852
/*
4953
* The version of the driver that the QA (bwc-)tests run against.
@@ -59,12 +63,11 @@ private JdbcTestUtils() {}
5963
* }
6064
* </code>
6165
*/
62-
static final Version JDBC_DRIVER_VERSION;
66+
static final SqlVersion JDBC_DRIVER_VERSION;
6367

6468
static {
65-
// master's version is x.0.0-SNAPSHOT, tho Version#fromString() won't accept that back for recent versions
66-
String jdbcDriverVersion = System.getProperty(DRIVER_VERSION_PROPERTY_NAME, "").replace("-SNAPSHOT", "");
67-
JDBC_DRIVER_VERSION = Version.fromString(jdbcDriverVersion); // takes empty and null strings, resolves them to CURRENT
69+
String jdbcDriverVersion = System.getProperty(DRIVER_VERSION_PROPERTY_NAME, "");
70+
JDBC_DRIVER_VERSION = jdbcDriverVersion.isEmpty() ? CURRENT : SqlVersion.fromString(jdbcDriverVersion);
6871

6972
// Note: keep in sync with org.elasticsearch.xpack.sql.jdbc.TypeUtils#CLASS_TO_TYPE
7073
Map<Class<?>, EsType> aMap = new LinkedHashMap<>();
@@ -150,15 +153,14 @@ static int extractNanosOnly(long nanos) {
150153
}
151154

152155
static boolean versionSupportsDateNanos() {
153-
return JDBC_DRIVER_VERSION.onOrAfter(Version.V_7_12_0);
156+
return supportsDateNanos(JDBC_DRIVER_VERSION);
154157
}
155158

156159
public static boolean isUnsignedLongSupported() {
157-
return JDBC_DRIVER_VERSION.onOrAfter(V_8_2_0);
160+
return supportsUnsignedLong(JDBC_DRIVER_VERSION);
158161
}
159162

160163
public static boolean isVersionFieldTypeSupported() {
161-
return JDBC_DRIVER_VERSION.onOrAfter(V_8_4_0);
164+
return supportsVersionType(JDBC_DRIVER_VERSION);
162165
}
163-
164166
}

x-pack/plugin/sql/qa/jdbc/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/JdbcWarningsTestCase.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
package org.elasticsearch.xpack.sql.qa.jdbc;
99

10-
import org.elasticsearch.Version;
1110
import org.junit.Before;
1211

1312
import java.io.IOException;
@@ -20,14 +19,13 @@
2019
import java.util.List;
2120
import java.util.Properties;
2221

22+
import static org.elasticsearch.xpack.sql.proto.VersionCompatibility.INTRODUCING_WARNING_HANDLING;
2323
import static org.elasticsearch.xpack.sql.qa.jdbc.JdbcTestUtils.JDBC_DRIVER_VERSION;
2424
import static org.hamcrest.Matchers.containsInAnyOrder;
2525
import static org.hamcrest.Matchers.containsString;
2626

2727
public abstract class JdbcWarningsTestCase extends JdbcIntegrationTestCase {
2828

29-
private static final Version WARNING_HANDLING_ADDED_VERSION = Version.V_8_2_0;
30-
3129
@Before
3230
public void setupData() throws IOException {
3331
index("test_data", b -> b.field("foo", 1));
@@ -89,7 +87,7 @@ public void testClearWarnings() throws SQLException {
8987
}
9088

9189
private void assumeWarningHandlingDriverVersion() {
92-
assumeTrue("Driver does not yet handle deprecation warnings", JDBC_DRIVER_VERSION.onOrAfter(WARNING_HANDLING_ADDED_VERSION));
90+
assumeTrue("Driver does not yet handle deprecation warnings", JDBC_DRIVER_VERSION.onOrAfter(INTRODUCING_WARNING_HANDLING));
9391
}
9492

9593
}

x-pack/plugin/sql/qa/mixed-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/mixed_node/SqlSearchIT.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import org.apache.http.HttpHost;
1111
import org.apache.lucene.sandbox.document.HalfFloatPoint;
12-
import org.elasticsearch.Version;
1312
import org.elasticsearch.client.Request;
1413
import org.elasticsearch.client.Response;
1514
import org.elasticsearch.client.RestClient;
@@ -19,6 +18,7 @@
1918
import org.elasticsearch.xcontent.json.JsonXContent;
2019
import org.elasticsearch.xpack.ql.TestNode;
2120
import org.elasticsearch.xpack.ql.TestNodes;
21+
import org.elasticsearch.xpack.sql.proto.SqlVersion;
2222
import org.junit.After;
2323
import org.junit.Before;
2424

@@ -36,13 +36,14 @@
3636
import static java.util.Collections.unmodifiableMap;
3737
import static org.elasticsearch.xpack.ql.TestUtils.buildNodeAndVersions;
3838
import static org.elasticsearch.xpack.ql.TestUtils.readResource;
39+
import static org.elasticsearch.xpack.sql.proto.VersionCompatibility.INTRODUCING_VERSION_FIELD_TYPE;
3940

4041
public class SqlSearchIT extends ESRestTestCase {
4142

4243
private static final String BWC_NODES_VERSION = System.getProperty("tests.bwc_nodes_version");
4344

44-
// TODO[lor]: replace this with feature-based checks when we have one
45-
private static final boolean SUPPORTS_VERSION_FIELD_QL_INTRODUCTION = Version.fromString(BWC_NODES_VERSION).onOrAfter(Version.V_8_4_0);
45+
private static final boolean SUPPORTS_VERSION_FIELD_QL_INTRODUCTION = SqlVersion.fromString(BWC_NODES_VERSION)
46+
.onOrAfter(INTRODUCING_VERSION_FIELD_TYPE);
4647

4748
private static final String index = "test_sql_mixed_versions";
4849
private static int numShards;

0 commit comments

Comments
 (0)