Skip to content

Commit

Permalink
BREAKING! Make SELECT clause columns optional
Browse files Browse the repository at this point in the history
  • Loading branch information
nene committed Nov 8, 2023
1 parent 0f98a6d commit 824386c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/cst/Select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export interface SelectClause extends BaseNode {
distinctKw?: Keyword<"ALL" | "DISTINCT" | "DISTINCTROW">;
hints: MysqlHint[];
asStructOrValueKw?: [Keyword<"AS">, Keyword<"STRUCT" | "VALUE">];
columns: ListExpr<
columns?: ListExpr<
AllColumns | ExceptColumns | ReplaceColumns | Expr | Alias<Expr> | Empty
>;
}
Expand Down
22 changes: 22 additions & 0 deletions test/select/select.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,28 @@ describe("select", () => {
test(`SELECT FROM tbl;`);
test(`SELECT;`);
});

it("parses empty select into undefined columns field", () => {
expect(parseStmt(`SELECT`)).toMatchInlineSnapshot(`
{
"clauses": [
{
"asStructOrValueKw": undefined,
"columns": undefined,
"distinctKw": undefined,
"hints": [],
"selectKw": {
"name": "SELECT",
"text": "SELECT",
"type": "keyword",
},
"type": "select_clause",
},
],
"type": "select_stmt",
}
`);
});
});

dialect("bigquery", () => {
Expand Down
4 changes: 2 additions & 2 deletions test/test_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ export function parseExpr(
if (clause.type !== "select_clause") {
throw new Error(`Expected select_clause, instead got ${clause.type}`);
}
if (clause.columns.items.length !== 1) {
if (clause.columns?.items.length !== 1) {
throw new Error(
`Expected 1 column, instead got ${clause.columns.items.length}`
`Expected 1 column, instead got ${clause.columns?.items.length ?? 0}`
);
}
const result = clause.columns.items[0];
Expand Down

0 comments on commit 824386c

Please sign in to comment.