Skip to content
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

Upgrade to Java SDK 2.3.3 #79

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
<argLine>@{argLine} -Duser.timezone=GMT-04</argLine>
<environmentVariables>
<TESTCONTAINERS_REUSE_ENABLE>true</TESTCONTAINERS_REUSE_ENABLE>
<YDB_DOCKER_IMAGE>cr.yandex/yc/yandex-docker-local-ydb:trunk</YDB_DOCKER_IMAGE>
<YDB_DOCKER_IMAGE>ydbplatform/local-ydb:trunk</YDB_DOCKER_IMAGE>
</environmentVariables>
<systemPropertyVariables>
<java.util.logging.config.file>src/test/resources/logging.properties</java.util.logging.config.file>
Expand Down
146 changes: 138 additions & 8 deletions jdbc/src/test/java/tech/ydb/jdbc/YdbDriverOlapTablesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)";
Expand All @@ -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 {
Expand Down Expand Up @@ -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();
}
}
}
}
14 changes: 7 additions & 7 deletions jdbc/src/test/java/tech/ydb/jdbc/YdbDriverTablesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<slf4j.version>1.7.36</slf4j.version>
<junit.version>5.9.3</junit.version>

<ydb.sdk.version>2.3.1</ydb.sdk.version>
<ydb.sdk.version>2.3.3</ydb.sdk.version>
</properties>

<licenses>
Expand Down