clickhouse-docs icon indicating copy to clipboard operation
clickhouse-docs copied to clipboard

Document `lowCardinalityXYZ` functions.

Open johnnymatthews opened this issue 1 year ago • 1 comments

Create documentation for the lowCardinalityXYZ functions:

  • [ ] lowCardinalityIndices
  • [ ] lowCardinalityKeys

See #1833 for details on how to complete this issue.

Child issue of #1833.

johnnymatthews avatar Feb 11 '24 19:02 johnnymatthews

lowCardinalityIndices: For each row in current block returns the index of the value in the dictionary of unique values for LowCardinality columns. The first unique value encountered has an index of 1.

lowCardinalityKeysfunction returns the keys (unique values) that for LowCardinality column. If column size less than dictionary size, then values will be cut, if greater, defaults will be added.

Note that each block may its own dictionary:


:) CREATE TABLE t1 (s LowCardinality(String)) ENGINE = Memory;

-- insert two blocks of data:

:) INSERT INTO t1 VALUES ('one'),('two'),('one'),('one'),('two');
:) INSERT INTO t1 VALUES ('three'),('two'),('one'),('two'),('two'),('three');


:) SELECT s, lowCardinalityIndices(s), lowCardinalityKeys(s) FROM t1

┌─s───┬─lowCardinalityIndices(s)─┬─lowCardinalityKeys(s)─┐
│ one │                        1 │                       │
│ two │                        2 │ one                   │
│ one │                        1 │ two                   │
│ one │                        1 │                       │
│ two │                        2 │                       │
└─────┴──────────────────────────┴───────────────────────┘
┌─s─────┬─lowCardinalityIndices(s)─┬─lowCardinalityKeys(s)─┐
│ three │                        1 │                       │
│ two   │                        2 │ three                 │
│ one   │                        3 │ two                   │
│ two   │                        2 │ one                   │
│ two   │                        2 │                       │
│ three │                        1 │                       │
└───────┴──────────────────────────┴───────────────────────┘

11 rows in set. Elapsed: 0.002 sec. 

vdimir avatar Mar 01 '24 11:03 vdimir