Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript type for Select.distinct does not match runtime value when parsing Snowflake SQL #2220

Open
chris-codaio opened this issue Nov 16, 2024 · 0 comments
Assignees

Comments

@chris-codaio
Copy link

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:

  • options is any-typed. Can we strongly type it?
  • columns is carrying an any[] option - can we eliminate that in favor of strong typing?
  • groupby is declared as being a mandatory object, but we see null at runtime.
  • having is any-typed. Can we strongly type it?
  • qualify is declared as any[] | null | undefined. Why does that field support both null and undefined when the others don't? Can we strongly type the any[] away?
  • limit is returned with a useless object at runtime, but should probably be null?
  • window is declared as window?: WindowExpr, but we see null at runtime. Maybe fix the type to be window: WindowExpr | null to match the other fields?
  • Why have both _limit and limit? Same with orderby and _orderby?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants