diff --git a/CHANGELOG.md b/CHANGELOG.md index eedbbff9..39b08690 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Features + +- Add support for new Variant, Dynamic, and JSON types (https://github.com/grafana/clickhouse-datasource/pull/1108) + ### Fixes - Optimized performance for log volumes processing using ClickHouse `multiSearchAny` diff --git a/go.mod b/go.mod index 0fc56016..f62597f5 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.23 toolchain go1.23.4 require ( - github.com/ClickHouse/clickhouse-go/v2 v2.30.0 + github.com/ClickHouse/clickhouse-go/v2 v2.30.1 github.com/docker/docker v27.5.0+incompatible github.com/docker/go-units v0.5.0 github.com/grafana/grafana-plugin-sdk-go v0.262.0 @@ -19,6 +19,7 @@ require ( ) require ( + github.com/AdaLogics/go-fuzz-headers v0.0.0-20240806141605-e8a1dd7889d6 // indirect github.com/apache/arrow-go/v18 v18.0.1-0.20241212180703-82be143d7c30 // indirect github.com/containerd/log v0.1.0 // indirect github.com/containerd/platforms v0.2.1 // indirect @@ -43,13 +44,14 @@ require ( go.opentelemetry.io/contrib/samplers/jaegerremote v0.27.0 // indirect go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.27.0 // indirect golang.org/x/sync v0.10.0 // indirect + golang.org/x/time v0.9.0 // indirect ) require ( dario.cat/mergo v1.0.0 // indirect github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect github.com/BurntSushi/toml v1.4.0 // indirect - github.com/ClickHouse/ch-go v0.61.5 // indirect + github.com/ClickHouse/ch-go v0.63.1 // indirect github.com/Microsoft/go-winio v0.6.2 // indirect github.com/andybalholm/brotli v1.1.1 // indirect github.com/beorn7/perks v1.0.1 // indirect diff --git a/go.sum b/go.sum index 85b3c792..6906905b 100644 --- a/go.sum +++ b/go.sum @@ -2,17 +2,17 @@ dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= -github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 h1:bvDV9vkmnHYOMsOr4WLk+Vo07yKIzd94sVoIqshQ4bU= -github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24/go.mod h1:8o94RPi1/7XTJvwPpRSzSUedZrtlirdB3r9Z20bi2f8= +github.com/AdaLogics/go-fuzz-headers v0.0.0-20240806141605-e8a1dd7889d6 h1:He8afgbRMd7mFxO99hRNu+6tazq8nFF9lIwo9JFroBk= +github.com/AdaLogics/go-fuzz-headers v0.0.0-20240806141605-e8a1dd7889d6/go.mod h1:8o94RPi1/7XTJvwPpRSzSUedZrtlirdB3r9Z20bi2f8= github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25UVaW/CKtUDjefjrs0SPonmDGUVOYP0= github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0= github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= -github.com/ClickHouse/ch-go v0.61.5 h1:zwR8QbYI0tsMiEcze/uIMK+Tz1D3XZXLdNrlaOpeEI4= -github.com/ClickHouse/ch-go v0.61.5/go.mod h1:s1LJW/F/LcFs5HJnuogFMta50kKDO0lf9zzfrbl0RQg= -github.com/ClickHouse/clickhouse-go/v2 v2.30.0 h1:AG4D/hW39qa58+JHQIFOSnxyL46H6h2lrmGGk17dhFo= -github.com/ClickHouse/clickhouse-go/v2 v2.30.0/go.mod h1:i9ZQAojcayW3RsdCb3YR+n+wC2h65eJsZCscZ1Z1wyo= +github.com/ClickHouse/ch-go v0.63.1 h1:s2JyZvWLTCSAGdtjMBBmAgQQHMco6pawLJMOXi0FODM= +github.com/ClickHouse/ch-go v0.63.1/go.mod h1:I1kJJCL3WJcBMGe1m+HVK0+nREaG+JOYYBWjrDrF3R0= +github.com/ClickHouse/clickhouse-go/v2 v2.30.1 h1:Dy0n0l+cMbPXs8hFkeeWGaPKrB+MDByUNQBSmRO3W6k= +github.com/ClickHouse/clickhouse-go/v2 v2.30.1/go.mod h1:szk8BMoQV/NgHXZ20ZbwDyvPWmpfhRKjFkc6wzASGxM= github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= github.com/andybalholm/brotli v1.1.1 h1:PR2pgnyFznKEugtsUo0xLdDop5SKXd5Qf5ysW+7XdTA= @@ -426,8 +426,8 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= -golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 h1:vVKdlvoWBphwdxWKrFZEuM0kGgGLxUOYcY4U/2Vjg44= -golang.org/x/time v0.0.0-20220210224613-90d013bbcef8/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.9.0 h1:EsRrnYcQiGH+5FfbgvV4AP7qEZstoyrHB0DzarOQ4ZY= +golang.org/x/time v0.9.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= diff --git a/pkg/converters/converters.go b/pkg/converters/converters.go index b5a38a42..5123a13c 100644 --- a/pkg/converters/converters.go +++ b/pkg/converters/converters.go @@ -4,6 +4,7 @@ import ( "encoding/json" "errors" "fmt" + "github.com/ClickHouse/clickhouse-go/v2" "math/big" "net" "reflect" @@ -41,6 +42,11 @@ var matchRegexes = map[string]*regexp.Regexp{ "Point": regexp.MustCompile(`^Point`), "SimpleAggregateFunction()": regexp.MustCompile(`^SimpleAggregateFunction\(.*\)`), "Tuple()": regexp.MustCompile(`^Tuple\(.*\)`), + "Variant()": regexp.MustCompile(`^Variant\(.*\)`), + "Dynamic": regexp.MustCompile(`^Dynamic`), + "Dynamic()": regexp.MustCompile(`Dynamic\(.*\)`), + "JSON": regexp.MustCompile(`^JSON`), + "JSON()": regexp.MustCompile(`^JSON\(.*\)`), } var Converters = map[string]Converter{ @@ -211,6 +217,36 @@ var Converters = map[string]Converter{ matchRegex: matchRegexes["Tuple()"], scanType: reflect.TypeOf((*interface{})(nil)).Elem(), }, + "Variant()": { + convert: jsonConverter, + fieldType: data.FieldTypeNullableJSON, + matchRegex: matchRegexes["Variant()"], + scanType: reflect.TypeOf((*interface{})(nil)).Elem(), + }, + "Dynamic": { + convert: jsonConverter, + fieldType: data.FieldTypeNullableJSON, + matchRegex: matchRegexes["Dynamic"], + scanType: reflect.TypeOf((*interface{})(nil)).Elem(), + }, + "Dynamic()": { + convert: jsonConverter, + fieldType: data.FieldTypeNullableJSON, + matchRegex: matchRegexes["Dynamic()"], + scanType: reflect.TypeOf((*interface{})(nil)).Elem(), + }, + "JSON": { + convert: jsonConverter, + fieldType: data.FieldTypeNullableJSON, + matchRegex: matchRegexes["JSON"], + scanType: reflect.TypeOf((*clickhouse.JSON)(nil)).Elem(), + }, + "JSON()": { + convert: jsonConverter, + fieldType: data.FieldTypeNullableJSON, + matchRegex: matchRegexes["JSON()"], + scanType: reflect.TypeOf((*clickhouse.JSON)(nil)).Elem(), + }, // NestedConverter currently only supports flatten_nested=0 only which can be marshalled into []map[string]interface{} "Nested()": { convert: jsonConverter,