Skip to content

Commit 2a90fde

Browse files
author
gdgate
authored
Merge pull request #227 from hkad98/data_sources
PSDK-110 PSDK-124 MS SQL and Databricks support Reviewed-by: https://github.com/pcerny
2 parents 1a59259 + 2949e0d commit 2a90fde

File tree

4 files changed

+112
-0
lines changed

4 files changed

+112
-0
lines changed

docs/content/en/docs/data/data-source/_index.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,40 @@ CatalogDataSourceGreenplum(
143143
),
144144
)
145145
```
146+
147+
### Microsoft SQL Server
148+
149+
```python
150+
CatalogDataSourceMsSql(
151+
id=data_source_id,
152+
name=data_source_name,
153+
db_specific_attributes=MsSqlAttributes(
154+
host=os.environ["MSSQL_HOST"],
155+
db_name=os.environ["MSSQL_DBNAME"]
156+
),
157+
schema=os.environ["MSSQL_SCHEMA"],
158+
credentials=BasicCredentials(
159+
username=os.environ["MSSQL_USER"],
160+
password=os.environ["MSSQL_PASSWORD"],
161+
),
162+
)
163+
```
164+
165+
### Databricks
166+
167+
```python
168+
CatalogDataSourceDatabricks(
169+
id=data_source_id,
170+
name=data_source_name,
171+
db_specific_attributes=DatabricksAttributes(
172+
host=os.environ["DATABRICKS_HOST"],
173+
http_path=os.environ["DATABRICKS_HTTP_PATH"]
174+
),
175+
schema=xyz,
176+
parameters=[{"name":"catalog", "value": os.environ["DATABRICKS_CATALOG"]}],
177+
credentials=BasicCredentials(
178+
username=os.environ["DATABRICKS_USER"],
179+
password=os.environ["DATABRICKS_PASSWORD"],
180+
),
181+
)
182+
```

gooddata-sdk/gooddata_sdk/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,16 @@
2929
from gooddata_sdk.catalog.data_source.entity_model.data_source import (
3030
CatalogDataSource,
3131
CatalogDataSourceBigQuery,
32+
CatalogDataSourceDatabricks,
3233
CatalogDataSourceGreenplum,
34+
CatalogDataSourceMsSql,
3335
CatalogDataSourcePostgres,
3436
CatalogDataSourceRedshift,
3537
CatalogDataSourceSnowflake,
3638
CatalogDataSourceVertica,
39+
DatabricksAttributes,
3740
GreenplumAttributes,
41+
MsSqlAttributes,
3842
PostgresAttributes,
3943
RedshiftAttributes,
4044
SnowflakeAttributes,

gooddata-sdk/gooddata_sdk/catalog/data_source/entity_model/data_source.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,41 @@ class CatalogDataSourceBigQuery(CatalogDataSource):
206206
class CatalogDataSourceGreenplum(CatalogDataSourcePostgres):
207207
type: str = "GREENPLUM"
208208
db_vendor: str = "postgresql"
209+
210+
211+
@attr.s(auto_attribs=True, kw_only=True)
212+
class MsSqlAttributes(DatabaseAttributes):
213+
host: str
214+
db_name: str
215+
port: str = "1433"
216+
217+
218+
@attr.s(auto_attribs=True, kw_only=True)
219+
class CatalogDataSourceMsSql(CatalogDataSource):
220+
_URL_TMPL: ClassVar[str] = "jdbc:{db_vendor}://{host}:{port};databaseName={db_name}"
221+
type: str = "MSSQL"
222+
db_vendor: str = "sqlserver"
223+
db_specific_attributes: MsSqlAttributes
224+
225+
226+
@attr.s(auto_attribs=True, kw_only=True)
227+
class DatabricksAttributes(DatabaseAttributes):
228+
host: str
229+
http_path: str
230+
port: str = "443"
231+
232+
233+
@attr.s(auto_attribs=True, kw_only=True)
234+
class CatalogDataSourceDatabricks(CatalogDataSource):
235+
_URL_TMPL: ClassVar[str] = "jdbc:{db_vendor}://{host}:{port}/default;httpPath={http_path}"
236+
type: str = "DATABRICKS"
237+
parameters: List[Dict[str, str]]
238+
db_specific_attributes: DatabricksAttributes
239+
240+
def __attrs_post_init__(self) -> None:
241+
mandatory_parameter = [parameter.get("name") == "catalog" for parameter in self.parameters]
242+
if not any(mandatory_parameter):
243+
raise ValueError(f"'catalog' is mandatory parameter for data source type {self.type}")
244+
245+
self.db_vendor = self.type.lower()
246+
self.url = self._make_url()

gooddata-sdk/tests/catalog/test_catalog_data_source.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
BasicCredentials,
1616
CatalogDataSource,
1717
CatalogDataSourceBigQuery,
18+
CatalogDataSourceDatabricks,
19+
CatalogDataSourceMsSql,
1820
CatalogDataSourcePostgres,
1921
CatalogDataSourceRedshift,
2022
CatalogDataSourceSnowflake,
@@ -25,9 +27,11 @@
2527
CatalogPdmLdmRequest,
2628
CatalogPdmSql,
2729
CatalogScanModelRequest,
30+
DatabricksAttributes,
2831
ExecutionDefinition,
2932
GoodDataApiClient,
3033
GoodDataSdk,
34+
MsSqlAttributes,
3135
PostgresAttributes,
3236
RedshiftAttributes,
3337
ScanSqlRequest,
@@ -746,3 +750,32 @@ def test_allowed_data_source_type(test_config):
746750
pass
747751
else:
748752
assert False, "ValueError was not raised for nonsense database type"
753+
754+
755+
def test_catalog_data_source_mssql(test_config):
756+
data_source = CatalogDataSourceMsSql(
757+
id="test",
758+
name="Test",
759+
db_specific_attributes=MsSqlAttributes(host="Host", db_name="DbName"),
760+
schema="Schema",
761+
credentials=BasicCredentials(
762+
username="demouser",
763+
password="demopass",
764+
),
765+
)
766+
assert data_source.url == "jdbc:sqlserver://Host:1433;databaseName=DbName"
767+
768+
769+
def test_catalog_data_source_databricks(test_config):
770+
data_source = CatalogDataSourceDatabricks(
771+
id="test",
772+
name="Test",
773+
db_specific_attributes=DatabricksAttributes(host="Host", http_path="xyz123abc"),
774+
schema="SCHEMA",
775+
parameters=[{"name": "catalog", "value": "super_catalog"}],
776+
credentials=BasicCredentials(
777+
username="demouser",
778+
password="demospass",
779+
),
780+
)
781+
assert data_source.url == "jdbc:databricks://Host:443/default;httpPath=xyz123abc"

0 commit comments

Comments
 (0)