Skip to content

Commit

Permalink
Merge pull request #709 from Altinity/issue-705
Browse files Browse the repository at this point in the history
fix "in" construction regexp
  • Loading branch information
Slach authored Jan 27, 2025
2 parents 60a5075 + 7d0f07a commit 6c9fa01
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ src/static/*.wasm
# test temporary files
tests/testflows/tmp/target/
tests/testflows/assets/
tests/automated/**.csv
tests/testflows/tests/automated/**/Downloads/*.csv
23 changes: 23 additions & 0 deletions pkg/eval_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -1519,6 +1519,11 @@ func (s *EvalQueryScanner) toAST() (*EvalAST, error) {

if isClosureChars(s.Token) {
subQuery = betweenBraces(s._s)

if subQuery == "" {
betweenSquareBraces(s._s)
}

var subAST *EvalAST
if subAST, err = toAST(subQuery); err != nil {
return nil, err
Expand Down Expand Up @@ -2098,6 +2103,24 @@ func betweenBraces(query string) string {
return subQuery
}

func betweenSquareBraces(query string) string {
var openBraces = 1
var subQuery = ""
for i := 0; i < len(query); i++ {
if query[i] == '[' {
openBraces++
}
if query[i] == ']' {
if openBraces == 1 {
subQuery = query[0:i]
break
}
openBraces--
}
}
return subQuery
}

// see https://clickhouse.tech/docs/en/sql-reference/statements/select/
func printAST(AST *EvalAST, tab string) string {
var result = ""
Expand Down
25 changes: 25 additions & 0 deletions src/datasource/scanner/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,10 @@ class Scanner {

if (isClosureChars(this.token)) {
subQuery = betweenBraces(this._s);
if (!subQuery) {
subQuery = betweenBrackets(this._s);
}

let subAST = toAST(subQuery);
if (isSet(subAST, 'root')) {
argument +=
Expand Down Expand Up @@ -603,6 +607,27 @@ function betweenBraces(query) {
return subQuery;
}


function betweenBrackets(query) {
let openBraces = 1;
let subQuery = '';

for (let i = 0; i < query.length; i++) {
if (query.charAt(i) === '[') {
openBraces++;
}
if (query.charAt(i) === ']') {
if (openBraces === 1) {
subQuery = query.substring(0, i);
break;
}
openBraces--;
}
}

return subQuery;
}

// see https://clickhouse.tech/docs/en/sql-reference/statements/select/
function print(AST, tab = '') {
let result = '';
Expand Down
6 changes: 3 additions & 3 deletions tests/testflows/regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ def argparser(parser):
"/Grafana Datasource Plugin For Clickhouse/functions/rate function/rate_space_in_variable/*": [
(Fail, "Functions do not support escaping")
],
"/Grafana Datasource Plugin For Clickhouse/e2e/many categories/*": [
(Fail, "Waiting for the fix https://github.com/Altinity/clickhouse-grafana/issues/705")
],
# "/Grafana Datasource Plugin For Clickhouse/e2e/many categories/*": [
# (Fail, "Waiting for the fix https://github.com/Altinity/clickhouse-grafana/issues/705")
# ],
# "/Grafana Datasource Plugin For Clickhouse/adhoc macro/*": [
# (Fail, "https://github.com/Altinity/clickhouse-grafana/pull/655")
# ]
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/testflows/screenshots/toUInt64_panel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions tests/testflows/steps/panel/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,15 +688,15 @@ def save_dashboard(self):
click_save_confirmation_button()

@TestStep(When)
def check_no_labels(self, labels):
def check_no_labels_on_visualization(self, labels):
"""Check there is no labels in the panel."""

for label in labels:
with By(f"searching for label {label}"):
try:
ui.wait_for_element_to_be_visible(
select_type=SelectBy.XPATH,
element=f'//*[contains(text(), "{label}")]'
element=f'//*[@data-viz-panel-key]//*[contains(text(), "{label}")]'
)
return False
except:
Expand Down
2 changes: 1 addition & 1 deletion tests/testflows/tests/automated/e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def many_categories(self):

with Then("I check there is no errors on the visualization"):
with delay():
assert panel.check_no_labels(labels=["normalized_query_hash", "Too many points"]), error()
assert panel.check_no_labels_on_visualization(labels=["normalized_query_hash", "Too many points"]), error()
finally:
with Finally("I discard changes for panel"):
with delay():
Expand Down

0 comments on commit 6c9fa01

Please sign in to comment.