@@ -1233,6 +1233,38 @@ public void testNonBatchUpdate(String mode, String query) throws SQLException {
12331233 }
12341234 }
12351235
1236+ @ Test (groups = "integration" )
1237+ public void testInsertAggregateFunction () throws SQLException {
1238+ // https://kb.altinity.com/altinity-kb-schema-design/ingestion-aggregate-function/
1239+ Properties props = new Properties ();
1240+ try (ClickHouseConnection conn = newConnection (props );
1241+ Statement s = conn .createStatement ();
1242+ PreparedStatement ps = conn .prepareStatement (
1243+ "insert into test_insert_aggregate_function SELECT uid, updated, arrayReduce('argMaxState', [name], [updated]) "
1244+ + "FROM input('uid Int16, updated DateTime, name String')" )) {
1245+ s .execute ("drop table if exists test_insert_aggregate_function;"
1246+ + "CREATE TABLE test_insert_aggregate_function (uid Int16, updated SimpleAggregateFunction(max, DateTime), "
1247+ + "name AggregateFunction(argMax, String, DateTime)) ENGINE=AggregatingMergeTree order by uid" );
1248+ ps .setInt (1 , 1 );
1249+ ps .setString (2 , "2020-01-02 00:00:00" );
1250+ ps .setString (3 , "b" );
1251+ ps .addBatch ();
1252+ ps .setInt (1 , 1 );
1253+ ps .setString (2 , "2020-01-01 00:00:00" );
1254+ ps .setString (3 , "a" );
1255+ ps .addBatch ();
1256+ ps .executeBatch ();
1257+ try (ResultSet rs = s .executeQuery (
1258+ "select uid, max(updated) AS updated, argMaxMerge(name) from test_insert_aggregate_function group by uid" )) {
1259+ Assert .assertTrue (rs .next ());
1260+ Assert .assertEquals (rs .getInt (1 ), 1 );
1261+ Assert .assertEquals (rs .getString (2 ), "2020-01-02 00:00:00" );
1262+ Assert .assertEquals (rs .getString (3 ), "b" );
1263+ Assert .assertFalse (rs .next ());
1264+ }
1265+ }
1266+ }
1267+
12361268 @ Test (groups = "integration" )
12371269 public void testInsertByteArray () throws SQLException {
12381270 Properties props = new Properties ();
@@ -1257,6 +1289,34 @@ public void testInsertByteArray() throws SQLException {
12571289 }
12581290 }
12591291
1292+ @ Test (groups = "integration" )
1293+ public void testInsertDefaultValue () throws SQLException {
1294+ Properties props = new Properties ();
1295+ try (ClickHouseConnection conn = newConnection (props );
1296+ Statement s = conn .createStatement ();
1297+ PreparedStatement ps = conn .prepareStatement (
1298+ "insert into test_insert_default_value select id, name from input('id UInt32, name Nullable(String)')" )) {
1299+ s .execute ("drop table if exists test_insert_default_value;"
1300+ + "create table test_insert_default_value(n Int32, s String DEFAULT 'secret') engine=Memory" );
1301+ ps .setInt (1 , 1 );
1302+ ps .setString (2 , null );
1303+ ps .addBatch ();
1304+ ps .setInt (1 , -1 );
1305+ ps .setNull (2 , Types .ARRAY );
1306+ ps .addBatch ();
1307+ ps .executeBatch ();
1308+ try (ResultSet rs = s .executeQuery ("select * from test_insert_default_value order by n" )) {
1309+ Assert .assertTrue (rs .next ());
1310+ Assert .assertEquals (rs .getInt (1 ), -1 );
1311+ Assert .assertEquals (rs .getString (2 ), "secret" );
1312+ Assert .assertTrue (rs .next ());
1313+ Assert .assertEquals (rs .getInt (1 ), 1 );
1314+ Assert .assertEquals (rs .getString (2 ), "secret" );
1315+ Assert .assertFalse (rs .next ());
1316+ }
1317+ }
1318+ }
1319+
12601320 @ Test (groups = "integration" )
12611321 public void testOutFileAndInFile () throws SQLException {
12621322 if (DEFAULT_PROTOCOL != ClickHouseProtocol .HTTP ) {
0 commit comments