Skip to content

Commit

Permalink
Add database name and schema to cloud scanStart command (sodadata#584)
Browse files Browse the repository at this point in the history
  • Loading branch information
vijaykiran authored Dec 2, 2021
1 parent 576c3ac commit 5237e47
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 2 deletions.
10 changes: 10 additions & 0 deletions core/sodasql/scan/dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ def default_connection_properties(self, params: dict):
# to be overridden by subclass
pass

def get_warehouse_name_and_schema(self) -> dict:
"""
This is a workaround to send the identifiers to soda cloud for integration with external
systems (e.g. metaphor), this will change in the future. The implementation should return a dict with
two keys 'database_name' and 'database_schema'
:return: dict
"""
pass

def safe_connection_data(self):
"""Return non-critically sensitive connection details.
Expand Down
5 changes: 4 additions & 1 deletion core/sodasql/soda_server_client/soda_server_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,13 @@ def scan_start(self, warehouse, scan_yml: ScanYml, scan_time,
}
soda_column_cfgs[column_name] = soda_column_cfg

database_and_schema = warehouse.dialect.get_warehouse_name_and_schema()
return self.execute_command({
'type': 'sodaSqlScanStart',
'warehouseName': warehouse.name,
'warehouseType': warehouse.dialect.type,
'warehouseDatabaseName': database_and_schema.get('database_name'),
'warehouseDatabaseSchema': database_and_schema.get('database_schema'),
'tableName': scan_yml.table_name,
'scanTime': scan_time,
'columns': soda_column_cfgs,
Expand Down Expand Up @@ -172,7 +175,7 @@ def scan_monitor_measurements(self, scan_reference: dict, monitor_measurement_js
'monitorMeasurement': monitor_measurement_json
})

def historic_metrics(self, warehouse, table_name, metrics):
def historic_metrics(self, warehouse, table_name, metrics):
return self.execute_query({
'type': 'sodaSqlHistoricMeasurements',
'warehouseName': warehouse.name,
Expand Down
6 changes: 6 additions & 0 deletions packages/athena/sodasql/dialects/athena_dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ def default_connection_properties(self, params: dict):
'catalog': 'AwsDataCatalog'
}

def get_warehouse_name_and_schema(self) -> dict:
return {
'database_name': self.database,
'database_schema': self.catalog
}

def safe_connection_data(self):
return [
self.type,
Expand Down
6 changes: 6 additions & 0 deletions packages/bigquery/sodasql/dialects/bigquery_dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ def default_connection_properties(self, params: dict):
'dataset': params.get('database', 'Eg your_bigquery_dataset')
}

def get_warehouse_name_and_schema(self) -> dict:
return {
'database_name': self.account_info_dict['project_id'],
'database_schema': self.dataset_name
}

def safe_connection_data(self):
return [
self.account_info_dict['project_id']
Expand Down
7 changes: 7 additions & 0 deletions packages/hive/sodasql/dialects/hive_dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ def default_connection_properties(self, params: dict):
'database': params.get('database', 'your_database')
}

def get_warehouse_name_and_schema(self) -> dict:
# In Hive database and schema are interchangeable
return {
'database_name': self.database,
'database_schema': self.database
}

def safe_connection_data(self):
return [
self.type,
Expand Down
7 changes: 7 additions & 0 deletions packages/mysql/sodasql/dialects/mysql_dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ def default_connection_properties(self, params: dict):
'database': params.get('database', 'your_database')
}

def get_warehouse_name_and_schema(self) -> dict:
# In MySQL schema is synonymous with database
return {
'database_name': self.database,
'database_schema': self.database
}

def safe_connection_data(self):
return [
self.type,
Expand Down
6 changes: 6 additions & 0 deletions packages/postgresql/sodasql/dialects/postgres_dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ def default_connection_properties(self, params: dict):
'schema': 'public'
}

def get_warehouse_name_and_schema(self) -> dict:
return {
'database_name': self.database,
'database_schema': self.schema
}

def safe_connection_data(self):
return [
self.type,
Expand Down
6 changes: 6 additions & 0 deletions packages/snowflake/sodasql/dialects/snowflake_dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ def default_connection_properties(self, params: dict):
'schema': 'PUBLIC'
}

def get_warehouse_name_and_schema(self) -> dict:
return {
'database_name': self.database,
'database_schema': self.schema
}

def safe_connection_data(self):
return [
self.type,
Expand Down
6 changes: 6 additions & 0 deletions packages/spark/sodasql/dialects/spark_dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ def default_connection_properties(self, params: dict):
'database': params.get('database', 'your_database')
}

def get_warehouse_name_and_schema(self) -> dict:
return {
'database_name': self.database,
'database_schema': self.database
}

def safe_connection_data(self):
return [
self.type,
Expand Down
6 changes: 6 additions & 0 deletions packages/sqlserver/sodasql/dialects/sqlserver_dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ def default_connection_properties(self, params: dict):
'schema': 'public'
}

def get_warehouse_name_and_schema(self) -> dict:
return {
'database_name': self.database,
'database_schema': self.schema
}

def safe_connection_data(self):
return [
self.type,
Expand Down
2 changes: 1 addition & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ python_files = *_suite.py test_*.py
python_classes = Suite Test
log_level = DEBUG
addopts = -v
norecursedirs = examples/*
norecursedirs = examples/* build/*

0 comments on commit 5237e47

Please sign in to comment.