@@ -1410,93 +1410,55 @@ public static void test_appender_list_basic_nested_list() throws Exception {
14101410 }
14111411 }
14121412
1413- private static void assertMapsEqual (Object obj1 , Map <?, ?> map2 ) throws Exception {
1414- Map <?, ?> map1 = (Map <?, ?>) obj1 ;
1415- assertEquals (map1 .size (), map2 .size ());
1416- List <Map .Entry <?, ?>> list2 = new ArrayList <>(map2 .entrySet ());
1417- int i = 0 ;
1418- for (Map .Entry <?, ?> en : map1 .entrySet ()) {
1419- assertEquals (en .getKey (), list2 .get (i ).getKey ());
1420- assertEquals (en .getValue (), list2 .get (i ).getValue ());
1421- i += 1 ;
1422- }
1423- }
1413+ public static void test_appender_list_bigint () throws Exception {
1414+ int count = 1 << 12 ; // auto flush twice
1415+ int tail = 7 ; // flushed on close
1416+ int listLen = (1 << 6 ) + 7 ; // increase this for stress tests
14241417
1425- public static void test_appender_map_basic () throws Exception {
1426- Map <Integer , String > map1 = createMap (41 , "foo" , 42 , "bar" );
1427- Map <Integer , String > map2 = createMap (41 , "foo" , 42 , null , 43 , "baz" );
14281418 try (DuckDBConnection conn = DriverManager .getConnection (JDBC_URL ).unwrap (DuckDBConnection .class );
14291419 Statement stmt = conn .createStatement ()) {
1430- stmt .execute ("CREATE TABLE tab1(col1 INTEGER, col2 MAP(INTEGER, VARCHAR) )" );
1420+ stmt .execute ("CREATE TABLE tab1(col1 INTEGER, col2 BIGINT[] )" );
14311421
14321422 try (DuckDBAppender appender = conn .createAppender ("tab1" )) {
1433- appender .beginRow ()
1434- .append (41 )
1435- .append (map1 )
1436- .endRow ()
1437- .beginRow ()
1438- .append (42 )
1439- .append (map2 )
1440- .endRow ()
1441- .flush ();
1423+ for (int i = 0 ; i < count + tail ; i ++) {
1424+ List <Long > list = new ArrayList <>();
1425+ for (long j = 0 ; j < Math .min (i , listLen ); j ++) {
1426+ if (0 == (i + j ) % 13 ) {
1427+ list .add (null );
1428+ } else {
1429+ list .add (i + j );
1430+ }
1431+ }
1432+ appender .beginRow ().append (i ).append (list ).endRow ();
1433+ }
14421434 }
14431435
1444- try (ResultSet rs = stmt .executeQuery ("SELECT col2 FROM tab1 ORDER BY col1" )) {
1445- assertTrue (rs .next ());
1446- assertMapsEqual (rs .getObject (1 ), map1 );
1436+ try (ResultSet rs = stmt .executeQuery ("SELECT count(*) FROM tab1" )) {
14471437 assertTrue (rs .next ());
1448- assertMapsEqual (rs .getObject (1 ), map2 );
1438+ assertEquals (rs .getInt (1 ), count + tail );
14491439 assertFalse (rs .next ());
14501440 }
1451- }
1452- }
1453-
1454- public static void test_appender_list_basic_map () throws Exception {
1455- Map <Integer , String > map1 = createMap (41 , "foo1" , 42 , "bar1" , 43 , "baz1" );
1456- Map <Integer , String > map2 = createMap (44 , null , 45 , "bar2" );
1457- Map <Integer , String > map3 = new LinkedHashMap <>();
1458- Map <Integer , String > map4 = createMap (46 , "foo3" );
1459- try (DuckDBConnection conn = DriverManager .getConnection (JDBC_URL ).unwrap (DuckDBConnection .class );
1460- Statement stmt = conn .createStatement ()) {
1461- stmt .execute ("CREATE TABLE tab1(col1 INT, col2 MAP(INTEGER, VARCHAR)[])" );
1462- try (DuckDBAppender appender = conn .createAppender ("tab1" )) {
1463- appender .beginRow ()
1464- .append (42 )
1465- .append (asList (map1 , map2 , map3 ))
1466- .endRow ()
1467- .beginRow ()
1468- .append (43 )
1469- .append ((List <Object >) null )
1470- .endRow ()
1471- .beginRow ()
1472- .append (44 )
1473- .append (asList (null , map4 ))
1474- .endRow ()
1475- .flush ();
1476- }
14771441
1478- try (ResultSet rs = stmt .executeQuery ("SELECT unnest(col2) from tab1 WHERE col1 = 42" )) {
1479- assertTrue (rs .next ());
1480- assertMapsEqual (rs .getObject (1 ), map1 );
1442+ try (ResultSet rs = stmt .executeQuery (
1443+ "SELECT count(*) FROM (SELECT unnest(col2) FROM tab1 WHERE col1 = " + (listLen - 7 ) + ")" )) {
14811444 assertTrue (rs .next ());
1482- assertMapsEqual (rs .getObject (1 ), map2 );
1483- assertTrue (rs .next ());
1484- assertMapsEqual (rs .getObject (1 ), map3 );
1485- assertFalse (rs .next ());
1486- }
1487- try (ResultSet rs = stmt .executeQuery ("SELECT col2 from tab1 WHERE col1 = 43" )) {
1488- assertTrue (rs .next ());
1489- assertNull (rs .getObject (1 ));
1490- assertTrue (rs .wasNull ());
1445+ assertEquals (rs .getInt (1 ), listLen - 7 );
14911446 assertFalse (rs .next ());
14921447 }
1493- try (ResultSet rs = stmt .executeQuery ("SELECT unnest(col2) from tab1 WHERE col1 = 44" )) {
1494- assertTrue (rs .next ());
1495- assertNull (rs .getObject (1 ));
1496- assertTrue (rs .wasNull ());
1497- assertTrue (rs .next ());
1498- assertMapsEqual (rs .getObject (1 ), map4 );
1499- assertFalse (rs .next ());
1448+
1449+ try (ResultSet rs = stmt .executeQuery ("SELECT col1, unnest(col2) FROM tab1 ORDER BY col1" )) {
1450+ for (int i = 0 ; i < count + tail ; i ++) {
1451+ for (long j = 0 ; j < Math .min (i , listLen ); j ++) {
1452+ assertTrue (rs .next ());
1453+ assertEquals (rs .getInt (1 ), i );
1454+ if (0 == (i + j ) % 13 ) {
1455+ assertNull (rs .getObject (2 ));
1456+ assertTrue (rs .wasNull ());
1457+ } else {
1458+ assertEquals (rs .getLong (2 ), i + j );
1459+ }
1460+ }
1461+ }
15001462 }
15011463 }
15021464 }
0 commit comments