Skip to content

Commit

Permalink
Feat: set misc. dialect settings if available (#3649)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgesittas authored Jun 13, 2024
1 parent 4c82c0d commit e7a158b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion sqlglot/dialects/dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,13 +410,15 @@ def format_time(
return expression

def __init__(self, **kwargs) -> None:
normalization_strategy = kwargs.get("normalization_strategy")
normalization_strategy = kwargs.pop("normalization_strategy", None)

if normalization_strategy is None:
self.normalization_strategy = self.NORMALIZATION_STRATEGY
else:
self.normalization_strategy = NormalizationStrategy(normalization_strategy.upper())

self.settings = kwargs

def __eq__(self, other: t.Any) -> bool:
# Does not currently take dialect state into account
return type(self) == other
Expand Down
6 changes: 6 additions & 0 deletions tests/dialects/test_dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ def test_get_or_raise(self):

self.assertEqual(str(cm.exception), "Unknown dialect 'asdfjasodiufjsd'.")

oracle_with_settings = Dialect.get_or_raise(
"oracle, normalization_strategy = lowercase, version = 19.5"
)
self.assertEqual(oracle_with_settings.normalization_strategy.value, "LOWERCASE")
self.assertEqual(oracle_with_settings.settings, {"version": "19.5"})

def test_compare_dialects(self):
bigquery_class = Dialect["bigquery"]
bigquery_object = BigQuery()
Expand Down

0 comments on commit e7a158b

Please sign in to comment.