Skip to content

Commit

Permalink
Merge branch 'issue-830' of https://github.com/ClickHouse/clickhouse-…
Browse files Browse the repository at this point in the history
…grafana-datasource into issue-828
  • Loading branch information
SpencerTorres committed May 23, 2024
2 parents 1be74f1 + 31f2c12 commit df6fdd5
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 15 deletions.
3 changes: 2 additions & 1 deletion cspell.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"mage_output_file.go"
],
"words": [
"lowcardinality",
"fixedstring",
"singlequote",
"concats",
Expand Down Expand Up @@ -78,4 +79,4 @@
"goproxy",
"Nonproxy"
]
}
}
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand All @@ -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=
Expand Down
6 changes: 5 additions & 1 deletion src/data/sqlGenerator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 13 additions & 1 deletion src/data/sqlGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit df6fdd5

Please sign in to comment.