Skip to content

Commit 8cb9f48

Browse files
committed
fix to get mappers
1 parent d74fcad commit 8cb9f48

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

phenex/mappers.py

+12-19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import copy
2-
from typing import Optional, Dict
3-
from dataclasses import dataclass, asdict
1+
from typing import Dict
42
from ibis.expr.types.relations import Table
53

64
from phenex.tables import *
@@ -11,11 +9,13 @@ class DomainsDictionary:
119
A DomainsDictionary is used to map an entire database from an arbitrary schema to a PhenEx internal representation.
1210
1311
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.
1513
1614
Methods:
1715
get_mapped_tables(con, database=None) -> Dict[str, Table]:
1816
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.
1919
"""
2020

2121
def __init__(self, domains_dict):
@@ -37,19 +37,15 @@ def set_mapped_tables(self, con, overwrite=False) -> Dict[str, Table]:
3737
existing_tables = con.dest_connection.list_tables(database=con.SNOWFLAKE_DEST_DATABASE)
3838
for domain, mapper in self.domains_dict.items():
3939
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)
4441
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,
4945
overwrite=overwrite
50-
)
46+
)
5147

52-
def get_mapped_tables(self, con) -> Dict[str, Table]:
48+
def get_mapped_tables(self, con) -> Dict[str, PhenexTable]:
5349
"""
5450
Get all tables mapped to PhenEx representation using the given connection.
5551
@@ -60,15 +56,12 @@ def get_mapped_tables(self, con) -> Dict[str, Table]:
6056
database (Optional[str]): The name of the database. Defaults to the current database of the connection.
6157
6258
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.
6460
"""
6561
# self.set_mapped_tables(con)
6662
mapped_tables = {}
6763
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))
7265
return mapped_tables
7366

7467

0 commit comments

Comments
 (0)