This repository has been archived by the owner on Nov 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore(tableau): make site as an optional param * feat: change logic mapping external databases * chore(tableau): add debug info
- Loading branch information
Showing
19 changed files
with
341 additions
and
802 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,67 @@ | ||
from typing import Dict, List, Type | ||
from typing import Type | ||
from urllib.parse import urlparse | ||
|
||
from odd_collector_sdk.domain.adapter import AbstractAdapter | ||
from odd_models.models import DataEntity, DataEntityList | ||
from oddrn_generator import TableauGenerator | ||
from odd_collector_sdk.domain.adapter import BaseAdapter | ||
from odd_models.models import DataEntityList | ||
from oddrn_generator import Generator, TableauGenerator | ||
|
||
from odd_collector.adapters.tableau.domain.table import EmbeddedTable | ||
from odd_collector.domain.plugin import TableauPlugin | ||
|
||
from .client import TableauBaseClient, TableauClient | ||
from .domain.table import EmbeddedTable, Table | ||
from .client import TableauClient | ||
from .logger import logger | ||
from .mappers.sheets import map_sheet | ||
from .mappers.tables import map_table | ||
|
||
|
||
class Adapter(AbstractAdapter): | ||
class Adapter(BaseAdapter): | ||
config: TableauPlugin | ||
generator: TableauGenerator | ||
|
||
def __init__( | ||
self, config: TableauPlugin, client: Type[TableauBaseClient] = None | ||
self, config: TableauPlugin, client: Type[TableauClient] = TableauClient | ||
) -> None: | ||
client = client or TableauClient | ||
super().__init__(config) | ||
self.client = client(config) | ||
|
||
self.__oddrn_generator = TableauGenerator( | ||
host_settings=self.client.get_server_host(), sites=config.site | ||
) | ||
|
||
def get_data_source_oddrn(self) -> str: | ||
return self.__oddrn_generator.get_data_source_oddrn() | ||
def create_generator(self) -> Generator: | ||
site = self.config.site or "default" | ||
host = urlparse(self.config.server).netloc | ||
return TableauGenerator(host_settings=host, sites=site) | ||
|
||
def get_data_entity_list(self) -> DataEntityList: | ||
sheets = self._get_sheets() | ||
tables = self._get_tables() | ||
sheets = self.client.get_sheets() | ||
tables = self.client.get_tables() | ||
|
||
tables_data_entities_by_id: Dict[str, DataEntity] = { | ||
table_id: map_table(self.__oddrn_generator, table) | ||
for table_id, table in tables.items() | ||
embedded_tables: list[EmbeddedTable] = [ | ||
t for t in tables.values() if isinstance(t, EmbeddedTable) | ||
] | ||
|
||
tbl_entities = { | ||
table.id: map_table(self.generator, table) for table in embedded_tables | ||
} | ||
tables_data_entities = tables_data_entities_by_id.values() | ||
|
||
sheets_data_entities = [] | ||
for sheet in sheets: | ||
sheet_tables = [ | ||
tables_data_entities_by_id[table_id] for table_id in sheet.tables_id | ||
] | ||
data_entity = map_sheet(self.__oddrn_generator, sheet, sheet_tables) | ||
sheets_data_entities.append(data_entity) | ||
|
||
return DataEntityList( | ||
data_source_oddrn=self.get_data_source_oddrn(), | ||
items=[*tables_data_entities, *sheets_data_entities], | ||
) | ||
|
||
def _get_tables(self) -> Dict[str, Table]: | ||
tables: List[Table] = self.client.get_tables() | ||
tables_by_id: Dict[str, Table] = {table.id: table for table in tables} | ||
sheet_entity = map_sheet(self.generator, sheet) | ||
|
||
ids = tables_ids_to_load(tables) | ||
tables_columns = self.client.get_tables_columns(ids) | ||
for table_id in sheet.tables_id: | ||
table = tables.get(table_id) | ||
|
||
for table_id, columns in tables_columns.items(): | ||
tables_by_id[table_id].columns = columns | ||
if not table: | ||
logger.warning(f"Table {table_id} not found in tables, skipping it") | ||
continue | ||
|
||
return tables_by_id | ||
if table.is_embedded: | ||
oddrn = tbl_entities[table_id].oddrn | ||
else: | ||
oddrn = tables.get(table_id).get_oddrn() | ||
|
||
def _get_sheets(self): | ||
return self.client.get_sheets() | ||
sheet_entity.data_consumer.inputs.append(oddrn) | ||
|
||
sheets_data_entities.append(sheet_entity) | ||
|
||
def tables_ids_to_load(tables: List[Table]): | ||
return [table.id for table in tables if isinstance(table, EmbeddedTable)] | ||
return DataEntityList( | ||
data_source_oddrn=self.get_data_source_oddrn(), | ||
items=[*tbl_entities.values(), *sheets_data_entities], | ||
) |
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 |
---|---|---|
@@ -1,24 +1,21 @@ | ||
from dataclasses import dataclass | ||
from typing import Optional | ||
|
||
|
||
@dataclass | ||
class Column: | ||
def __init__( | ||
self, | ||
id: str, | ||
name: str, | ||
is_nullable: bool, | ||
remote_type: str = None, | ||
description: str = None, | ||
): | ||
self.id = id | ||
self.name = name | ||
self.remote_type = remote_type | ||
self.is_nullable = is_nullable | ||
self.description = description or None | ||
id: str | ||
name: str | ||
is_nullable: bool | ||
remote_type: Optional[str] = None | ||
description: Optional[str] = None | ||
|
||
@staticmethod | ||
def from_response(response): | ||
return Column( | ||
response.get("id"), | ||
response.get("name"), | ||
response.get("isNullable"), | ||
response.get("remoteType"), | ||
response.get("description"), | ||
@classmethod | ||
def from_dict(cls, **data) -> "Column": | ||
return cls( | ||
data["id"], | ||
data["name"], | ||
data["isNullable"], | ||
data.get("remoteType"), | ||
data.get("description"), | ||
) |
23 changes: 23 additions & 0 deletions
23
odd_collector/adapters/tableau/domain/connection_params.py
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,23 @@ | ||
from dataclasses import dataclass | ||
from typing import Optional | ||
|
||
|
||
@dataclass | ||
class ConnectionParams: | ||
id: str | ||
name: str | ||
connection_type: str | ||
host: str | ||
port: int | ||
service: Optional[str] | ||
|
||
@classmethod | ||
def from_dict(cls, **kwargs): | ||
return cls( | ||
id=kwargs["id"], | ||
name=kwargs["name"], | ||
connection_type=kwargs["connectionType"], | ||
host=kwargs["hostName"], | ||
port=kwargs["port"], | ||
service=kwargs["service"], | ||
) |
Oops, something went wrong.