taozhi8833998 / taozhi8833998/node-sql-parser
Typescript type for Select.distinct does not match runtime value when parsing Snowflake SQL
@taozhi8833998 is already working on this.
Since Nov 16, 2024.
- Dominant language
- PEG.js
- Stars
- 1k
- Forks
- 244
- PR merge metrics
- No merged PRs in 30d
Description
Describe the bug
Typescript type for Select.distinct does not match runtime value when parsing Snowflake SQL.
Database Engine
Snowflake
To Reproduce
node-sql-parser version: 5.3.4
node version: 22.11.0
parser.astify('SELECT * from foo;', {database: 'Snowflake'});
[
{
with: null,
type: 'select',
options: null,
distinct: { type: null },
columns: [ [Object] ],
into: { position: null },
from: [ [Object] ],
where: null,
groupby: null,
having: null,
qualify: null,
orderby: null,
top: null,
limit: { seperator: '', value: [] },
window: null
}
]
Expected behavior
Declared type as follows. Note that distinct should be the string DISTINCT or null, but is {type: null} at runtime.
export interface Select {
with: With[] | null;
type: "select";
options: any[] | null;
distinct: "DISTINCT" | null;
columns: any[] | Column[];
from: From[] | TableExpr | null ;
where: Binary | Function | null;
groupby: { columns: ColumnRef[] | null, modifiers: ValueExpr<string>[] };
having: any[] | null;
orderby: OrderBy[] | null;
limit: Limit | null;
window?: WindowExpr;
qualify?: any[] | null;
_orderby?: OrderBy[] | null;
_limit?: Limit | null;
parentheses_symbol?: boolean;
_parentheses?: boolean;
loc?: LocationRange;
_next?: Select;
set_op?: string;
}
As a side note, there are some other mismatched/broken types in here. Examples include:
optionsis any-typed. Can we strongly type it?columnsis carrying anany[]option - can we eliminate that in favor of strong typing?groupbyis declared as being a mandatory object, but we seenullat runtime.havingis any-typed. Can we strongly type it?qualifyis declared asany[] | null | undefined. Why does that field support bothnullandundefinedwhen the others don't? Can we strongly type theany[]away?limitis returned with a useless object at runtime, but should probably benull?windowis declared aswindow?: WindowExpr, but we seenullat runtime. Maybe fix the type to bewindow: WindowExpr | nullto match the other fields?- Why have both
_limitandlimit? Same withorderbyand_orderby?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.