Skip to content

Commit

Permalink
support array indexing in AST
Browse files Browse the repository at this point in the history
  • Loading branch information
r.khavronenko committed Feb 12, 2018
1 parent f8fc0f6 commit 6fbd2b9
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 11 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 1.3.1 (2018-02-12)

## Fixes

* support array indexing int AST


# 1.3.0 (2018-02-07)

## New Features
Expand Down
7 changes: 7 additions & 0 deletions dist/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 1.3.1 (2018-02-12)

## Fixes

* support array indexing int AST


# 1.3.0 (2018-02-07)

## New Features
Expand Down
2 changes: 1 addition & 1 deletion dist/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
"url": "https://github.com/Vertamedia/clickhouse-grafana"
}
],
"version": "1.3.0"
"version": "1.3.1"
}
}
3 changes: 2 additions & 1 deletion dist/scanner.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/scanner.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export default class Scanner {
let subQuery = '',
argument = '';

while (this.next()) {
while (this.next()) {debugger
if (!this.isExpectedNext() && isStatement(this.token) && !this.tree.hasOwnProperty(_.toLower(this.token))) {
if (!isClosured(argument)) {
argument += this.token;
Expand Down Expand Up @@ -234,10 +234,10 @@ let wsRe = "\\s+",
macroFuncRe = "(\\$rateColumns|\\$rate|\\$columns)",
condRe = "\\b(or|and)\\b",
inRe = "\\b(global in|global not in|not in|in)\\b",
closureRe = "[\\(\\)]",
closureRe = "[\\(\\)\\[\\]]",
specCharsRe = "[,?:]",
macroRe = "\\$[A-Za-z0-9_$]+",
skipSpaceRe = "[\\(\\.! ]",
skipSpaceRe = "[\\(\\.! \\[]",

builtInFuncRe = "\\b(avg|countIf|first|last|max|min|sum|sumIf|ucase|lcase|mid|round|rank|now|" +
"coalesce|ifnull|isnull|nvl|count|timeSlot|yesterday|today|now|toRelativeSecondNum|" +
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vertamedia-clickhouse",
"version": "1.3.0",
"version": "1.3.1",
"description": "ClickHouse datasource for Grafana",
"scripts": {
"build": "grunt",
Expand Down
23 changes: 23 additions & 0 deletions specs/scanner_specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,4 +341,27 @@ describe("scanner:", () => {
expect(scanner.toAST()).to.eql(expectedAST);
});
});

describe("AST case 10(array)", () => {
let query = "SELECT count() FROM $table WHERE type[1] = 'key' AND zone['City'] = 'Kyiv'",
scanner = new Scanner(query);

let expectedAST = {
"root": [],
"select": [
"count()"
],
"from": [
"$table"
],
"where": [
"type[1] = 'key'",
"AND zone['City'] = 'Kyiv'",
],
};

it("expects equality", () => {
expect(scanner.toAST()).to.eql(expectedAST);
});
});
});
2 changes: 1 addition & 1 deletion src/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
"url": "https://github.com/Vertamedia/clickhouse-grafana"
}
],
"version": "1.3.0"
"version": "1.3.1"
}
}
6 changes: 3 additions & 3 deletions src/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export default class Scanner {
let subQuery = '',
argument = '';

while (this.next()) {
while (this.next()) {debugger
if (!this.isExpectedNext() && isStatement(this.token) && !this.tree.hasOwnProperty(_.toLower(this.token))) {
if (!isClosured(argument)) {
argument += this.token;
Expand Down Expand Up @@ -234,10 +234,10 @@ let wsRe = "\\s+",
macroFuncRe = "(\\$rateColumns|\\$rate|\\$columns)",
condRe = "\\b(or|and)\\b",
inRe = "\\b(global in|global not in|not in|in)\\b",
closureRe = "[\\(\\)]",
closureRe = "[\\(\\)\\[\\]]",
specCharsRe = "[,?:]",
macroRe = "\\$[A-Za-z0-9_$]+",
skipSpaceRe = "[\\(\\.! ]",
skipSpaceRe = "[\\(\\.! \\[]",

builtInFuncRe = "\\b(avg|countIf|first|last|max|min|sum|sumIf|ucase|lcase|mid|round|rank|now|" +
"coalesce|ifnull|isnull|nvl|count|timeSlot|yesterday|today|now|toRelativeSecondNum|" +
Expand Down

0 comments on commit 6fbd2b9

Please sign in to comment.