diff --git a/cspell.config.json b/cspell.config.json index 9e76f58b..75549651 100644 --- a/cspell.config.json +++ b/cspell.config.json @@ -10,6 +10,7 @@ "mage_output_file.go" ], "words": [ + "lowcardinality", "fixedstring", "singlequote", "concats", @@ -78,4 +79,4 @@ "goproxy", "Nonproxy" ] -} \ No newline at end of file +} diff --git a/go.mod b/go.mod index c48fa861..6fc8039f 100644 --- a/go.mod +++ b/go.mod @@ -7,10 +7,10 @@ toolchain go1.21.4 require ( dagger.io/dagger v0.11.4 github.com/ClickHouse/clickhouse-go/v2 v2.24.0 - github.com/docker/docker v26.1.2+incompatible + github.com/docker/docker v26.1.3+incompatible github.com/docker/go-units v0.5.0 - github.com/grafana/grafana-plugin-sdk-go v0.230.0 - github.com/grafana/sqlds/v3 v3.2.0 + github.com/grafana/grafana-plugin-sdk-go v0.231.0 + github.com/grafana/sqlds/v3 v3.3.0 github.com/paulmach/orb v0.11.1 github.com/pkg/errors v0.9.1 github.com/shopspring/decimal v1.4.0 @@ -79,7 +79,7 @@ require ( github.com/gorilla/mux v1.8.1 // indirect github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 // indirect github.com/hashicorp/go-hclog v1.6.3 // indirect - github.com/hashicorp/go-plugin v1.6.0 // indirect + github.com/hashicorp/go-plugin v1.6.1 // indirect github.com/hashicorp/yamux v0.1.1 // indirect github.com/invopop/yaml v0.2.0 // indirect github.com/josharian/intern v1.0.0 // indirect diff --git a/go.sum b/go.sum index 9b9b4301..59ee5a33 100644 --- a/go.sum +++ b/go.sum @@ -58,8 +58,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/distribution/reference v0.5.0 h1:/FUIFXtfc/x2gpa5/VGfiGLuOIdYa1t65IKK2OFGvA0= github.com/distribution/reference v0.5.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E= -github.com/docker/docker v26.1.2+incompatible h1:UVX5ZOrrfTGZZYEP+ZDq3Xn9PdHNXaSYMFPDumMqG2k= -github.com/docker/docker v26.1.2+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= +github.com/docker/docker v26.1.3+incompatible h1:lLCzRbrVZrljpVNobJu1J2FHk8V0s4BawoZippkc+xo= +github.com/docker/docker v26.1.3+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj1Br63c= github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc= github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= @@ -124,10 +124,10 @@ github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= github.com/grafana/dataplane/sdata v0.0.7 h1:CImITypIyS1jxijCR6xqKx71JnYAxcwpH9ChK0gH164= github.com/grafana/dataplane/sdata v0.0.7/go.mod h1:Jvs5ddpGmn6vcxT7tCTWAZ1mgi4sbcdFt9utQx5uMAU= -github.com/grafana/grafana-plugin-sdk-go v0.230.0 h1:Y4IL+eT1jXqTCctlNzdCvxAozpBZ8xEsRGWjGAVRXxo= -github.com/grafana/grafana-plugin-sdk-go v0.230.0/go.mod h1:6V6ikT4ryva8MrAp7Bdz5fTJx3/ztzKvpMJFfpzr4CI= -github.com/grafana/sqlds/v3 v3.2.0 h1:WXuYEaFfiCvgm8kK2ixx44/zAEjFzCylA2+RF3GBqZA= -github.com/grafana/sqlds/v3 v3.2.0/go.mod h1:kH0WuHUR3j0Q7IEymbm2JiaPckUhRCbqjV9ajaBAnmM= +github.com/grafana/grafana-plugin-sdk-go v0.231.0 h1:Qt4PBDR8b4MTUxL48EaZw1fHI1rXUNNhvTU/Nf0Ex2g= +github.com/grafana/grafana-plugin-sdk-go v0.231.0/go.mod h1:8fJk+5J1hMkpqY/7vrXHKgAsqELWNkQvLQ5A5xCVZHk= +github.com/grafana/sqlds/v3 v3.3.0 h1:Pr7+w3muJp5cUcORdvFYxc1z9Q35XGfA4r+3Gj+MPt4= +github.com/grafana/sqlds/v3 v3.3.0/go.mod h1:NdALlDk49eEyDsmm7CoGP9CkIDDF6tV2adGcpxWRHlk= github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1 h1:qnpSQwGEnkcRpTqNOIR6bJbR0gAorgP9CSALpRcKoAA= github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1/go.mod h1:lXGCsh6c22WGtjr+qGHj1otzZpV/1kwTMAqkwZsnWRU= github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0 h1:pRhl55Yx1eC7BZ1N+BBWwnKaMyD8uC+34TLdndZMAKk= @@ -136,8 +136,8 @@ github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 h1:/c3QmbOGMGTOumP2iT/rCwB7b0Q github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1/go.mod h1:5SN9VR2LTsRFsrEC6FHgRbTWrTHu6tqPeKxEQv15giM= github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k= github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M= -github.com/hashicorp/go-plugin v1.6.0 h1:wgd4KxHJTVGGqWBq4QPB1i5BZNEx9BR8+OFmHDmTk8A= -github.com/hashicorp/go-plugin v1.6.0/go.mod h1:lBS5MtSSBZk0SHc66KACcjjlU6WzEVP/8pwz68aMkCI= +github.com/hashicorp/go-plugin v1.6.1 h1:P7MR2UP6gNKGPp+y7EZw2kOiq4IR9WiqLvp0XOsVdwI= +github.com/hashicorp/go-plugin v1.6.1/go.mod h1:XPHFku2tFo3o3QKFgSYo+cghcUhw1NA1hZyMK0PWAw0= github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE= github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= diff --git a/src/data/sqlGenerator.test.ts b/src/data/sqlGenerator.test.ts index 1ad994f4..f3663388 100644 --- a/src/data/sqlGenerator.test.ts +++ b/src/data/sqlGenerator.test.ts @@ -532,9 +532,13 @@ describe('getLimit', () => { describe('is*Type', () => { it.each<{ input: string, expected: boolean }>([ + { input: 'String', expected: true }, { input: 'Nullable(String)', expected: true }, + { input: 'LowCardinality(Nullable(String))', expected: true }, { input: 'FixedString(1)', expected: true }, - { input: 'String', expected: true }, + { input: 'LowCardinality(Nullable(FixedString(1)))', expected: true }, + { input: 'LowCardinality(FixedString(1))', expected: true }, + { input: 'Nullable(FixedString(1))', expected: true }, { input: 'Array(String)', expected: false }, ])('$input isStringType $expected', (c) => { expect(_testExports.isStringType(c.input)).toEqual(c.expected); diff --git a/src/data/sqlGenerator.ts b/src/data/sqlGenerator.ts index 280188ac..e9ad84a4 100644 --- a/src/data/sqlGenerator.ts +++ b/src/data/sqlGenerator.ts @@ -742,12 +742,24 @@ const getFilters = (options: QueryBuilderOptions): string => { return concatQueryParts(builtFilters); }; +const stripTypeModifiers = (type: string): string => { + return type.toLowerCase(). + replace(/\(/g, ''). + replace(/\)/g, ''). + replace(/nullable/g, ''). + replace(/lowcardinality/g, ''); + +} const isBooleanType = (type: string): boolean => (type?.toLowerCase().startsWith('boolean')); const numberTypes = ['int', 'float', 'decimal']; const isNumberType = (type: string): boolean => numberTypes.some(t => type?.toLowerCase().includes(t)); const isDateType = (type: string): boolean => type?.toLowerCase().startsWith('date') || type?.toLowerCase().startsWith('nullable(date'); // const isDateTimeType = (type: string): boolean => type?.toLowerCase().startsWith('datetime') || type?.toLowerCase().startsWith('nullable(datetime'); -const isStringType = (type: string): boolean => (type.toLowerCase() === 'string' || type.toLowerCase().startsWith('nullable(string') || type.toLowerCase().startsWith('fixedstring')) && !(isBooleanType(type) || isNumberType(type) || isDateType(type)); +const isStringType = (type: string): boolean => { + type = stripTypeModifiers(type.toLowerCase()); + return (type === 'string' || type.startsWith('fixedstring')) + && !(isBooleanType(type) || isNumberType(type) || isDateType(type)); +} const isNullFilter = (operator: FilterOperator): boolean => operator === FilterOperator.IsNull || operator === FilterOperator.IsNotNull; const isBooleanFilter = (type: string): boolean => isBooleanType(type); const isNumberFilter = (type: string): boolean => isNumberType(type);