Skip to content

Commit

Permalink
Fix(optimizer): make normalize_identifiers identifier conversion more…
Browse files Browse the repository at this point in the history
… lenient (#2478)
  • Loading branch information
georgesittas committed Oct 30, 2023
1 parent 7a6da28 commit 2307910
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 5 additions & 2 deletions sqlglot/optimizer/normalize_identifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import typing as t

from sqlglot import exp, parse_one
from sqlglot import ParseError, exp, parse_one
from sqlglot._typing import E
from sqlglot.dialects.dialect import Dialect, DialectType

Expand Down Expand Up @@ -49,7 +49,10 @@ def normalize_identifiers(expression, dialect=None):
The transformed expression.
"""
if isinstance(expression, str):
expression = parse_one(expression, dialect=dialect, into=exp.Identifier)
try:
expression = parse_one(expression, dialect=dialect, into=exp.Identifier)
except ParseError:
expression = exp.to_identifier(expression)

dialect = Dialect.get_or_raise(dialect)

Expand Down
2 changes: 2 additions & 0 deletions tests/test_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ def test_normalize_identifiers(self):
set_dialect=True,
)

self.assertEqual(optimizer.normalize_identifiers.normalize_identifiers("a%").sql(), '"a%"')

def test_pushdown_projection(self):
self.check_file("pushdown_projections", pushdown_projections, schema=self.schema)

Expand Down

0 comments on commit 2307910

Please sign in to comment.