From ee2d53a6482f139fe2beb5bbdf35ada42a1907f1 Mon Sep 17 00:00:00 2001 From: Alexandr Gorshenin Date: Thu, 17 Oct 2024 10:25:07 +0100 Subject: [PATCH] Upgrade to Java SDK 2.3.3 --- jdbc/pom.xml | 2 +- .../ydb/jdbc/YdbDriverOlapTablesTest.java | 146 +++++++++++++++++- .../tech/ydb/jdbc/YdbDriverTablesTest.java | 14 +- .../jdbc/impl/YdbQueryConnectionImplTest.java | 2 - pom.xml | 2 +- 5 files changed, 147 insertions(+), 19 deletions(-) diff --git a/jdbc/pom.xml b/jdbc/pom.xml index 3854ad1..eb0e7f2 100644 --- a/jdbc/pom.xml +++ b/jdbc/pom.xml @@ -76,7 +76,7 @@ @{argLine} -Duser.timezone=GMT-04 true - cr.yandex/yc/yandex-docker-local-ydb:trunk + ydbplatform/local-ydb:trunk src/test/resources/logging.properties diff --git a/jdbc/src/test/java/tech/ydb/jdbc/YdbDriverOlapTablesTest.java b/jdbc/src/test/java/tech/ydb/jdbc/YdbDriverOlapTablesTest.java index d501a10..2895a55 100644 --- a/jdbc/src/test/java/tech/ydb/jdbc/YdbDriverOlapTablesTest.java +++ b/jdbc/src/test/java/tech/ydb/jdbc/YdbDriverOlapTablesTest.java @@ -27,7 +27,9 @@ public class YdbDriverOlapTablesTest { @RegisterExtension private static final YdbHelperExtension ydb = new YdbHelperExtension(); - private static final JdbcUrlHelper jdbcURL = new JdbcUrlHelper(ydb); + private static final JdbcUrlHelper jdbcURL = new JdbcUrlHelper(ydb) + .withArg("enableTxTracer", "true") + .withArg("usePrefixPath", "jdbc_olap"); private final static String ERROR_DATA_MANIPULATION = "Data manipulation queries do not support column shard tables. (S_ERROR)"; @@ -40,19 +42,19 @@ public class YdbDriverOlapTablesTest { "BULK mode is available only for prepared statement with one UPSERT"; private final static String CREATE_TABLE = "" - + "CREATE TABLE olap_table(" + + "CREATE TABLE table(" + " id Int32 NOT NULL," + " value Text," + " date Date," + " PRIMARY KEY (id)" + ") WITH (STORE = COLUMN)"; - private final static String DROP_TABLE = "DROP TABLE olap_table"; - private final static String UPSERT_ROW = "UPSERT INTO olap_table (id, value, date) VALUES (?, ?, ?)"; - private final static String INSERT_ROW = "INSERT INTO olap_table (id, value, date) VALUES (?, ?, ?)"; - private final static String SELECT_ALL = "SELECT * FROM olap_table ORDER BY id"; - private final static String UPDATE_ROW = "UPDATE olap_table SET value = ? WHERE id = ?"; - private final static String DELETE_ROW = "DELETE FROM olap_table WHERE id = ?"; + private final static String DROP_TABLE = "DROP TABLE table"; + private final static String UPSERT_ROW = "UPSERT INTO table (id, value, date) VALUES (?, ?, ?)"; + private final static String INSERT_ROW = "INSERT INTO table (id, value, date) VALUES (?, ?, ?)"; + private final static String SELECT_ALL = "SELECT * FROM table ORDER BY id"; + private final static String UPDATE_ROW = "UPDATE table SET value = ? WHERE id = ?"; + private final static String DELETE_ROW = "DELETE FROM table WHERE id = ?"; @Test public void defaultModeTest() throws SQLException { @@ -326,4 +328,132 @@ public void forceScanAndBulkTest() throws SQLException { } } } + + @Test + public void streamResultsTest() throws SQLException { + try (Connection conn = DriverManager.getConnection(jdbcURL + .withArg("useQueryService", "true") + .withArg("useStreamResultSets", "true") + .build() + )) { + try { + conn.createStatement().execute(DROP_TABLE); + } catch (SQLException e) { + // ignore +} + + conn.createStatement().execute(CREATE_TABLE); + + LocalDate ld = LocalDate.of(2017, 12, 3); + String prefix = "text-value-"; + int idx = 0; + + // single batch upsert + try (PreparedStatement ps = conn.prepareStatement(UPSERT_ROW)) { + ps.setInt(1, ++idx); + ps.setString(2, prefix + idx); + ps.setDate(3, Date.valueOf(ld.plusDays(idx))); + ps.executeUpdate(); + } + + // single batch insert + try (PreparedStatement ps = conn.prepareStatement(INSERT_ROW)) { + ps.setInt(1, ++idx); + ps.setString(2, prefix + idx); + ps.setDate(3, Date.valueOf(ld.plusDays(idx))); + ps.executeUpdate(); + } + + // stream read + try (Statement st = conn.createStatement()) { + int readed = 0; + try (ResultSet rs = st.executeQuery(SELECT_ALL)) { + while (rs.next()) { + readed++; + Assertions.assertEquals(readed, rs.getInt("id")); + Assertions.assertEquals(prefix + readed, rs.getString("value")); + Assertions.assertEquals(Date.valueOf(ld.plusDays(readed)), rs.getDate("date")); + } + } + Assertions.assertEquals(2, readed); + } + + // batch upsert + try (PreparedStatement ps = conn.prepareStatement(UPSERT_ROW)) { + for (int j = 0; j < 2000; j++) { + ps.setInt(1, ++idx); + ps.setString(2, prefix + idx); + ps.setDate(3, Date.valueOf(ld.plusDays(idx))); + ps.addBatch(); + } + ps.executeBatch(); + + // single row upsert + ps.setInt(1, ++idx); + ps.setString(2, prefix + idx); + ps.setDate(3, Date.valueOf(ld.plusDays(idx))); + ps.execute(); + + for (int j = 0; j < 2000; j++) { + ps.setInt(1, ++idx); + ps.setString(2, prefix + idx); + ps.setDate(3, Date.valueOf(ld.plusDays(idx))); + ps.addBatch(); + } + ps.executeBatch(); + } + + // batch inserts + try (PreparedStatement ps = conn.prepareStatement(INSERT_ROW)) { + for (int j = 0; j < 2000; j++) { + ps.setInt(1, ++idx); + ps.setString(2, prefix + idx); + ps.setDate(3, Date.valueOf(ld.plusDays(idx))); + ps.addBatch(); + } + ps.executeBatch(); + + // single row insert + ps.setInt(1, ++idx); + ps.setString(2, prefix + idx); + ps.setDate(3, Date.valueOf(ld.plusDays(idx))); + ps.execute(); + + for (int j = 0; j < 2000; j++) { + ps.setInt(1, ++idx); + ps.setString(2, prefix + idx); + ps.setDate(3, Date.valueOf(ld.plusDays(idx))); + ps.addBatch(); + } + ps.executeBatch(); + } + + // read all + try (Statement st = conn.createStatement()) { + int readed = 0; + try (ResultSet rs = st.executeQuery(SELECT_ALL)) { + while (rs.next()) { + readed++; + Assertions.assertEquals(readed, rs.getInt("id")); + Assertions.assertEquals(prefix + readed, rs.getString("value")); + Assertions.assertEquals(Date.valueOf(ld.plusDays(readed)), rs.getDate("date")); + } + } + Assertions.assertEquals(8004, readed); + } + + // single update + try (PreparedStatement ps = conn.prepareStatement(UPDATE_ROW)) { + ps.setString(1, "updated-value"); + ps.setInt(2, 1); + ps.executeUpdate(); + } + + // single delete + try (PreparedStatement ps = conn.prepareStatement(DELETE_ROW)) { + ps.setInt(1, 2); + ps.executeUpdate(); + } + } + } } diff --git a/jdbc/src/test/java/tech/ydb/jdbc/YdbDriverTablesTest.java b/jdbc/src/test/java/tech/ydb/jdbc/YdbDriverTablesTest.java index 9ea164b..f811789 100644 --- a/jdbc/src/test/java/tech/ydb/jdbc/YdbDriverTablesTest.java +++ b/jdbc/src/test/java/tech/ydb/jdbc/YdbDriverTablesTest.java @@ -34,19 +34,19 @@ public class YdbDriverTablesTest { "BULK mode is available only for prepared statement with one UPSERT"; private final static String CREATE_TABLE = "" - + "CREATE TABLE simple_table (" + + "CREATE TABLE table (" + " id Int32 NOT NULL," + " value Text," + " date Date," + " PRIMARY KEY (id)" + ")"; - private final static String DROP_TABLE = "DROP TABLE simple_table"; - private final static String UPSERT_ROW = "UPSERT INTO simple_table (id, value, date) VALUES (?, ?, ?)"; - private final static String INSERT_ROW = "INSERT INTO simple_table (id, value, date) VALUES (?, ?, ?)"; - private final static String SELECT_ALL = "SELECT * FROM simple_table ORDER BY id"; - private final static String UPDATE_ROW = "UPDATE simple_table SET value = ? WHERE id = ?"; - private final static String DELETE_ROW = "DELETE FROM simple_table WHERE id = ?"; + private final static String DROP_TABLE = "DROP TABLE table"; + private final static String UPSERT_ROW = "UPSERT INTO table (id, value, date) VALUES (?, ?, ?)"; + private final static String INSERT_ROW = "INSERT INTO table (id, value, date) VALUES (?, ?, ?)"; + private final static String SELECT_ALL = "SELECT * FROM table ORDER BY id"; + private final static String UPDATE_ROW = "UPDATE table SET value = ? WHERE id = ?"; + private final static String DELETE_ROW = "DELETE FROM table WHERE id = ?"; @Test public void defaultModeTest() throws SQLException { diff --git a/jdbc/src/test/java/tech/ydb/jdbc/impl/YdbQueryConnectionImplTest.java b/jdbc/src/test/java/tech/ydb/jdbc/impl/YdbQueryConnectionImplTest.java index bc1eb65..678867c 100644 --- a/jdbc/src/test/java/tech/ydb/jdbc/impl/YdbQueryConnectionImplTest.java +++ b/jdbc/src/test/java/tech/ydb/jdbc/impl/YdbQueryConnectionImplTest.java @@ -18,7 +18,6 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; @@ -691,7 +690,6 @@ public void testMixedStatements() throws SQLException { } @Test - @Disabled // https://github.com/ydb-platform/ydb/issues/6699 public void testReturingStatements() throws SQLException { String returningQuery = QUERIES.withTableName("" + "INSERT INTO #tableName (key, c_Text) VALUES (1, '123') RETURNING key;\n" diff --git a/pom.xml b/pom.xml index 17e80c3..02a068f 100644 --- a/pom.xml +++ b/pom.xml @@ -20,7 +20,7 @@ 1.7.36 5.9.3 - 2.3.1 + 2.3.3