vitaliis
vitaliis

Reputation: 4212

Get checksum (cityHash64) of first n rows of ClickHouse table

According to https://clickhouse.tech/docs/en/sql-reference/functions/hash-functions/, I can get a checksum of entire table this way:

SELECT groupBitXor(cityHash64(*)) FROM table

What is the most accurate way to get a checksum of first N rows of a table?

As an example, I'm using a table with GenerateRandom engine as stated here.

CREATE TABLE test (name String, value UInt32) ENGINE = GenerateRandom(1, 5, 3)

I tried using LIMIT clause, but with no luck yet.

Upvotes: 1

Views: 1390

Answers (1)

vladimir
vladimir

Reputation: 15226

Consider using sub-query:

SELECT groupBitXor(cityHash64(*)) 
FROM (
  SELECT *
  FROM table
  LIMIT x)

SELECT groupBitXor(cityHash64(*))
FROM 
(
    SELECT *
    FROM system.numbers
    LIMIT 10
)

/*
┌─groupBitXor(cityHash64(number))─┐
│             9791317254842948406 │
└─────────────────────────────────┘
*/

Upvotes: 2

Related Questions