-
Notifications
You must be signed in to change notification settings - Fork 818
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Range query for custom attribute #5426
Changes from all commits
f771131
9b86598
360ee20
3f074de
218e829
fa587cb
bb4fa67
c056a9f
10b4598
7421c35
931f364
624a769
9130637
909ac6f
d623f8f
8ac32e8
2370332
94cb588
ed103a5
ab15272
d749c1a
6191af5
9f7b620
8aade6a
52e993d
97b5763
a3c05cc
3ff2029
ba1879d
6c3dd9c
45ccf60
dc93318
c71355d
b73ad5f
0b1d5a2
9407591
067e71c
31cbb5b
64ff7bb
66db061
8f7dcaf
543810b
c95251c
d1fbe11
2fa02a3
376251d
9fda9f3
c0c327c
64748d6
5751cd1
3978502
7ade724
5a2c271
378597b
6bc3f61
f5b7734
bac8352
97bc5a4
af28635
0d527a9
16c37ea
3bb3010
76247ac
79c83e5
b695a18
763e378
fa08342
2db04d3
9afb738
1adf907
91adba5
3d1ac46
8d9da02
fca6bba
ac9c769
eae9ad4
c49ea32
775a31e
b4e2c66
295a989
7b68dd3
ed8dbe2
02a0812
593483b
2cbfa21
2c84916
cce115e
f6917e8
5b98b5b
45031c5
21d1dda
0d2f41a
49fe217
41a8345
94c308e
2bf6418
5e3bc5c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
neil-xie marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,7 +59,7 @@ func TestValidateQuery(t *testing.T) { | |
}, | ||
"Case6-1: complex query I: with parenthesis": { | ||
query: "(CustomStringField = 'custom and custom2 or custom3 order by') or CustomIntField between 1 and 10", | ||
validated: "((JSON_MATCH(Attr, '\"$.CustomStringField\" is not null') AND REGEXP_LIKE(JSON_EXTRACT_SCALAR(Attr, '$.CustomStringField', 'string'), 'custom and custom2 or custom3 order by*')) or CustomIntField between 1 and 10)", | ||
validated: "((JSON_MATCH(Attr, '\"$.CustomStringField\" is not null') AND REGEXP_LIKE(JSON_EXTRACT_SCALAR(Attr, '$.CustomStringField', 'string'), 'custom and custom2 or custom3 order by*')) or (JSON_MATCH(Attr, '\"$.CustomIntField\" is not null') AND CAST(JSON_EXTRACT_SCALAR(Attr, '$.CustomIntField') AS INT) >= 1 AND CAST(JSON_EXTRACT_SCALAR(Attr, '$.CustomIntField') AS INT) <= 10))", | ||
}, | ||
"Case6-2: complex query II: with only system keys": { | ||
query: "DomainID = 'd-id' and (RunID = 'run-id' or WorkflowID = 'wid')", | ||
|
@@ -71,7 +71,7 @@ func TestValidateQuery(t *testing.T) { | |
}, | ||
"Case6-4: complex query IV": { | ||
query: "WorkflowID = 'wid' and (CustomStringField = 'custom and custom2 or custom3 order by' or CustomIntField between 1 and 10)", | ||
validated: "WorkflowID = 'wid' and ((JSON_MATCH(Attr, '\"$.CustomStringField\" is not null') AND REGEXP_LIKE(JSON_EXTRACT_SCALAR(Attr, '$.CustomStringField', 'string'), 'custom and custom2 or custom3 order by*')) or CustomIntField between 1 and 10)", | ||
validated: "WorkflowID = 'wid' and ((JSON_MATCH(Attr, '\"$.CustomStringField\" is not null') AND REGEXP_LIKE(JSON_EXTRACT_SCALAR(Attr, '$.CustomStringField', 'string'), 'custom and custom2 or custom3 order by*')) or (JSON_MATCH(Attr, '\"$.CustomIntField\" is not null') AND CAST(JSON_EXTRACT_SCALAR(Attr, '$.CustomIntField') AS INT) >= 1 AND CAST(JSON_EXTRACT_SCALAR(Attr, '$.CustomIntField') AS INT) <= 10))", | ||
}, | ||
"Case7: invalid sql query": { | ||
query: "Invalid SQL", | ||
|
@@ -113,6 +113,43 @@ func TestValidateQuery(t *testing.T) { | |
query: "CustomIntField = 1 or CustomIntField = 2", | ||
validated: "(JSON_MATCH(Attr, '\"$.CustomIntField\"=''1''') or JSON_MATCH(Attr, '\"$.CustomIntField\"=''2'''))", | ||
}, | ||
"Case14-1: range query: custom filed": { | ||
query: "CustomIntField BETWEEN 1 AND 2", | ||
validated: "(JSON_MATCH(Attr, '\"$.CustomIntField\" is not null') AND CAST(JSON_EXTRACT_SCALAR(Attr, '$.CustomIntField') AS INT) >= 1 AND CAST(JSON_EXTRACT_SCALAR(Attr, '$.CustomIntField') AS INT) <= 2)", | ||
}, | ||
"Case14-2: range query: system filed": { | ||
query: "NumClusters BETWEEN 1 AND 2", | ||
validated: "NumClusters between 1 and 2", | ||
}, | ||
"Case15-1: custom date attribute less than": { | ||
query: "CustomDatetimeField < 1697754674", | ||
validated: "(JSON_MATCH(Attr, '\"$.CustomDatetimeField\" is not null') AND CAST(JSON_EXTRACT_SCALAR(Attr, '$.CustomDatetimeField') AS BIGINT) < 1697754674)", | ||
}, | ||
"Case15-2: custom date attribute greater than or equal to": { | ||
query: "CustomDatetimeField >= 1697754674", | ||
validated: "(JSON_MATCH(Attr, '\"$.CustomDatetimeField\" is not null') AND CAST(JSON_EXTRACT_SCALAR(Attr, '$.CustomDatetimeField') AS BIGINT) >= 1697754674)", | ||
}, | ||
"Case15-3: system date attribute greater than or equal to": { | ||
query: "StartTime >= 1697754674", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When user input a date string like StartTime > "2023-11-02T15:36:47", is this handled in the query validator? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not handled here. But that will be converted to |
||
validated: "StartTime >= 1697754674", | ||
}, | ||
"Case16-1: custom int attribute greater than or equal to": { | ||
query: "CustomIntField >= 0", | ||
validated: "(JSON_MATCH(Attr, '\"$.CustomIntField\" is not null') AND CAST(JSON_EXTRACT_SCALAR(Attr, '$.CustomIntField') AS INT) >= 0)", | ||
}, | ||
"Case16-2: custom double attribute greater than or equal to": { | ||
query: "CustomDoubleField >= 0", | ||
validated: "(JSON_MATCH(Attr, '\"$.CustomDoubleField\" is not null') AND CAST(JSON_EXTRACT_SCALAR(Attr, '$.CustomDoubleField') AS DOUBLE) >= 0)", | ||
}, | ||
"Case17: custom keyword attribute greater than or equal to. Will return error run time": { | ||
query: "CustomKeywordField < 0", | ||
validated: "(JSON_MATCH(Attr, '\"$.CustomKeywordField\"<''0''') or JSON_MATCH(Attr, '\"$.CustomKeywordField[*]\"<''0'''))", | ||
}, | ||
// TODO | ||
"Case18: custom int order by. Will have errors at run time. Doesn't support for now": { | ||
query: "CustomIntField = 0 order by CustomIntField desc", | ||
validated: "JSON_MATCH(Attr, '\"$.CustomIntField\"=''0''') order by CustomIntField desc", | ||
}, | ||
} | ||
|
||
for name, test := range tests { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
previously we didn't find the range query was not working since we used the old pinot table which we had flatten attribute. So the range query "between and" worked.