Repository: tobymao/sqlglot

Issue:
Spark `array` call starting with `time` ParseError
I installed sqlglot from git using pip.
```
pip install git+https://github.com/tobymao/sqlglot.git

Collecting git+https://github.com/tobymao/sqlglot.git
  Cloning https://github.com/tobymao/sqlglot.git to /tmp/pip-req-build-r7k14u67
  Running command git clone --filter=blob:none --quiet https://github.com/tobymao/sqlglot.git /tmp/pip-req-build-r7k14u67
  Resolved https://github.com/tobymao/sqlglot.git to commit 942165055bfe655112e38a247481f7429823e608
  Preparing metadata (setup.py) ... done
Installing collected packages: sqlglot

```

**Fully reproducible code snippet**

sqlglot gives a parsing error with the following:

```
>>> import sqlglot
>>> sqlglot.__version__
'11.6.2'

>>> sqlglot.parse_one('SELECT array(time, foo)', read='spark')

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/lib/python3.10/site-packages/sqlglot/__init__.py", line 147, in parse_one
    result = dialect.parse(sql, **opts)
  File "/lib/python3.10/site-packages/sqlglot/dialects/dialect.py", line 163, in parse
    return self.parser(**opts).parse(self.tokenize(sql), sql)
  File "/lib/python3.10/site-packages/sqlglot/parser.py", line 829, in parse
    return self._parse(
  File "/lib/python3.10/site-packages/sqlglot/parser.py", line 892, in _parse
    expressions.append(parse_method(self))
  File "/lib/python3.10/site-packages/sqlglot/parser.py", line 1040, in _parse_statement
    expression = self._parse_set_operations(expression) if expression else self._parse_select()
  File "/lib/python3.10/site-packages/sqlglot/parser.py", line 1817, in _parse_select
    expressions = self._parse_csv(self._parse_expression)
  File "/lib/python3.10/site-packages/sqlglot/parser.py", line 3950, in _parse_csv
    parse_result = parse_method()
  File "/lib/python3.10/site-packages/sqlglot/parser.py", line 2615, in _parse_expression
    return self._parse_alias(self._parse_conjunction())
  File "/lib/python3.10/site-packages/sqlglot/parser.py", line 2618, in _parse_conjunction
    return self._parse_tokens(self._parse_equality, self.CONJUNCTION)
  File "/lib/python3.10/site-packages/sqlglot/parser.py", line 3966, in _parse_tokens
    this = parse_method()
  File "/lib/python3.10/site-packages/sqlglot/parser.py", line 2621, in _parse_equality
    return self._parse_tokens(self._parse_comparison, self.EQUALITY)
  File "/lib/python3.10/site-packages/sqlglot/parser.py", line 3966, in _parse_tokens
    this = parse_method()
  File "/lib/python3.10/site-packages/sqlglot/parser.py", line 2624, in _parse_comparison
    return self._parse_tokens(self._parse_range, self.COMPARISON)
  File "/lib/python3.10/site-packages/sqlglot/parser.py", line 3966, in _parse_tokens
    this = parse_method()
  File "/lib/python3.10/site-packages/sqlglot/parser.py", line 2627, in _parse_range
    this = self._parse_bitwise()
  File "/lib/python3.10/site-packages/sqlglot/parser.py", line 2719, in _parse_bitwise
    this = self._parse_term()
  File "/lib/python3.10/site-packages/sqlglot/parser.py", line 2742, in _parse_term
    return self._parse_tokens(self._parse_factor, self.TERM)
  File "/lib/python3.10/site-packages/sqlglot/parser.py", line 3966, in _parse_tokens
    this = parse_method()
  File "/lib/python3.10/site-packages/sqlglot/parser.py", line 2745, in _parse_factor
    return self._parse_tokens(self._parse_unary, self.FACTOR)
  File "/lib/python3.10/site-packages/sqlglot/parser.py", line 3966, in _parse_tokens
    this = parse_method()
  File "/lib/python3.10/site-packages/sqlglot/parser.py", line 2750, in _parse_unary
    return self._parse_at_time_zone(self._parse_type())
  File "/lib/python3.10/site-packages/sqlglot/parser.py", line 2758, in _parse_type
    data_type = self._parse_types(check_func=True)
  File "/lib/python3.10/site-packages/sqlglot/parser.py", line 2804, in _parse_types
    self._match_r_paren()
  File "/lib/python3.10/site-packages/sqlglot/parser.py", line 4365, in _match_r_paren
    self.raise_error("Expecting )")
  File "/lib/python3.10/site-packages/sqlglot/parser.py", line 938, in raise_error
    raise error

sqlglot.errors.ParseError: Expecting ). Line 1, Col: 23.
  SELECT array(time, foo)
```

Variations of this same query do parse correctly.
```
SELECT array(time)
SELECT time
SELECT array(`time`, foo)
SELECT array(foo, time, foo)
SELECT array(foo, time)
```

**Official Documentation**

I don't have any official documentation, but `time` is a column name and the query works when sending to Spark 2.4.

Related issues
- https://github.com/tobymao/sqlglot/issues/954
- https://github.com/tobymao/sqlglot/issues/225



Discussion:
Thanks for the report, I'm gonna take a look.

Resolving patch:
diff --git a/sqlglot/parser.py b/sqlglot/parser.py
--- a/sqlglot/parser.py
+++ b/sqlglot/parser.py
@@ -2793,7 +2793,7 @@ def _parse_types(self, check_func: bool = False) -> t.Optional[exp.Expression]:
             if is_struct:
                 expressions = self._parse_csv(self._parse_struct_kwargs)
             elif nested:
-                expressions = self._parse_csv(self._parse_types)
+                expressions = self._parse_csv(lambda: self._parse_types() or self._parse_bitwise())
             else:
                 expressions = self._parse_csv(self._parse_conjunction)
 


Test patch:
diff --git a/tests/fixtures/identity.sql b/tests/fixtures/identity.sql
--- a/tests/fixtures/identity.sql
+++ b/tests/fixtures/identity.sql
@@ -100,6 +100,8 @@ CURRENT_DATE AT TIME ZONE zone_column
 CURRENT_DATE AT TIME ZONE 'UTC' AT TIME ZONE 'Asia/Tokio'
 ARRAY()
 ARRAY(1, 2)
+ARRAY(time, foo)
+ARRAY(foo, time)
 ARRAY_CONTAINS(x, 1)
 EXTRACT(x FROM y)
 EXTRACT(DATE FROM y)
diff --git a/tests/test_expressions.py b/tests/test_expressions.py
--- a/tests/test_expressions.py
+++ b/tests/test_expressions.py
@@ -528,6 +528,7 @@ def test_functions(self):
         self.assertIsInstance(parse_one("VARIANCE_POP(a)"), exp.VariancePop)
         self.assertIsInstance(parse_one("YEAR(a)"), exp.Year)
         self.assertIsInstance(parse_one("HLL(a)"), exp.Hll)
+        self.assertIsInstance(parse_one("ARRAY(time, foo)"), exp.Array)
 
     def test_column(self):
         column = parse_one("a.b.c.d")