-
Notifications
You must be signed in to change notification settings - Fork 614
Closed
Labels
Description
Describe the bug
I noticed that if the table schema has a Default column with a Hash function, that hash function or any other functions are not executed on the server side.
Steps to reproduce
- Create a simple schema as shown below.
CREATE TABLE exp.student (
name String,
age Int64,
marks Int64 DEFAULT 10,
fingerPrint UInt64 DEFAULT xxHash64(name)
) ENGINE = MergeTree()
ORDER BY name;- Using the below Java client v2 code, I am inserting a record single record with only name and age. The expectation is that the server should update the marks with 10 and for fingerPrint, the server should generate a xxHash64 using the name. But I see 0 values in the table.
Client clickHouseClient = new Client.Builder().addEndpoint("http://localhost:8123").setUsername("default").setPassword(new String("")).compressServerResponse(false).build();
String tableName = "exp.student";
clickHouseClient.register(Student.class, clickHouseClient.getTableSchema(tableName));
Student s1 = new Student();
s1.setAge(18);
s1.setName("Bob");
List<Student> studentList = new ArrayList<>();
studentList.add(s1);
try (InsertResponse response = clickHouseClient.insert(tableName, studentList, new InsertSettings()).get()) {
System.out.println("Inseted.");
} catch (Exception e) {
System.out.println("Failed to write to table " + tableName);
}- Below is the output from the select * from exp.student table.
ch-1S_1K :) select * from exp.student;
SELECT *
FROM exp.student
Query id: 02196a52-c200-4757-b91c-05a9a36e9d7d
┌─name─┬─age─┬─marks─┬─fingerPrint─┐
1. │ Bob │ 18 │ 0 │ 0 │
└──────┴─────┴───────┴─────────────┘
1 row in set. Elapsed: 0.008 sec.
ch-1S_1K :) - But If I use the insert command via clickhouse client it works. There is an issue with the clickhouse java v2 client.
ch-1S_1K :) INSERT INTO exp.student (name, age) VALUES ('Alice', 20);
INSERT INTO exp.student (name, age) FORMAT Values
Query id: d802feb3-2364-435e-a567-ce549fb8703c
Ok.
1 row in set. Elapsed: 0.008 sec.
ch-1S_1K :) select * from exp.student;
SELECT *
FROM exp.student
Query id: 15de2f65-b13f-43a6-ad23-26db7fbab695
┌─name─┬─age─┬─marks─┬─fingerPrint─┐
1. │ Bob │ 18 │ 0 │ 0 │
└──────┴─────┴───────┴─────────────┘
┌─name──┬─age─┬─marks─┬──────────fingerPrint─┐
2. │ Alice │ 20 │ 10 │ 15323875830165214731 │
└───────┴─────┴───────┴──────────────────────┘
2 rows in set. Elapsed: 0.024 sec.
ch-1S_1K :) Expected behaviour
The default value or the requested function has to be executed on the server side and that value has to be updated in the record.
Code example
Error log
No error log, below are the successful logs
2024.12.04 09:34:26.225027 [ 1558 ] {} <Debug> HTTP-Session: 66262d80-55b6-4f23-b22c-b55a367fe43b Authenticating user 'default' from 192.168.65.1:43269
2024.12.04 09:34:26.225081 [ 1558 ] {} <Debug> HTTP-Session: 66262d80-55b6-4f23-b22c-b55a367fe43b Authenticated with global context as user 94309d50-4f52-5250-31bd-74fecac179db
2024.12.04 09:34:26.225091 [ 1558 ] {} <Debug> HTTP-Session: 66262d80-55b6-4f23-b22c-b55a367fe43b Creating session context with user_id: 94309d50-4f52-5250-31bd-74fecac179db
2024.12.04 09:34:26.225315 [ 1558 ] {44c7fa95-bac7-4dcb-a473-44e1ebc3341d} <Debug> executeQuery: (from 192.168.65.1:43269) INSERT INTO exp.student FORMAT RowBinaryWithDefaults (stage: Complete)
2024.12.04 09:34:26.234399 [ 1558 ] {44c7fa95-bac7-4dcb-a473-44e1ebc3341d} <Debug> executeQuery: Read 1 rows, 38.00 B in 0.009127 sec., 109.56502684343158 rows/sec., 4.07 KiB/sec.
2024.12.04 09:34:26.234974 [ 1558 ] {44c7fa95-bac7-4dcb-a473-44e1ebc3341d} <Debug> DynamicQueryHandler: Done processing query
2024.12.04 09:34:26.235024 [ 1558 ] {} <Debug> HTTP-Session: 66262d80-55b6-4f23-b22c-b55a367fe43b Logout, user_id: 94309d50-4f52-5250-31bd-74fecac179db
Configuration
Environment
- Clickhouse Client version: ClickHouse local version 24.9.1.2573 (official build)
- Client Language version: Java 17. The latest 0.7.1-patch1 jar version and 0.7.0 version were used and issue is seen in both.
- OS: Mac OS 14.5 (23F79)
ClickHouse server
- ClickHouse Server version: Connected to ClickHouse server version 24.8.4.
- ClickHouse Server non-default settings, if any:
CREATE TABLEstatements for tables involved:- Sample data for all these tables, use clickhouse-obfuscator if necessary