11package com .clickhouse .jdbc ;
22
33import com .clickhouse .client .api .ClientConfigProperties ;
4+ import com .clickhouse .data .Tuple ;
45import org .slf4j .Logger ;
56import org .slf4j .LoggerFactory ;
67import org .testng .annotations .BeforeClass ;
@@ -455,7 +456,7 @@ public void testBooleanTypes() throws SQLException {
455456 @ Test (groups = { "integration" })
456457 public void testArrayTypes () throws SQLException {
457458 runQuery ("CREATE TABLE test_arrays (order Int8, "
458- + "array Array(Int8), arraystr Array(String)"
459+ + "array Array(Int8), arraystr Array(String), arraytuple Array(Tuple(Int8, String)) "
459460 + ") ENGINE = MergeTree ORDER BY ()" );
460461
461462 // Insert random (valid) values
@@ -473,11 +474,17 @@ public void testArrayTypes() throws SQLException {
473474 arraystr [i ] = "string" + rand .nextInt (1000 );
474475 }
475476
477+ Tuple [] arraytuple = new Tuple [rand .nextInt (10 ) + 1 ];
478+ for (int i = 0 ; i < arraytuple .length ; i ++) {
479+ arraytuple [i ] = new Tuple (rand .nextInt (256 ) - 128 , "string" + rand .nextInt (1000 ));
480+ }
481+
476482 // Insert random (valid) values
477483 try (Connection conn = getConnection ()) {
478- try (PreparedStatement stmt = conn .prepareStatement ("INSERT INTO test_arrays VALUES ( 1, ?, ? )" )) {
484+ try (PreparedStatement stmt = conn .prepareStatement ("INSERT INTO test_arrays VALUES ( 1, ?, ?, ? )" )) {
479485 stmt .setArray (1 , conn .createArrayOf ("Int8" , array ));
480486 stmt .setArray (2 , conn .createArrayOf ("String" , arraystr ));
487+ stmt .setArray (3 , conn .createArrayOf ("Tuple" , arraytuple ));
481488 stmt .executeUpdate ();
482489 }
483490 }
@@ -498,7 +505,14 @@ public void testArrayTypes() throws SQLException {
498505 for (int i = 0 ; i < arraystr .length ; i ++) {
499506 assertEquals (arraystrResult [i ], arraystr [i ]);
500507 }
501-
508+ Object [] arraytupleResult = (Object []) rs .getArray ("arraytuple" ).getArray ();
509+ assertEquals (arraytupleResult .length , arraytuple .length );
510+ for (int i = 0 ; i < arraytuple .length ; i ++) {
511+ Tuple tuple = arraytuple [i ];
512+ Tuple tupleResult = new Tuple (((Object []) arraytupleResult [i ]));
513+ assertEquals (String .valueOf (tupleResult .getValue (0 )), String .valueOf (tuple .getValue (0 )));
514+ assertEquals (String .valueOf (tupleResult .getValue (1 )), String .valueOf (tuple .getValue (1 )));
515+ }
502516 assertFalse (rs .next ());
503517 }
504518 }
0 commit comments