ClickHouse Schema
dictionary
The dictionary block describes a dictionary in a database schema.
dictionary "name" {
schema = schema.public
source = sql("CLICKHOUSE(TABLE)")
layout = sql("HASH()")
key "id" {
type = UInt64
}
attribute "name" {
type = String
}
lifetime {
min = 0
max = 0
}
...
}
dictionary attributes
| Name | Required | Value |
|---|---|---|
comment | false | string |
layout | true | Raw expression defined with |
schema | true | Object reference to |
settings | false | map |
source | true | Raw expression defined with |
dictionary blocks
dictionary.attribute
dictionary.attribute attributes
| Name | Required | Value |
|---|---|---|
default | false | Column default expression can be one of:
|
null | false | bool |
type | true | Attribute type can be one of:
|
dictionary.attribute constraints
| Constraint | Value |
|---|---|
| Required | false |
Require Name (e.g., dictionary.attribute "name" ) | true |
dictionary.key
dictionary.key attributes
| Name | Required | Value |
|---|---|---|
default | false | Column default expression can be one of:
|
null | false | bool |
type | true | Attribute type can be one of:
|
dictionary.key constraints
| Constraint | Value |
|---|---|
| Required | false |
Require Name (e.g., dictionary.key "name" ) | true |
dictionary.lifetime
dictionary.lifetime attributes
| Name | Required | Value |
|---|---|---|
max | true | int |
min | true | int |
dictionary.lifetime constraints
| Constraint | Value |
|---|---|
| Required | true |
| Require Name | false |
dictionary constraints
| Constraint | Value |
|---|---|
| Required | false |
Require Name (e.g., dictionary "name" ) | true |
Allow Qualifier (e.g., dictionary "schema" "name" ) | true |
function
The function block describes a ClickHouse User-Defined Function (UDF).
function "plus_one" {
as = "(x) -> x + 1"
}
function attributes
| Name | Required | Value |
|---|---|---|
as | true | string |
function constraints
| Constraint | Value |
|---|---|
| Required | false |
Require Name (e.g., function "name" ) | true |
materialized
The materialized block describes a materialized view in a database schema.
materialized "name" {
schema = schema.public
column "total" {
null = true
type = numeric
}
...
}
materialized attributes
| Name | Required | Value |
|---|---|---|
as | true | string |
comment | false | string |
depends_on | false | List of object references |
engine | false | Table engine can be one of:
|
populate | false | bool |
schema | true | Object reference to |
to | false | Define structure of view can be one of: |
materialized blocks
materialized.column
materialized.column attributes
| Name | Required | Value |
|---|---|---|
comment | false | string |
null | false | bool |
type | true | Column type can be one of:
|
materialized.column constraints
| Constraint | Value |
|---|---|
| Required | false |
Require Name (e.g., materialized.column "name" ) | true |
materialized.primary_key
materialized.primary_key attributes
| Name | Required | Value |
|---|---|---|
columns | false | Primary key columns can be one of:
|
comment | false | string |
materialized.primary_key blocks
materialized.primary_key.on
materialized.primary_key.on attributes
| Name | Required | Value |
|---|---|---|
column | false | Primary key column can be one of:
|
expr | false | string |
materialized.primary_key.on constraints
| Constraint | Value |
|---|---|
| Required | false |
| Require Name | false |
| Repeatable | true |
| Mutually exclusive sets | [column, expr] |
| One of required sets | [column, expr] |
materialized.primary_key constraints
| Constraint | Value |
|---|---|
| Required | false |
| Require Name | false |
| Mutually exclusive sets | [columns, on] |
| One of required sets | [columns, on] |
materialized.refresh
The refresh block describes the refresh settings for a materialized view.
materialized "name" {
schema = schema.public
as = sql("SELECT * FROM table")
refresh {
expr = "EVERY 1 MINUTE"
append = true
depends_on = [materialized.other_view]
settings = {
refresh_retries = 4
}
}
materialized.refresh attributes
| Name | Required | Value |
|---|---|---|
append | false | bool |
depends_on | false | List of object reference to |
expr | true | string |
settings | false | map |
materialized constraints
| Constraint | Value |
|---|---|
| Required | false |
Require Name (e.g., materialized "name" ) | true |
Allow Qualifier (e.g., materialized "schema" "name" ) | true |
| Mutually exclusive sets | [to, engine], [to, populate] |
| One of required sets | [to, engine] |
schema
The schema block describes a database schema.
schema "public" {
...
}
schema attributes
| Name | Required | Value |
|---|---|---|
comment | false | string |
engine | false | Schema engine can be one of:
|
name | false | string |
schema constraints
| Constraint | Value |
|---|---|
| Required | false |
Require Name (e.g., schema "name" ) | true |
table
The table block describes a table in a database schema.
table "users" {
schema = schema.public
column "id" {
type = int
}
...
}
table attributes
| Name | Required | Value |
|---|---|---|
comment | false | string |
engine | false | Table engine can be one of:
|
schema | true | Object reference to |
settings | false | map |
ttl | false | Column ttl can be one of:
|
table blocks
table.check
table.check attributes
| Name | Required | Value |
|---|---|---|
comment | false | string |
expr | true | string |
table.check constraints
| Constraint | Value |
|---|---|
| Required | false |
| Require Name | false |
| Repeatable | true |
table.column
table.column attributes
| Name | Required | Value |
|---|---|---|
codec | false | Column codec can be one of:
|
comment | false | string |
default | false | Column default expression can be one of:
|
default_kind | false | Column default kind can be one of:
|
null | false | bool |
ttl | false | Column ttl can be one of:
|
type | true | Column type can be one of:
|
table.column constraints
| Constraint | Value |
|---|---|
| Required | false |
Require Name (e.g., table.column "name" ) | true |
| Repeatable | true |
table.engine.TimeSeries
table.engine.TimeSeries attributes
| Name | Required | Value |
|---|---|---|
data | false | Object reference to |
metrics | false | Object reference to |
tags | false | Object reference to |
table.index
table.index attributes
| Name | Required | Value |
|---|---|---|
comment | false | string |
granularity | false | int |
type | true | Index type can be one of:
|
table.index blocks
table.index.on
table.index.on attributes
| Name | Required | Value |
|---|---|---|
expr | true | string |
table.index.on constraints
| Constraint | Value |
|---|---|
| Required | true |
| Require Name | false |
table.index constraints
| Constraint | Value |
|---|---|
| Required | false |
Require Name (e.g., table.index "name" ) | true |
table.partition
table.partition attributes
| Name | Required | Value |
|---|---|---|
columns | false | List of object reference to |
table.partition blocks
table.partition.on
table.partition.on attributes
| Name | Required | Value |
|---|---|---|
column | false | Object reference to |
expr | false | string |
table.partition.on constraints
| Constraint | Value |
|---|---|
| Required | false |
| Require Name | false |
| Repeatable | true |
| Mutually exclusive sets | [column, expr] |
| One of required sets | [column, expr] |
table.partition constraints
| Constraint | Value |
|---|---|
| Required | false |
| Require Name | false |
| Mutually exclusive sets | [columns, on] |
| One of required sets | [columns, on] |
table.primary_key
table.primary_key attributes
| Name | Required | Value |
|---|---|---|
columns | false | Primary key columns can be one of:
|
comment | false | string |
table.primary_key blocks
table.primary_key.on
table.primary_key.on attributes
| Name | Required | Value |
|---|---|---|
column | false | Primary key column can be one of:
|
expr | false | string |
table.primary_key.on constraints
| Constraint | Value |
|---|---|
| Required | false |
| Require Name | false |
| Repeatable | true |
| Mutually exclusive sets | [column, expr] |
| One of required sets | [column, expr] |
table.primary_key constraints
| Constraint | Value |
|---|---|
| Required | false |
| Require Name | false |
| Mutually exclusive sets | [columns, on] |
| One of required sets | [columns, on] |
table.projection
The projection block describes a projection for a table
table "name" {
schema = schema.public
projection "name" {
as = "SELECT * FROM table WHERE condition"
}
projection "another" {
as = "SELECT * FROM table WHERE another_condition"
}
}
table.projection attributes
| Name | Required | Value |
|---|---|---|
as | true | string |
table.projection constraints
| Constraint | Value |
|---|---|
| Required | false |
| Require Name | false |
| Repeatable | true |
table.sort
table.sort attributes
| Name | Required | Value |
|---|---|---|
columns | false | List of object reference to |
table.sort blocks
table.sort.on
table.sort.on attributes
| Name | Required | Value |
|---|---|---|
column | false | Object reference to |
expr | false | string |
table.sort.on constraints
| Constraint | Value |
|---|---|
| Required | false |
| Require Name | false |
| Repeatable | true |
| Mutually exclusive sets | [column, expr] |
| One of required sets | [column, expr] |
table.sort constraints
| Constraint | Value |
|---|---|
| Required | false |
| Require Name | false |
| Mutually exclusive sets | [columns, on] |
| One of required sets | [columns, on] |
table constraints
| Constraint | Value |
|---|---|
| Required | false |
Require Name (e.g., table "name" ) | true |
Allow Qualifier (e.g., table "schema" "name" ) | true |
view
The view block describes a view in a database schema.
view "clean_users" {
schema = schema.public
column "id" {
type = int
}
...
}
view attributes
| Name | Required | Value |
|---|---|---|
as | true | string |
comment | false | string |
depends_on | false | List of object references |
schema | true | Object reference to |
view blocks
view.column
view.column attributes
| Name | Required | Value |
|---|---|---|
comment | false | string |
null | false | bool |
type | true | Column type can be one of:
|
view.column constraints
| Constraint | Value |
|---|---|
| Required | false |
Require Name (e.g., view.column "name" ) | true |
view constraints
| Constraint | Value |
|---|---|
| Required | false |
Require Name (e.g., view "name" ) | true |
Allow Qualifier (e.g., view "schema" "name" ) | true |
| Mutually exclusive sets | [latest, git] |