Skip to content
This repository was archived by the owner on Dec 11, 2022. It is now read-only.

Commit 3a05791

Browse files
author
Tamir Klein
authored
Merge pull request #267 from doitintl/feature/lior/repeatedField
Handle repeated field at window function
2 parents 50f4123 + a3b0709 commit 3a05791

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

dist/module.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/module.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/bigquery_query.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,8 +594,14 @@ export default class BigQueryQuery {
594594
query = query + " " + orderBy;
595595
}
596596
}
597-
if (this.isWindow) {
598-
query = "\nSELECT * EXCEPT (" + this.tmpValue + ") From \n (" + query;
597+
else {
598+
const DELIMITER = '.';
599+
let starFields = "*", parent, child = this.tmpValue;
600+
if(this.tmpValue.includes(DELIMITER)){
601+
[parent, child] = this.tmpValue.split(DELIMITER);
602+
starFields += `, ${parent}.*`;
603+
}
604+
query = "\nSELECT " + starFields + " EXCEPT (" + child + ") From \n (" + query;
599605
query = query + " " + this.groupBy;
600606
}
601607

src/specs/bigquery_query.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,26 @@ describe("BigQueryQuery", () => {
229229
expect(query.buildQuery()).toBe(result);
230230
});
231231

232+
describe("Window function with except and repeated field", () => {
233+
const target = {
234+
select: [[{ type: "column", params: ["value"] }]],
235+
table: "table",
236+
timeColumn: "t",
237+
where: [],
238+
};
239+
const query = new BigQueryQuery(target, templateSrv);
240+
query.tmpValue = "t.l";
241+
query.isWindow = true;
242+
const result = "#standardSQL\nSELECT *, t.* EXCEPT (l) From \n" +
243+
" (\n" +
244+
"SELECT\n" +
245+
" `t` AS time,\n" +
246+
" `value`\n" +
247+
"FROM `undefined.undefined.table`)\n" +
248+
"GROUP BY 1,2 ";
249+
expect(query.buildQuery()).toBe(result);
250+
});
251+
232252
describe("escapeLiteral", () => {
233253
const res = BigQueryQuery.escapeLiteral("'a");
234254
expect(BigQueryQuery.escapeLiteral("'a")).toBe("''a");

0 commit comments

Comments
 (0)