-
Notifications
You must be signed in to change notification settings - Fork 609
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(backends/mssql): add backend support for Microsoft Sql Server
- Loading branch information
Showing
31 changed files
with
781 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
DROP TABLE IF EXISTS diamonds; | ||
|
||
CREATE TABLE diamonds ( | ||
carat FLOAT, | ||
cut VARCHAR(MAX), | ||
color VARCHAR(MAX), | ||
clarity VARCHAR(MAX), | ||
depth FLOAT, | ||
"table" FLOAT, | ||
price BIGINT, | ||
x FLOAT, | ||
y FLOAT, | ||
z FLOAT | ||
); | ||
|
||
DROP TABLE IF EXISTS batting; | ||
|
||
CREATE TABLE batting ( | ||
"playerID" VARCHAR(MAX), | ||
"yearID" BIGINT, | ||
stint BIGINT, | ||
"teamID" VARCHAR(MAX), | ||
"lgID" VARCHAR(MAX), | ||
"G" BIGINT, | ||
"AB" BIGINT, | ||
"R" BIGINT, | ||
"H" BIGINT, | ||
"X2B" BIGINT, | ||
"X3B" BIGINT, | ||
"HR" BIGINT, | ||
"RBI" BIGINT, | ||
"SB" BIGINT, | ||
"CS" BIGINT, | ||
"BB" BIGINT, | ||
"SO" BIGINT, | ||
"IBB" BIGINT, | ||
"HBP" BIGINT, | ||
"SH" BIGINT, | ||
"SF" BIGINT, | ||
"GIDP" BIGINT | ||
); | ||
|
||
DROP TABLE IF EXISTS awards_players; | ||
|
||
CREATE TABLE awards_players ( | ||
"playerID" VARCHAR(MAX), | ||
"awardID" VARCHAR(MAX), | ||
"yearID" BIGINT, | ||
"lgID" VARCHAR(MAX), | ||
tie VARCHAR(MAX), | ||
notes VARCHAR(MAX) | ||
); | ||
|
||
DROP TABLE IF EXISTS functional_alltypes; | ||
|
||
CREATE TABLE functional_alltypes ( | ||
"index" BIGINT, | ||
"Unnamed: 0" BIGINT, | ||
id INTEGER, | ||
bool_col BIT, | ||
tinyint_col SMALLINT, | ||
smallint_col SMALLINT, | ||
int_col INTEGER, | ||
bigint_col BIGINT, | ||
float_col REAL, | ||
double_col DOUBLE PRECISION, | ||
date_string_col VARCHAR(MAX), | ||
string_col VARCHAR(MAX), | ||
timestamp_col DATETIME2, | ||
year INTEGER, | ||
month INTEGER | ||
); | ||
|
||
CREATE INDEX "ix_functional_alltypes_index" ON functional_alltypes ("index"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"""The Microsoft Sql Server backend.""" | ||
|
||
from __future__ import annotations | ||
|
||
from typing import Literal | ||
|
||
import sqlalchemy as sa | ||
|
||
from ibis.backends.base.sql.alchemy import BaseAlchemyBackend | ||
from ibis.backends.mssql.compiler import MsSqlCompiler | ||
|
||
|
||
class Backend(BaseAlchemyBackend): | ||
name = "mssql" | ||
compiler = MsSqlCompiler | ||
|
||
def do_connect( | ||
self, | ||
host: str = "localhost", | ||
user: str | None = None, | ||
password: str | None = None, | ||
port: int = 1433, | ||
database: str | None = None, | ||
url: str | None = None, | ||
driver: Literal["pymssql"] = "pymssql", | ||
) -> None: | ||
if driver != "pymssql": | ||
raise NotImplementedError("pymssql is currently the only supported driver") | ||
alchemy_url = self._build_alchemy_url( | ||
url=url, | ||
host=host, | ||
port=port, | ||
user=user, | ||
password=password, | ||
database=database, | ||
driver=f'mssql+{driver}', | ||
) | ||
self.database_name = alchemy_url.database | ||
super().do_connect(sa.create_engine(alchemy_url)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import sqlalchemy as sa | ||
from sqlalchemy.dialects import mssql | ||
|
||
import ibis.expr.datatypes as dt | ||
from ibis.backends.base.sql.alchemy import AlchemyCompiler, AlchemyExprTranslator | ||
from ibis.backends.mssql.registry import operation_registry | ||
|
||
|
||
class MsSqlExprTranslator(AlchemyExprTranslator): | ||
_registry = operation_registry | ||
_rewrites = AlchemyExprTranslator._rewrites.copy() | ||
_type_map = AlchemyExprTranslator._type_map.copy() | ||
_type_map.update( | ||
{ | ||
dt.Boolean: mssql.BIT, | ||
dt.Int8: mssql.TINYINT, | ||
dt.Int16: mssql.SMALLINT, | ||
dt.Int32: mssql.INTEGER, | ||
dt.Int64: mssql.BIGINT, | ||
dt.Float16: mssql.FLOAT, | ||
dt.Float32: mssql.FLOAT, | ||
dt.Float64: mssql.REAL, | ||
dt.String: mssql.NVARCHAR, | ||
} | ||
) | ||
_bool_aggs_need_cast_to_int32 = True | ||
integer_to_timestamp = sa.func.from_unixtime | ||
native_json_type = False | ||
|
||
|
||
rewrites = MsSqlExprTranslator.rewrites | ||
|
||
|
||
class MsSqlCompiler(AlchemyCompiler): | ||
translator_class = MsSqlExprTranslator |
Oops, something went wrong.