Skip to content

Hive should not successfully parse the factorial operator #1473

Closed
@wugeer

Description

@wugeer

Hive does not support the syntax a!, although it is supported in Postgres. However, the current project's Hive dialect supports the select a! clause.

cargo run --features json_example --example cli test.sql  --hive
   Compiling sqlparser v0.51.0 (/home/xiehw/code/person/rust/sqlparser-rs)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 5.61s
     Running `target/debug/examples/cli test.sql --hive`
Parsing from file 'test.sql' using HiveDialect
2024-10-12T07:43:55.615Z DEBUG [sqlparser::parser] Parsing sql 'select a!
'...
2024-10-12T07:43:55.615Z DEBUG [sqlparser::parser] parsing expr
2024-10-12T07:43:55.615Z DEBUG [sqlparser::parser] prefix: Identifier(Ident { value: "a", quote_style: None })
2024-10-12T07:43:55.615Z DEBUG [sqlparser::dialect] get_next_precedence_full() TokenWithLocation { token: ExclamationMark, location: Location { line: 1, column: 9 } }
2024-10-12T07:43:55.615Z DEBUG [sqlparser::parser] next precedence: 50
2024-10-12T07:43:55.615Z DEBUG [sqlparser::dialect] get_next_precedence_full() TokenWithLocation { token: EOF, location: Location { line: 0, column: 0 } }
2024-10-12T07:43:55.615Z DEBUG [sqlparser::parser] next precedence: 0
Round-trip:
'SELECT a!'
Serialized as JSON:
[
  {
    "Query": {
      "with": null,
      "body": {
        "Select": {
          "distinct": null,
          "top": null,
          "projection": [
            {
              "UnnamedExpr": {
                "UnaryOp": {
                  "op": "PGPostfixFactorial",
                  "expr": {
                    "Identifier": {
                      "value": "a",
                      "quote_style": null
                    }
                  }
                }
              }
            }
          ],
          "into": null,
          "from": [],
          "lateral_views": [],
          "prewhere": null,
          "selection": null,
          "group_by": {
            "Expressions": [
              [],
              []
            ]
          },
          "cluster_by": [],
          "distribute_by": [],
          "sort_by": [],
          "having": null,
          "named_window": [],
          "qualify": null,
          "window_before_qualify": false,
          "value_table_mode": null,
          "connect_by": null
        }
      },
      "order_by": null,
      "limit": null,
      "limit_by": [],
      "offset": null,
      "fetch": null,
      "locks": [],
      "for_clause": null,
      "settings": null,
      "format_clause": null
    }
  }
]

The expected result is to throw an exception.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions