@@ -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}
0 commit comments