Repository: tobymao/sqlglot

Issue:
BUG: can not parse presto sql
Hi

Below is valid presto sql which sqlglot can not parse. Can you please fix it.

```
WITH
    A(filter) AS (
        VALUES 1, 2, 3
    )

SELECT
    *
FROM
    A
WHERE
    filter >= 2
```


Discussion:

Patch:
diff --git a/sqlglot/parser.py b/sqlglot/parser.py
index 1324d77c..2c9d9e0b 100644
--- a/sqlglot/parser.py
+++ b/sqlglot/parser.py
@@ -169,6 +169,7 @@ class Parser(metaclass=_Parser):
         TokenType.ESCAPE,
         TokenType.FALSE,
         TokenType.FIRST,
+        TokenType.FILTER,
         TokenType.FOLLOWING,
         TokenType.FORMAT,
         TokenType.FUNCTION,
@@ -1155,9 +1156,19 @@ class Parser(metaclass=_Parser):
             self._match_r_paren()
             this = self._parse_subquery(this)
         elif self._match(TokenType.VALUES):
+            if self._curr.token_type == TokenType.L_PAREN:
+                # We don't consume the left paren because it's consumed in _parse_value
+                expressions = self._parse_csv(self._parse_value)
+            else:
+                # In presto we can have VALUES 1, 2 which results in 1 column & 2 rows.
+                # Source: https://prestodb.io/docs/current/sql/values.html
+                expressions = self._parse_csv(
+                    lambda: self.expression(exp.Tuple, expressions=[self._parse_conjunction()])
+                )
+
             this = self.expression(
                 exp.Values,
-                expressions=self._parse_csv(self._parse_value),
+                expressions=expressions,
                 alias=self._parse_table_alias(),
             )
         else:


Test patch:
diff --git a/tests/test_transpile.py b/tests/test_transpile.py
index 7bf53e5f..fc8d9ef0 100644
--- a/tests/test_transpile.py
+++ b/tests/test_transpile.py
@@ -28,7 +28,7 @@ class TestTranspile(unittest.TestCase):
         self.assertEqual(transpile("SELECT 1 current_datetime")[0], "SELECT 1 AS current_datetime")
         self.assertEqual(transpile("SELECT 1 row")[0], "SELECT 1 AS row")
 
-        for key in ("union", "filter", "over", "from", "join"):
+        for key in ("union", "over", "from", "join"):
             with self.subTest(f"alias {key}"):
                 self.validate(f"SELECT x AS {key}", f"SELECT x AS {key}")
                 self.validate(f'SELECT x "{key}"', f'SELECT x AS "{key}"')
@@ -263,6 +263,10 @@ FROM bar /* comment 5 */, tbl /*          comment 6 */""",
             "WITH a AS (SELECT 1), WITH b AS (SELECT 2) SELECT *",
             "WITH a AS (SELECT 1), b AS (SELECT 2) SELECT *",
         )
+        self.validate(
+            "WITH A(filter) AS (VALUES 1, 2, 3) SELECT * FROM A WHERE filter >= 2",
+            "WITH A(filter) AS (VALUES (1), (2), (3)) SELECT * FROM A WHERE filter >= 2",
+        )
 
     def test_time(self):
         self.validate("TIMESTAMP '2020-01-01'", "CAST('2020-01-01' AS TIMESTAMP)")