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

How to use specialized codecs for nested columns? #12758

Closed
schneefux opened this issue Jul 25, 2020 · 4 comments
Closed

How to use specialized codecs for nested columns? #12758

schneefux opened this issue Jul 25, 2020 · 4 comments
Assignees
Labels

Comments

@schneefux
Copy link

I am trying to create a nested table with a Gorilla encoded column but I get a syntax error:

ClickHouse client version 20.5.2.7.
Connecting to localhost:9000 as user default.
Connected to ClickHouse server version 20.5.2 revision 54435.

clickhouse-db :) create table nested_test (id UInt8, Attrs Nested(Key String, Value UInt8 Codec(Gorilla))) ENGINE=MergeTree() ORDER BY id;

Syntax error: failed at position 74:
create table nested_test (id UInt8, Attrs Nested(Key String, Value UInt8 Codec(Gorilla))) ENGINE=MergeTree() ORDER BY id;
Expected one of: Comma, token

The following works, but I do not understand what it does:

create table nested_test (id UInt8, Attrs Nested(Key String, Value UInt8) Codec(Gorilla)) ENGINE=MergeTree() ORDER BY id;

The documentation does not specify how Array or Nested columns work with custom codecs.
Can you clarify? 😊

@schneefux schneefux added the question Question? label Jul 25, 2020
@den-crane
Copy link
Contributor

den-crane commented Jul 26, 2020

CREATE TABLE nested_test
(
    `id` UInt8,
    `Attrs` Nested(    Key String,     Value UInt8) CODEC(Gorilla)
)
ENGINE = MergeTree()
ORDER BY id


DESCRIBE TABLE nested_test

┌─name────────┬─type──────────┬─default_type─┬─default_expression─┬─comment─┬─codec_expression─┬─ttl_expression─┐
│ id          │ UInt8         │              │                    │         │                  │                │
│ Attrs.Key   │ Array(String) │              │                    │         │ Gorilla          │                │
│ Attrs.Value │ Array(UInt8)  │              │                    │         │ Gorilla          │                │
└─────────────┴───────────────┴──────────────┴────────────────────┴─────────┴──────────────────┴────────────────┘

Nested is a syntax sugar for CREATE TABLE

WA (the same result as Nested):

CREATE TABLE nested_test
(
    `id` UInt8,
    `Attrs.Key` Array(String),
    `Attrs.Value` UInt8 CODEC(Gorilla)
)
ENGINE = MergeTree()
ORDER BY id

BTW Gorilla is good for Float types, try Delta for UInt8.

@darkleaf
Copy link

How does codec work with an array? Codec is applied to two neighboring values in the same array, isn’t it? Or is it applied to values with the same index in to neighboring arrays?

@alexey-milovidov
Copy link
Member

See #12551 and #15089

@alexey-milovidov
Copy link
Member

Codec is applied to two neighboring values in the same array, isn’t it?

Almost this. It is applied to the sequence of all elements of arrays if placed one after the other.
For example, if we have two rows with [1, 2, 3], [1, 2], the codec will be applied to the sequence 1, 2, 3, 1, 2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants