1
- import copy
2
- from typing import Optional , Dict
3
- from dataclasses import dataclass , asdict
1
+ from typing import Dict
4
2
from ibis .expr .types .relations import Table
5
3
6
4
from phenex .tables import *
@@ -11,11 +9,13 @@ class DomainsDictionary:
11
9
A DomainsDictionary is used to map an entire database from an arbitrary schema to a PhenEx internal representation.
12
10
13
11
Attributes:
14
- domains_dict (Dict[str, ]): A dictionary where keys are domain names and values are instances .
12
+ domains_dict (Dict[str, class ]): A dictionary where keys are domain names and values are uninstantiated PhenexTable class objects .
15
13
16
14
Methods:
17
15
get_mapped_tables(con, database=None) -> Dict[str, Table]:
18
16
Get all tables mapped to PhenEx representation using the given connection.
17
+ set_mapped_tables(con, con, overwrite=False) -> None:
18
+ Create a view for all mapped tables in the destination database.
19
19
"""
20
20
21
21
def __init__ (self , domains_dict ):
@@ -37,19 +37,15 @@ def set_mapped_tables(self, con, overwrite=False) -> Dict[str, Table]:
37
37
existing_tables = con .dest_connection .list_tables (database = con .SNOWFLAKE_DEST_DATABASE )
38
38
for domain , mapper in self .domains_dict .items ():
39
39
if domain not in existing_tables or overwrite :
40
- t = con .source_connection .table (
41
- mapper .NAME_TABLE ,
42
- database = con .SNOWFLAKE_SOURCE_DATABASE
43
- )
40
+ t = con .get_source_table (mapper .NAME_TABLE )
44
41
mapped_table = mapper (t ).table
45
- con .dest_connection .create_view (
46
- name = mapper .NAME_TABLE ,
47
- database = con .SNOWFLAKE_DEST_DATABASE ,
48
- obj = mapped_table ,
42
+ con .create_view (
43
+ mapped_table ,
44
+ name_table = mapper .NAME_TABLE ,
49
45
overwrite = overwrite
50
- )
46
+ )
51
47
52
- def get_mapped_tables (self , con ) -> Dict [str , Table ]:
48
+ def get_mapped_tables (self , con ) -> Dict [str , PhenexTable ]:
53
49
"""
54
50
Get all tables mapped to PhenEx representation using the given connection.
55
51
@@ -60,15 +56,12 @@ def get_mapped_tables(self, con) -> Dict[str, Table]:
60
56
database (Optional[str]): The name of the database. Defaults to the current database of the connection.
61
57
62
58
Returns:
63
- Dict[str, Table ]: A dictionary where keys are domain names and values are mapped tables.
59
+ Dict[str, PhenexTable ]: A dictionary where keys are domain names and values are mapped tables.
64
60
"""
65
61
# self.set_mapped_tables(con)
66
62
mapped_tables = {}
67
63
for domain , mapper in self .domains_dict .items ():
68
- mapped_tables [domain ] = mapper (con .dest_connection .table (
69
- mapper .NAME_TABLE ,
70
- database = con .SNOWFLAKE_DEST_DATABASE
71
- ))
64
+ mapped_tables [domain ] = mapper (con .get_source_table (mapper .NAME_TABLE ))
72
65
return mapped_tables
73
66
74
67
0 commit comments