-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DH-5457] Add MS SQL Server support (#422)
- Loading branch information
1 parent
2230e78
commit 396eb5f
Showing
6 changed files
with
59 additions
and
2 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,38 @@ | ||
from overrides import override | ||
from sqlalchemy.exc import SQLAlchemyError | ||
from sqlalchemy.sql.schema import Column | ||
|
||
from dataherald.db_scanner.models.types import QueryHistory | ||
from dataherald.db_scanner.services.abstract_scanner import AbstractScanner | ||
from dataherald.sql_database.base import SQLDatabase | ||
|
||
MIN_CATEGORY_VALUE = 1 | ||
MAX_CATEGORY_VALUE = 100 | ||
MAX_LOGS = 5_000 | ||
|
||
|
||
class SqlServerScanner(AbstractScanner): | ||
@override | ||
def cardinality_values(self, column: Column, db_engine: SQLDatabase) -> list | None: | ||
try: | ||
count_query = f"SELECT APPROX_COUNT_DISTINCT({column.name}) FROM {column.table.name}" # noqa: S608 | ||
rs = db_engine.engine.execute(count_query).fetchall() | ||
except SQLAlchemyError: | ||
return None | ||
|
||
if ( | ||
len(rs) > 0 | ||
and len(rs[0]) > 0 | ||
and MIN_CATEGORY_VALUE < rs[0][0] <= MAX_CATEGORY_VALUE | ||
): | ||
cardinality_query = f"SELECT TOP 101 {column.name} FROM (SELECT DISTINCT {column.name} FROM [{column.table.name}]) AS subquery;" # noqa: E501 S608 | ||
cardinality = db_engine.engine.execute(cardinality_query).fetchall() | ||
return [str(category[0]) for category in cardinality] | ||
|
||
return None | ||
|
||
@override | ||
def get_logs( | ||
self, table: str, db_engine: SQLDatabase, db_connection_id: str # noqa: ARG002 | ||
) -> list[QueryHistory]: | ||
return [] |
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 |
---|---|---|
|
@@ -216,6 +216,21 @@ Example:: | |
|
||
"connection_uri": mysql+pymysql://admin:[email protected]:3306/my-database | ||
|
||
Microsoft SQL Server | ||
^^^^^^^^^^^^ | ||
|
||
Uri structure:: | ||
|
||
"connection_uri": mssql+pymssql://<user>:<password>@<host>:<port>/<db-name> | ||
|
||
Example:: | ||
|
||
"connection_uri": mssql+pymssql://admin:[email protected]:1433/my-database | ||
|
||
To specify a schema other than the default dbo, execute the following command:: | ||
|
||
ALTER USER <your_username> WITH DEFAULT_SCHEMA = <your_schema_name>; | ||
|
||
Databricks | ||
^^^^^^^^^^^^ | ||
|
||
|
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 |
---|---|---|
|
@@ -42,3 +42,4 @@ duckdb==0.9.1 | |
PyMySQL==1.1.0 | ||
clickhouse-sqlalchemy==0.2.5 | ||
astrapy==0.7.6 | ||
pymssql==2.2.11 |