Skip to content

Commit

Permalink
Merge pull request #1036 from ClickHouse/docs/low-cardinality
Browse files Browse the repository at this point in the history
docs: add LowCardinality(String) example
  • Loading branch information
ernado authored Jan 31, 2025
2 parents 3f22486 + 2272241 commit 22981da
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ CREATE TABLE test_table_insert
ts DateTime64(9),
severity_text Enum8('INFO'=1, 'DEBUG'=2),
severity_number UInt8,
service_name LowCardinality(String),
body String,
name String,
arr Array(String)
Expand All @@ -111,9 +112,11 @@ var (
sevText proto.ColEnum
sevNumber proto.ColUInt8

ts = new(proto.ColDateTime64).WithPrecision(proto.PrecisionNano) // DateTime64(9)
arr = new(proto.ColStr).Array() // Array(String)
now = time.Date(2010, 1, 1, 10, 22, 33, 345678, time.UTC)
// or new(proto.ColStr).LowCardinality()
serviceName = proto.NewLowCardinality(new(proto.ColStr))
ts = new(proto.ColDateTime64).WithPrecision(proto.PrecisionNano) // DateTime64(9)
arr = new(proto.ColStr).Array() // Array(String)
now = time.Date(2010, 1, 1, 10, 22, 33, 345678, time.UTC)
)

// Append 10 rows to initial data block.
Expand All @@ -124,6 +127,7 @@ for i := 0; i < 10; i++ {
sevText.Append("INFO")
sevNumber.Append(10)
arr.Append([]string{"foo", "bar", "baz"})
serviceName.Append("service")
}

input := proto.Input{
Expand Down Expand Up @@ -186,6 +190,7 @@ if err := conn.Do(ctx, ch.Query{
sevText.Append("DEBUG")
sevNumber.Append(10)
arr.Append([]string{"foo", "bar", "baz"})
serviceName.Append("service")
}

// Data will be encoded and sent to ClickHouse server after returning nil.
Expand Down
12 changes: 9 additions & 3 deletions examples/insert/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func main() {
ts DateTime64(9),
severity_text Enum8('INFO'=1, 'DEBUG'=2),
severity_number UInt8,
service_name LowCardinality(String),
body String,
name String,
arr Array(String)
Expand All @@ -38,9 +39,11 @@ func main() {
sevText proto.ColEnum
sevNumber proto.ColUInt8

ts = new(proto.ColDateTime64).WithPrecision(proto.PrecisionNano) // DateTime64(9)
arr = new(proto.ColStr).Array() // Array(String)
now = time.Date(2010, 1, 1, 10, 22, 33, 345678, time.UTC)
// or new(proto.ColStr).LowCardinality()
serviceName = proto.NewLowCardinality(new(proto.ColStr))
ts = new(proto.ColDateTime64).WithPrecision(proto.PrecisionNano) // DateTime64(9)
arr = new(proto.ColStr).Array() // Array(String)
now = time.Date(2010, 1, 1, 10, 22, 33, 345678, time.UTC)
)

// Append 10 rows to initial data block.
Expand All @@ -51,13 +54,15 @@ func main() {
sevText.Append("INFO")
sevNumber.Append(10)
arr.Append([]string{"foo", "bar", "baz"})
serviceName.Append("service")
}

// Insert single data block.
input := proto.Input{
{Name: "ts", Data: ts},
{Name: "severity_text", Data: &sevText},
{Name: "severity_number", Data: &sevNumber},
{Name: "service_name", Data: serviceName},
{Name: "body", Data: &body},
{Name: "name", Data: &name},
{Name: "arr", Data: arr},
Expand Down Expand Up @@ -106,6 +111,7 @@ func main() {
sevText.Append("DEBUG")
sevNumber.Append(10)
arr.Append([]string{"foo", "bar", "baz"})
serviceName.Append("service")
}

// Data will be encoded and sent to ClickHouse server after returning nil.
Expand Down

0 comments on commit 22981da

Please sign in to comment.