Repository: tobymao/sqlglot

Issue:
Parser error for Snowflake SQL when "window" is used as an alias
Hi All,

Trying to parse our Snowflake queries to perform some validations. Parser fails when the keyword "window" is used as an alias for a table. The SQL executes fine on Snowflake though. 

Code:

```
parsed_sql = parse_one(
    """
     SELECT
        dd.delivery_id
    FROM prod.public.orders o
    LEFT JOIN orders.public.order_assignment window on o.order_id = window.order_id
    WHERE active_dt BETWEEN '2023-06-28' and '2023-09-27'
  """,
    read="snowflake"
)
print(parsed_sql)
```

Error:

```
sqlglot.errors.ParseError: Invalid expression / Unexpected token. Line 5, Col: 57.
  d.delivery_id
    FROM prod.public.orders o
    LEFT JOIN orders.public.order_assignment window on o.order_id = window.order_id
    WHERE active_dt BETWEEN '2023-06-28' and '2023-09-27'
```

`sqlglot version - 18.8.0`

Discussion:

Patch:
diff --git a/sqlglot/dialects/snowflake.py b/sqlglot/dialects/snowflake.py
index 0ba6a113..5131726e 100644
--- a/sqlglot/dialects/snowflake.py
+++ b/sqlglot/dialects/snowflake.py
@@ -239,6 +239,8 @@ class Snowflake(Dialect):
     class Parser(parser.Parser):
         IDENTIFY_PIVOT_STRINGS = True
 
+        TABLE_ALIAS_TOKENS = parser.Parser.TABLE_ALIAS_TOKENS | {TokenType.WINDOW}
+
         FUNCTIONS = {
             **parser.Parser.FUNCTIONS,
             "ARRAYAGG": exp.ArrayAgg.from_arg_list,


Test patch:
diff --git a/tests/dialects/test_snowflake.py b/tests/dialects/test_snowflake.py
index a85dc841..b96b7ee8 100644
--- a/tests/dialects/test_snowflake.py
+++ b/tests/dialects/test_snowflake.py
@@ -50,6 +50,10 @@ class TestSnowflake(Validator):
         self.validate_identity(
             "SELECT state, city, SUM(retail_price * quantity) AS gross_revenue FROM sales GROUP BY ALL"
         )
+        self.validate_identity(
+            "SELECT * FROM foo window",
+            "SELECT * FROM foo AS window",
+        )
         self.validate_identity(
             r"SELECT RLIKE(a, $$regular expression with \ characters: \d{2}-\d{3}-\d{4}$$, 'i') FROM log_source",
             r"SELECT REGEXP_LIKE(a, 'regular expression with \\ characters: \\d{2}-\\d{3}-\\d{4}', 'i') FROM log_source",