Skip to content

Commit 6e4043a

Browse files
authored
Upgrade to Java SDK 2.3.3 (#79)
2 parents 1851089 + ee2d53a commit 6e4043a

File tree

5 files changed

+147
-19
lines changed

5 files changed

+147
-19
lines changed

jdbc/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
<argLine>@{argLine} -Duser.timezone=GMT-04</argLine>
7777
<environmentVariables>
7878
<TESTCONTAINERS_REUSE_ENABLE>true</TESTCONTAINERS_REUSE_ENABLE>
79-
<YDB_DOCKER_IMAGE>cr.yandex/yc/yandex-docker-local-ydb:trunk</YDB_DOCKER_IMAGE>
79+
<YDB_DOCKER_IMAGE>ydbplatform/local-ydb:trunk</YDB_DOCKER_IMAGE>
8080
</environmentVariables>
8181
<systemPropertyVariables>
8282
<java.util.logging.config.file>src/test/resources/logging.properties</java.util.logging.config.file>

jdbc/src/test/java/tech/ydb/jdbc/YdbDriverOlapTablesTest.java

Lines changed: 138 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ public class YdbDriverOlapTablesTest {
2727
@RegisterExtension
2828
private static final YdbHelperExtension ydb = new YdbHelperExtension();
2929

30-
private static final JdbcUrlHelper jdbcURL = new JdbcUrlHelper(ydb);
30+
private static final JdbcUrlHelper jdbcURL = new JdbcUrlHelper(ydb)
31+
.withArg("enableTxTracer", "true")
32+
.withArg("usePrefixPath", "jdbc_olap");
3133

3234
private final static String ERROR_DATA_MANIPULATION =
3335
"Data manipulation queries do not support column shard tables. (S_ERROR)";
@@ -40,19 +42,19 @@ public class YdbDriverOlapTablesTest {
4042
"BULK mode is available only for prepared statement with one UPSERT";
4143

4244
private final static String CREATE_TABLE = ""
43-
+ "CREATE TABLE olap_table("
45+
+ "CREATE TABLE table("
4446
+ " id Int32 NOT NULL,"
4547
+ " value Text,"
4648
+ " date Date,"
4749
+ " PRIMARY KEY (id)"
4850
+ ") WITH (STORE = COLUMN)";
4951

50-
private final static String DROP_TABLE = "DROP TABLE olap_table";
51-
private final static String UPSERT_ROW = "UPSERT INTO olap_table (id, value, date) VALUES (?, ?, ?)";
52-
private final static String INSERT_ROW = "INSERT INTO olap_table (id, value, date) VALUES (?, ?, ?)";
53-
private final static String SELECT_ALL = "SELECT * FROM olap_table ORDER BY id";
54-
private final static String UPDATE_ROW = "UPDATE olap_table SET value = ? WHERE id = ?";
55-
private final static String DELETE_ROW = "DELETE FROM olap_table WHERE id = ?";
52+
private final static String DROP_TABLE = "DROP TABLE table";
53+
private final static String UPSERT_ROW = "UPSERT INTO table (id, value, date) VALUES (?, ?, ?)";
54+
private final static String INSERT_ROW = "INSERT INTO table (id, value, date) VALUES (?, ?, ?)";
55+
private final static String SELECT_ALL = "SELECT * FROM table ORDER BY id";
56+
private final static String UPDATE_ROW = "UPDATE table SET value = ? WHERE id = ?";
57+
private final static String DELETE_ROW = "DELETE FROM table WHERE id = ?";
5658

5759
@Test
5860
public void defaultModeTest() throws SQLException {
@@ -326,4 +328,132 @@ public void forceScanAndBulkTest() throws SQLException {
326328
}
327329
}
328330
}
331+
332+
@Test
333+
public void streamResultsTest() throws SQLException {
334+
try (Connection conn = DriverManager.getConnection(jdbcURL
335+
.withArg("useQueryService", "true")
336+
.withArg("useStreamResultSets", "true")
337+
.build()
338+
)) {
339+
try {
340+
conn.createStatement().execute(DROP_TABLE);
341+
} catch (SQLException e) {
342+
// ignore
343+
}
344+
345+
conn.createStatement().execute(CREATE_TABLE);
346+
347+
LocalDate ld = LocalDate.of(2017, 12, 3);
348+
String prefix = "text-value-";
349+
int idx = 0;
350+
351+
// single batch upsert
352+
try (PreparedStatement ps = conn.prepareStatement(UPSERT_ROW)) {
353+
ps.setInt(1, ++idx);
354+
ps.setString(2, prefix + idx);
355+
ps.setDate(3, Date.valueOf(ld.plusDays(idx)));
356+
ps.executeUpdate();
357+
}
358+
359+
// single batch insert
360+
try (PreparedStatement ps = conn.prepareStatement(INSERT_ROW)) {
361+
ps.setInt(1, ++idx);
362+
ps.setString(2, prefix + idx);
363+
ps.setDate(3, Date.valueOf(ld.plusDays(idx)));
364+
ps.executeUpdate();
365+
}
366+
367+
// stream read
368+
try (Statement st = conn.createStatement()) {
369+
int readed = 0;
370+
try (ResultSet rs = st.executeQuery(SELECT_ALL)) {
371+
while (rs.next()) {
372+
readed++;
373+
Assertions.assertEquals(readed, rs.getInt("id"));
374+
Assertions.assertEquals(prefix + readed, rs.getString("value"));
375+
Assertions.assertEquals(Date.valueOf(ld.plusDays(readed)), rs.getDate("date"));
376+
}
377+
}
378+
Assertions.assertEquals(2, readed);
379+
}
380+
381+
// batch upsert
382+
try (PreparedStatement ps = conn.prepareStatement(UPSERT_ROW)) {
383+
for (int j = 0; j < 2000; j++) {
384+
ps.setInt(1, ++idx);
385+
ps.setString(2, prefix + idx);
386+
ps.setDate(3, Date.valueOf(ld.plusDays(idx)));
387+
ps.addBatch();
388+
}
389+
ps.executeBatch();
390+
391+
// single row upsert
392+
ps.setInt(1, ++idx);
393+
ps.setString(2, prefix + idx);
394+
ps.setDate(3, Date.valueOf(ld.plusDays(idx)));
395+
ps.execute();
396+
397+
for (int j = 0; j < 2000; j++) {
398+
ps.setInt(1, ++idx);
399+
ps.setString(2, prefix + idx);
400+
ps.setDate(3, Date.valueOf(ld.plusDays(idx)));
401+
ps.addBatch();
402+
}
403+
ps.executeBatch();
404+
}
405+
406+
// batch inserts
407+
try (PreparedStatement ps = conn.prepareStatement(INSERT_ROW)) {
408+
for (int j = 0; j < 2000; j++) {
409+
ps.setInt(1, ++idx);
410+
ps.setString(2, prefix + idx);
411+
ps.setDate(3, Date.valueOf(ld.plusDays(idx)));
412+
ps.addBatch();
413+
}
414+
ps.executeBatch();
415+
416+
// single row insert
417+
ps.setInt(1, ++idx);
418+
ps.setString(2, prefix + idx);
419+
ps.setDate(3, Date.valueOf(ld.plusDays(idx)));
420+
ps.execute();
421+
422+
for (int j = 0; j < 2000; j++) {
423+
ps.setInt(1, ++idx);
424+
ps.setString(2, prefix + idx);
425+
ps.setDate(3, Date.valueOf(ld.plusDays(idx)));
426+
ps.addBatch();
427+
}
428+
ps.executeBatch();
429+
}
430+
431+
// read all
432+
try (Statement st = conn.createStatement()) {
433+
int readed = 0;
434+
try (ResultSet rs = st.executeQuery(SELECT_ALL)) {
435+
while (rs.next()) {
436+
readed++;
437+
Assertions.assertEquals(readed, rs.getInt("id"));
438+
Assertions.assertEquals(prefix + readed, rs.getString("value"));
439+
Assertions.assertEquals(Date.valueOf(ld.plusDays(readed)), rs.getDate("date"));
440+
}
441+
}
442+
Assertions.assertEquals(8004, readed);
443+
}
444+
445+
// single update
446+
try (PreparedStatement ps = conn.prepareStatement(UPDATE_ROW)) {
447+
ps.setString(1, "updated-value");
448+
ps.setInt(2, 1);
449+
ps.executeUpdate();
450+
}
451+
452+
// single delete
453+
try (PreparedStatement ps = conn.prepareStatement(DELETE_ROW)) {
454+
ps.setInt(1, 2);
455+
ps.executeUpdate();
456+
}
457+
}
458+
}
329459
}

jdbc/src/test/java/tech/ydb/jdbc/YdbDriverTablesTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,19 @@ public class YdbDriverTablesTest {
3434
"BULK mode is available only for prepared statement with one UPSERT";
3535

3636
private final static String CREATE_TABLE = ""
37-
+ "CREATE TABLE simple_table ("
37+
+ "CREATE TABLE table ("
3838
+ " id Int32 NOT NULL,"
3939
+ " value Text,"
4040
+ " date Date,"
4141
+ " PRIMARY KEY (id)"
4242
+ ")";
4343

44-
private final static String DROP_TABLE = "DROP TABLE simple_table";
45-
private final static String UPSERT_ROW = "UPSERT INTO simple_table (id, value, date) VALUES (?, ?, ?)";
46-
private final static String INSERT_ROW = "INSERT INTO simple_table (id, value, date) VALUES (?, ?, ?)";
47-
private final static String SELECT_ALL = "SELECT * FROM simple_table ORDER BY id";
48-
private final static String UPDATE_ROW = "UPDATE simple_table SET value = ? WHERE id = ?";
49-
private final static String DELETE_ROW = "DELETE FROM simple_table WHERE id = ?";
44+
private final static String DROP_TABLE = "DROP TABLE table";
45+
private final static String UPSERT_ROW = "UPSERT INTO table (id, value, date) VALUES (?, ?, ?)";
46+
private final static String INSERT_ROW = "INSERT INTO table (id, value, date) VALUES (?, ?, ?)";
47+
private final static String SELECT_ALL = "SELECT * FROM table ORDER BY id";
48+
private final static String UPDATE_ROW = "UPDATE table SET value = ? WHERE id = ?";
49+
private final static String DELETE_ROW = "DELETE FROM table WHERE id = ?";
5050

5151
@Test
5252
public void defaultModeTest() throws SQLException {

jdbc/src/test/java/tech/ydb/jdbc/impl/YdbQueryConnectionImplTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import org.junit.jupiter.api.Assertions;
1919
import org.junit.jupiter.api.BeforeAll;
2020
import org.junit.jupiter.api.BeforeEach;
21-
import org.junit.jupiter.api.Disabled;
2221
import org.junit.jupiter.api.DisplayName;
2322
import org.junit.jupiter.api.Test;
2423
import org.junit.jupiter.api.Timeout;
@@ -691,7 +690,6 @@ public void testMixedStatements() throws SQLException {
691690
}
692691

693692
@Test
694-
@Disabled // https://github.com/ydb-platform/ydb/issues/6699
695693
public void testReturingStatements() throws SQLException {
696694
String returningQuery = QUERIES.withTableName(""
697695
+ "INSERT INTO #tableName (key, c_Text) VALUES (1, '123') RETURNING key;\n"

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<slf4j.version>1.7.36</slf4j.version>
2121
<junit.version>5.9.3</junit.version>
2222

23-
<ydb.sdk.version>2.3.1</ydb.sdk.version>
23+
<ydb.sdk.version>2.3.3</ydb.sdk.version>
2424
</properties>
2525

2626
<licenses>

0 commit comments

Comments
 (0)