Skip to content

Commit

Permalink
Fix: bigquery udf existing func clash closes #1535
Browse files Browse the repository at this point in the history
  • Loading branch information
tobymao committed May 4, 2023
1 parent 51ca411 commit abfbce2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
8 changes: 4 additions & 4 deletions sqlglot/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2932,7 +2932,7 @@ def _parse_column(self) -> t.Optional[exp.Expression]:
else exp.Literal.string(value)
)
else:
field = self._parse_star() or self._parse_function() or self._parse_id_var()
field = self._parse_star() or self._parse_function(anonymous=True) or self._parse_id_var()

if isinstance(field, exp.Func):
# bigquery allows function calls like x.y.count(...)
Expand Down Expand Up @@ -3017,7 +3017,7 @@ def _parse_field(
)

def _parse_function(
self, functions: t.Optional[t.Dict[str, t.Callable]] = None
self, functions: t.Optional[t.Dict[str, t.Callable]] = None, anonymous: bool=False
) -> t.Optional[exp.Expression]:
if not self._curr:
return None
Expand All @@ -3043,7 +3043,7 @@ def _parse_function(

parser = self.FUNCTION_PARSERS.get(upper)

if parser:
if parser and not anonymous:
this = parser(self)
else:
subquery_predicate = self.SUBQUERY_PREDICATES.get(token_type)
Expand All @@ -3059,7 +3059,7 @@ def _parse_function(
function = functions.get(upper)
args = self._parse_csv(self._parse_lambda)

if function:
if function and not anonymous:
# Clickhouse supports function calls like foo(x, y)(z), so for these we need to also parse the
# second parameter list (i.e. "(z)") and the corresponding function will receive both arg lists.
if count_params(function) == 2:
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/identity.sql
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ ARRAY(time, foo)
ARRAY(foo, time)
ARRAY(LENGTH(waiter_name) > 0)
ARRAY_CONTAINS(x, 1)
x.EXTRACT(1)
EXTRACT(x FROM y)
EXTRACT(DATE FROM y)
EXTRACT(WEEK(monday) FROM created_at)
Expand Down
1 change: 1 addition & 0 deletions tests/test_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class TestOptimizer(unittest.TestCase):

@classmethod
def setUpClass(cls):
sqlglot.schema = MappingSchema()
cls.conn = duckdb.connect()
cls.conn.execute(
"""
Expand Down

0 comments on commit abfbce2

Please sign in to comment.