Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[client-v2] Java client-v2 doesn't support default functions like xxHash64 #1999

Open
nagavenkateshgowru opened this issue Dec 4, 2024 · 2 comments

Comments

@nagavenkateshgowru
Copy link

nagavenkateshgowru commented Dec 4, 2024

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

  1. 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;
  1. 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);
        }
  1. 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 :) 
  1. 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 TABLE statements for tables involved:
  • Sample data for all these tables, use clickhouse-obfuscator if necessary
@mshustov
Copy link
Member

mshustov commented Dec 4, 2024

client should use https://clickhouse.com/docs/en/interfaces/formats#rowbinarywithdefaults to support defaults

@nagavenkateshgowru
Copy link
Author

2024.12.04 09:34:26.225315 [ 1558 ] {44c7fa95-bac7-4dcb-a473-44e1ebc3341d} executeQuery: (from 192.168.65.1:43269) INSERT INTO exp.student FORMAT RowBinaryWithDefaults (stage: Complete)

From the log we can see, Java client-v2 by default uses RowBinaryWithDefaults format.

@chernser chernser changed the title Java client-v2 doesn't support default functions like xxHash64 [client-v2] Java client-v2 doesn't support default functions like xxHash64 Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants