Skip to content

Commit

Permalink
Merge pull request #1345 from zhicwu/main
Browse files Browse the repository at this point in the history
Add tests to cover insert AggregateFunction and column with default value
  • Loading branch information
zhicwu authored May 2, 2023
2 parents e9b9197 + e3d7847 commit a068fc7
Showing 1 changed file with 60 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1233,6 +1233,38 @@ public void testNonBatchUpdate(String mode, String query) throws SQLException {
}
}

@Test(groups = "integration")
public void testInsertAggregateFunction() throws SQLException {
// https://kb.altinity.com/altinity-kb-schema-design/ingestion-aggregate-function/
Properties props = new Properties();
try (ClickHouseConnection conn = newConnection(props);
Statement s = conn.createStatement();
PreparedStatement ps = conn.prepareStatement(
"insert into test_insert_aggregate_function SELECT uid, updated, arrayReduce('argMaxState', [name], [updated]) "
+ "FROM input('uid Int16, updated DateTime, name String')")) {
s.execute("drop table if exists test_insert_aggregate_function;"
+ "CREATE TABLE test_insert_aggregate_function (uid Int16, updated SimpleAggregateFunction(max, DateTime), "
+ "name AggregateFunction(argMax, String, DateTime)) ENGINE=AggregatingMergeTree order by uid");
ps.setInt(1, 1);
ps.setString(2, "2020-01-02 00:00:00");
ps.setString(3, "b");
ps.addBatch();
ps.setInt(1, 1);
ps.setString(2, "2020-01-01 00:00:00");
ps.setString(3, "a");
ps.addBatch();
ps.executeBatch();
try (ResultSet rs = s.executeQuery(
"select uid, max(updated) AS updated, argMaxMerge(name) from test_insert_aggregate_function group by uid")) {
Assert.assertTrue(rs.next());
Assert.assertEquals(rs.getInt(1), 1);
Assert.assertEquals(rs.getString(2), "2020-01-02 00:00:00");
Assert.assertEquals(rs.getString(3), "b");
Assert.assertFalse(rs.next());
}
}
}

@Test(groups = "integration")
public void testInsertByteArray() throws SQLException {
Properties props = new Properties();
Expand All @@ -1257,6 +1289,34 @@ public void testInsertByteArray() throws SQLException {
}
}

@Test(groups = "integration")
public void testInsertDefaultValue() throws SQLException {
Properties props = new Properties();
try (ClickHouseConnection conn = newConnection(props);
Statement s = conn.createStatement();
PreparedStatement ps = conn.prepareStatement(
"insert into test_insert_default_value select id, name from input('id UInt32, name Nullable(String)')")) {
s.execute("drop table if exists test_insert_default_value;"
+ "create table test_insert_default_value(n Int32, s String DEFAULT 'secret') engine=Memory");
ps.setInt(1, 1);
ps.setString(2, null);
ps.addBatch();
ps.setInt(1, -1);
ps.setNull(2, Types.ARRAY);
ps.addBatch();
ps.executeBatch();
try (ResultSet rs = s.executeQuery("select * from test_insert_default_value order by n")) {
Assert.assertTrue(rs.next());
Assert.assertEquals(rs.getInt(1), -1);
Assert.assertEquals(rs.getString(2), "secret");
Assert.assertTrue(rs.next());
Assert.assertEquals(rs.getInt(1), 1);
Assert.assertEquals(rs.getString(2), "secret");
Assert.assertFalse(rs.next());
}
}
}

@Test(groups = "integration")
public void testOutFileAndInFile() throws SQLException {
if (DEFAULT_PROTOCOL != ClickHouseProtocol.HTTP) {
Expand Down

0 comments on commit a068fc7

Please sign in to comment.