MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / registerDataTypeNested

Function registerDataTypeNested

src/DataTypes/DataTypeNested.cpp:62–175  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

60}
61
62void registerDataTypeNested(DataTypeFactory & factory)
63{
64 factory.registerDataTypeCustom("Nested", create, DataTypeFactory::Case::Sensitive, Documentation{
65 .description = R"DOCS_MD(
66## Nested(name1 Type1, Name2 Type2, ...) {#nestedname1-type1-name2-type2-}
67
68A nested data structure is like a table inside a cell. The parameters of a nested data structure – the column names and types – are specified the same way as in a [CREATE TABLE](../../../sql-reference/statements/create/table.md) query. Each table row can correspond to any number of rows in a nested data structure.
69
70:::tip[Avoid using dots in column names]
71Column names containing dots, columns sharing a common dot-prefix, and columns with the `Array` type can each be interpreted as part of a flattened Nested structure when `flatten_nested = 1` (the default). This can cause unexpected array-length validation on inserts and renaming restrictions.
72
73Avoid using dots in column names if possible.
74Use underscores (`_`) or another separator instead of dots in column names unless you intentionally need `Nested` semantics.
75:::
76
77Example:
78
79```sql
80CREATE TABLE test.visits
81(
82 CounterID UInt32,
83 StartDate Date,
84 Sign Int8,
85 IsNew UInt8,
86 VisitID UInt64,
87 UserID UInt64,
88 ...
89 Goals Nested
90 (
91 ID UInt32,
92 Serial UInt32,
93 EventTime DateTime,
94 Price Int64,
95 OrderID String,
96 CurrencyID UInt32
97 ),
98 ...
99) ENGINE = CollapsingMergeTree(StartDate, intHash32(UserID), (CounterID, StartDate, intHash32(UserID), VisitID), 8192, Sign)
100```
101
102This example declares the `Goals` nested data structure, which contains data about conversions (goals reached). Each row in the 'visits' table can correspond to zero or any number of conversions.
103
104When [flatten_nested](/operations/settings/settings#flatten_nested) is set to `0` (which is not by default), arbitrary levels of nesting are supported.
105
106In most cases, when working with a nested data structure, its columns are specified with column names separated by a dot. These columns make up an array of matching types. All the column arrays of a single nested data structure have the same length.
107
108Example:
109
110```sql
111SELECT
112 Goals.ID,
113 Goals.EventTime
114FROM test.visits
115WHERE CounterID = 101500 AND length(Goals.ID) < 5
116LIMIT 10
117```
118
119```text

Callers 1

DataTypeFactoryMethod · 0.85

Calls 1

Tested by

no test coverage detected