|
74 | 74 | import java.util.Random; |
75 | 75 | import java.util.Set; |
76 | 76 | import java.util.UUID; |
77 | | -import java.util.concurrent.CountDownLatch; |
78 | | -import java.util.concurrent.ExecutionException; |
79 | | -import java.util.concurrent.ExecutorService; |
80 | | -import java.util.concurrent.Executors; |
81 | | -import java.util.concurrent.Future; |
82 | | -import java.util.concurrent.TimeUnit; |
| 77 | +import java.util.concurrent.*; |
83 | 78 | import java.util.concurrent.atomic.AtomicInteger; |
84 | 79 | import java.util.function.Consumer; |
85 | 80 | import java.util.function.Function; |
@@ -1562,6 +1557,38 @@ public void testQueryParams() throws Exception { |
1562 | 1557 | Assert.assertEquals(allRecords.size(), 2); |
1563 | 1558 | } |
1564 | 1559 |
|
| 1560 | + @Test(groups = {"integration"}) |
| 1561 | + public void testExecuteQueryParam() throws ExecutionException, InterruptedException, TimeoutException { |
| 1562 | + |
| 1563 | + final String table = "execute_query_test"; |
| 1564 | + Map<String, Object> query_param = new HashMap<>(); |
| 1565 | + query_param.put("table_name",table); |
| 1566 | + query_param.put("engine","MergeTree"); |
| 1567 | + client.execute("DROP TABLE IF EXISTS " + table).get(10, TimeUnit.SECONDS); |
| 1568 | + client.execute("CREATE TABLE {table_name:Identifier} ( id UInt32, name String, created_at DateTime) ENGINE = MergeTree ORDER BY tuple()", query_param) |
| 1569 | + .get(10, TimeUnit.SECONDS); |
| 1570 | + |
| 1571 | + TableSchema schema = client.getTableSchema(table); |
| 1572 | + Assert.assertNotNull(schema); |
| 1573 | + } |
| 1574 | + |
| 1575 | + @Test(groups = {"integration"}) |
| 1576 | + public void testExecuteQueryParamCommandSettings() throws ExecutionException, InterruptedException, TimeoutException { |
| 1577 | + |
| 1578 | + final String table = "execute_query_test"; |
| 1579 | + String q1Id = UUID.randomUUID().toString(); |
| 1580 | + Map<String, Object> query_param = new HashMap<>(); |
| 1581 | + query_param.put("table_name",table); |
| 1582 | + query_param.put("engine","MergeTree"); |
| 1583 | + client.execute("DROP TABLE IF EXISTS " + table).get(10, TimeUnit.SECONDS); |
| 1584 | + client.execute("CREATE TABLE {table_name:Identifier} ( id UInt32, name String, created_at DateTime) ENGINE = MergeTree ORDER BY tuple()", |
| 1585 | + query_param, (CommandSettings) new CommandSettings().setQueryId(q1Id)) |
| 1586 | + .get(10, TimeUnit.SECONDS); |
| 1587 | + |
| 1588 | + TableSchema schema = client.getTableSchema(table); |
| 1589 | + Assert.assertNotNull(schema); |
| 1590 | + } |
| 1591 | + |
1565 | 1592 | @Test(groups = {"integration"}) |
1566 | 1593 | public void testGetTableSchema() throws Exception { |
1567 | 1594 |
|
@@ -1985,6 +2012,31 @@ public void testReadingSimpleAggregateFunction() throws Exception { |
1985 | 2012 | } |
1986 | 2013 | } |
1987 | 2014 |
|
| 2015 | + @Test(groups = {"integration"}) |
| 2016 | + public void testReadingSimpleAggregateFunction2() throws Exception { |
| 2017 | + final String tableName = "simple_aggregate_function_test_table"; |
| 2018 | + client.execute("DROP TABLE IF EXISTS " + tableName).get(); |
| 2019 | + client.execute("CREATE TABLE `" + tableName + "` " + |
| 2020 | + "(idx UInt8, lowest_value SimpleAggregateFunction(min, UInt8), count SimpleAggregateFunction(sum, Int64), date SimpleAggregateFunction(anyLast, DateTime32)) " + |
| 2021 | + "ENGINE Memory;").get(); |
| 2022 | + |
| 2023 | + |
| 2024 | + try (InsertResponse response = client.insert(tableName, new ByteArrayInputStream("1\t2\t3\t2024-12-22T12:00:00".getBytes(StandardCharsets.UTF_8)), ClickHouseFormat.TSV).get(30, TimeUnit.SECONDS)) { |
| 2025 | + Assert.assertEquals(response.getWrittenRows(), 1); |
| 2026 | + } |
| 2027 | + |
| 2028 | + try (QueryResponse queryResponse = client.query("SELECT * FROM " + tableName + " LIMIT 1").get(30, TimeUnit.SECONDS)) { |
| 2029 | + |
| 2030 | + ClickHouseBinaryFormatReader reader = client.newBinaryFormatReader(queryResponse); |
| 2031 | + Assert.assertNotNull(reader.next()); |
| 2032 | + Assert.assertEquals(reader.getByte("idx"), Byte.valueOf("1")); |
| 2033 | + Assert.assertEquals((Short) reader.getShort("lowest_value"), Short.parseShort("2")); |
| 2034 | + Assert.assertEquals((Long) reader.getLong("count"), Long.parseLong("3")); |
| 2035 | + Assert.assertEquals(reader.getLocalDateTime("date"), LocalDateTime.of(2024,12,22,12,00,00)); |
| 2036 | + Assert.assertFalse(reader.hasNext()); |
| 2037 | + } |
| 2038 | + } |
| 2039 | + |
1988 | 2040 | @Test(groups = {"integration"}) |
1989 | 2041 | public void testReadingEnumsAsStrings() throws Exception { |
1990 | 2042 | final String tableName = "enums_as_strings_test_table"; |
|
0 commit comments