Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: add mssql and sqlserver as aliases of the TSQL dialect #4666

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions sqlglot/dialects/dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,16 @@ def get(
def __new__(cls, clsname, bases, attrs):
klass = super().__new__(cls, clsname, bases, attrs)
enum = Dialects.__members__.get(clsname.upper())

cls.classes[enum.value if enum is not None else clsname.lower()] = klass

aliases = klass.__dict__.get("ALIASES")
if aliases:
for alias in aliases:
cls.classes[alias.lower()] = klass
else:
klass.ALIASES = []

klass.TIME_TRIE = new_trie(klass.TIME_MAPPING)
klass.FORMAT_TRIE = (
new_trie(klass.FORMAT_MAPPING) if klass.FORMAT_MAPPING else klass.TIME_TRIE
Expand Down Expand Up @@ -223,6 +231,9 @@ def get_start_end(token_type: TokenType) -> t.Tuple[t.Optional[str], t.Optional[


class Dialect(metaclass=_Dialect):
ALIASES: t.List[str] = []
"""Other names by which this dialect can be referred to."""

INDEX_OFFSET = 0
"""The base index offset for arrays."""

Expand Down
2 changes: 2 additions & 0 deletions sqlglot/dialects/tsql.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,8 @@ def _build_datetrunc(args: t.List) -> exp.TimestampTrunc:


class TSQL(Dialect):
ALIASES = ["mssql", "sqlserver"]

SUPPORTS_SEMI_ANTI_JOIN = False
LOG_BASE_FIRST = False
TYPED_DIVISION = True
Expand Down
6 changes: 5 additions & 1 deletion tests/dialects/test_dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
exp,
parse_one,
)
from sqlglot.dialects import BigQuery, Hive, Snowflake
from sqlglot.dialects import BigQuery, Hive, Snowflake, TSQL
from sqlglot.parser import logger as parser_logger


Expand Down Expand Up @@ -90,6 +90,10 @@ def test_enum(self):
self.assertIsNotNone(Dialect[dialect.value])

def test_get_or_raise(self):
self.assertIsInstance(Dialect.get_or_raise("tsql"), TSQL)
self.assertIsInstance(Dialect.get_or_raise("mssql"), TSQL)
self.assertIsInstance(Dialect.get_or_raise("sqlserver"), TSQL)

self.assertIsInstance(Dialect.get_or_raise(Hive), Hive)
self.assertIsInstance(Dialect.get_or_raise(Hive()), Hive)
self.assertIsInstance(Dialect.get_or_raise("hive"), Hive)
Expand Down