-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jorrit Sandbrink
committed
Jan 18, 2024
1 parent
77b070d
commit 7bc2163
Showing
28 changed files
with
672 additions
and
72 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
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
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,58 @@ | ||
# Set up loader user | ||
Execute the following SQL statements to set up the [loader](https://learn.microsoft.com/en-us/azure/synapse-analytics/sql/data-loading-best-practices#create-a-loading-user) user: | ||
```sql | ||
-- on master database | ||
|
||
CREATE LOGIN loader WITH PASSWORD = 'YOUR_LOADER_PASSWORD_HERE'; | ||
``` | ||
|
||
```sql | ||
-- on minipool database | ||
|
||
CREATE USER loader FOR LOGIN loader; | ||
|
||
-- DDL permissions | ||
GRANT CREATE TABLE ON DATABASE :: minipool TO loader; | ||
GRANT CREATE VIEW ON DATABASE :: minipool TO loader; | ||
|
||
-- DML permissions | ||
GRANT SELECT ON DATABASE :: minipool TO loader; | ||
GRANT INSERT ON DATABASE :: minipool TO loader; | ||
GRANT ADMINISTER DATABASE BULK OPERATIONS TO loader; | ||
``` | ||
|
||
```sql | ||
-- https://learn.microsoft.com/en-us/azure/synapse-analytics/sql-data-warehouse/sql-data-warehouse-workload-isolation | ||
|
||
CREATE WORKLOAD GROUP DataLoads | ||
WITH ( | ||
MIN_PERCENTAGE_RESOURCE = 0 | ||
,CAP_PERCENTAGE_RESOURCE = 50 | ||
,REQUEST_MIN_RESOURCE_GRANT_PERCENT = 25 | ||
); | ||
|
||
CREATE WORKLOAD CLASSIFIER [wgcELTLogin] | ||
WITH ( | ||
WORKLOAD_GROUP = 'DataLoads' | ||
,MEMBERNAME = 'loader' | ||
); | ||
``` | ||
|
||
# config.toml | ||
```toml | ||
[destination.synapse.credentials] | ||
database = "minipool" | ||
username = "loader" | ||
host = "dlt-synapse-ci.sql.azuresynapse.net" | ||
port = 1433 | ||
driver = "ODBC Driver 18 for SQL Server" | ||
|
||
[destination.synapse] | ||
create_indexes = false | ||
``` | ||
|
||
# secrets.toml | ||
```toml | ||
[destination.synapse.credentials] | ||
password = "YOUR_LOADER_PASSWORD_HERE" | ||
``` |
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,46 @@ | ||
from dlt.common.data_writers.escape import escape_postgres_identifier, escape_mssql_literal | ||
from dlt.common.destination import DestinationCapabilitiesContext | ||
from dlt.common.arithmetics import DEFAULT_NUMERIC_PRECISION, DEFAULT_NUMERIC_SCALE | ||
from dlt.common.wei import EVM_DECIMAL_PRECISION | ||
|
||
|
||
def capabilities() -> DestinationCapabilitiesContext: | ||
caps = DestinationCapabilitiesContext() | ||
|
||
caps.preferred_loader_file_format = "insert_values" | ||
caps.supported_loader_file_formats = ["insert_values"] | ||
caps.preferred_staging_file_format = None | ||
caps.supported_staging_file_formats = [] | ||
|
||
caps.insert_values_writer_type = "select_union" # https://stackoverflow.com/a/77014299 | ||
|
||
caps.escape_identifier = escape_postgres_identifier | ||
caps.escape_literal = escape_mssql_literal | ||
|
||
# Synapse has a max precision of 38 | ||
# https://learn.microsoft.com/en-us/sql/t-sql/statements/create-table-azure-sql-data-warehouse?view=aps-pdw-2016-au7#DataTypes | ||
caps.decimal_precision = (DEFAULT_NUMERIC_PRECISION, DEFAULT_NUMERIC_SCALE) | ||
caps.wei_precision = (DEFAULT_NUMERIC_PRECISION, 0) | ||
|
||
# https://learn.microsoft.com/en-us/sql/t-sql/statements/create-table-azure-sql-data-warehouse?view=aps-pdw-2016-au7#LimitationsRestrictions | ||
caps.max_identifier_length = 128 | ||
caps.max_column_identifier_length = 128 | ||
|
||
# https://learn.microsoft.com/en-us/azure/synapse-analytics/sql-data-warehouse/sql-data-warehouse-service-capacity-limits#queries | ||
caps.max_query_length = 65536 * 4096 | ||
caps.is_max_query_length_in_bytes = True | ||
|
||
# nvarchar(max) can store 2 GB | ||
# https://learn.microsoft.com/en-us/sql/t-sql/data-types/nchar-and-nvarchar-transact-sql?view=sql-server-ver16#nvarchar---n--max-- | ||
caps.max_text_data_type_length = 2 * 1024 * 1024 * 1024 | ||
caps.is_max_text_data_type_length_in_bytes = True | ||
|
||
# https://learn.microsoft.com/en-us/azure/synapse-analytics/sql-data-warehouse/sql-data-warehouse-develop-transactions | ||
caps.supports_transactions = True | ||
caps.supports_ddl_transactions = False | ||
|
||
# datetimeoffset can store 7 digits for fractional seconds | ||
# https://learn.microsoft.com/en-us/sql/t-sql/data-types/datetimeoffset-transact-sql?view=sql-server-ver16 | ||
caps.timestamp_precision = 7 | ||
|
||
return caps |
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 typing import Final, Any, List, Dict, Optional, ClassVar | ||
|
||
from dlt.common.configuration import configspec | ||
|
||
from dlt.destinations.impl.mssql.configuration import ( | ||
MsSqlCredentials, | ||
MsSqlClientConfiguration, | ||
) | ||
from dlt.destinations.impl.mssql.configuration import MsSqlCredentials | ||
|
||
|
||
@configspec | ||
class SynapseCredentials(MsSqlCredentials): | ||
drivername: Final[str] = "synapse" # type: ignore | ||
|
||
# LongAsMax keyword got introduced in ODBC Driver 18 for SQL Server. | ||
SUPPORTED_DRIVERS: ClassVar[List[str]] = ["ODBC Driver 18 for SQL Server"] | ||
|
||
def _get_odbc_dsn_dict(self) -> Dict[str, Any]: | ||
params = super()._get_odbc_dsn_dict() | ||
# Long types (text, ntext, image) are not supported on Synapse. | ||
# Convert to max types using LongAsMax keyword. | ||
# https://stackoverflow.com/a/57926224 | ||
params["LONGASMAX"] = "yes" | ||
return params | ||
|
||
|
||
@configspec | ||
class SynapseClientConfiguration(MsSqlClientConfiguration): | ||
destination_type: Final[str] = "synapse" # type: ignore | ||
credentials: SynapseCredentials | ||
|
||
# Determines if `primary_key` and `unique` column hints are applied. | ||
# Set to False by default because the PRIMARY KEY and UNIQUE constraints | ||
# are tricky in Synapse: they are NOT ENFORCED and can lead to innacurate | ||
# results if the user does not ensure all column values are unique. | ||
# https://learn.microsoft.com/en-us/azure/synapse-analytics/sql-data-warehouse/sql-data-warehouse-table-constraints | ||
create_indexes: bool = False |
Oops, something went wrong.