Merging upstream version 16.4.0.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
8a4abed982
commit
71f21d9752
90 changed files with 35638 additions and 33343 deletions
|
@ -1,12 +1,15 @@
|
|||
from sqlglot import exp
|
||||
from sqlglot._typing import E
|
||||
from sqlglot.dialects.dialect import RESOLVES_IDENTIFIERS_AS_UPPERCASE, DialectType
|
||||
from sqlglot.dialects.dialect import Dialect, DialectType
|
||||
|
||||
|
||||
def normalize_identifiers(expression: E, dialect: DialectType = None) -> E:
|
||||
"""
|
||||
Normalize all unquoted identifiers to either lower or upper case, depending on
|
||||
the dialect. This essentially makes those identifiers case-insensitive.
|
||||
Normalize all unquoted identifiers to either lower or upper case, depending
|
||||
on the dialect. This essentially makes those identifiers case-insensitive.
|
||||
|
||||
Note:
|
||||
Some dialects (e.g. BigQuery) treat identifiers as case-insensitive even
|
||||
when they're quoted, so in these cases all identifiers are normalized.
|
||||
|
||||
Example:
|
||||
>>> import sqlglot
|
||||
|
@ -21,16 +24,4 @@ def normalize_identifiers(expression: E, dialect: DialectType = None) -> E:
|
|||
Returns:
|
||||
The transformed expression.
|
||||
"""
|
||||
return expression.transform(_normalize, dialect, copy=False)
|
||||
|
||||
|
||||
def _normalize(node: exp.Expression, dialect: DialectType = None) -> exp.Expression:
|
||||
if isinstance(node, exp.Identifier) and not node.quoted:
|
||||
node.set(
|
||||
"this",
|
||||
node.this.upper()
|
||||
if dialect in RESOLVES_IDENTIFIERS_AS_UPPERCASE
|
||||
else node.this.lower(),
|
||||
)
|
||||
|
||||
return node
|
||||
return expression.transform(Dialect.get_or_raise(dialect).normalize_identifier, copy=False)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue