Skip to content

Commit 688d116

Browse files
committed
do not fetch original DB primary key when creating training schema
1 parent 4669c0c commit 688d116

4 files changed

Lines changed: 7 additions & 10 deletions

File tree

mostlyai/sdk/_data/db/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,7 @@ class SqlAlchemyTable(DBTable, abc.ABC):
876876

877877
def __init__(self, *args, **kwargs):
878878
self.is_view = kwargs.get("is_view", False)
879+
self.lazy_fetch_primary_key = kwargs.get("lazy_fetch_primary_key", True)
879880
super().__init__(*args, **kwargs)
880881

881882
def __repr__(self):
@@ -1065,7 +1066,7 @@ def _lazy_fetch(self, item: str) -> None:
10651066
if item == "columns":
10661067
self.columns = [c.name for c in self._sa_table.columns]
10671068
elif item == "primary_key":
1068-
self.primary_key = self._get_primary_key()
1069+
self.primary_key = self._get_primary_key() if self.lazy_fetch_primary_key else None
10691070
elif item == "dtypes":
10701071
self.dtypes = self._get_dtypes()
10711072
else:

mostlyai/sdk/_data/file/utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ def _fetch_file_data_table(
8888
return data_table
8989

9090

91-
def make_data_table_from_container(container: DataContainer, is_output=False) -> DataTable:
91+
def make_data_table_from_container(
92+
container: DataContainer, is_output: bool = False, lazy_fetch_primary_key: bool = True
93+
) -> DataTable:
9294
if isinstance(container, SqlAlchemyContainer):
9395
# handle DB containers
9496
data_table_class = container.table_class()
@@ -100,4 +102,4 @@ def make_data_table_from_container(container: DataContainer, is_output=False) ->
100102
data_table_class = read_data_table_from_path(container, return_class=True)
101103
else:
102104
raise RuntimeError(f"Unknown container type: {type(container)}")
103-
return data_table_class(container=container, is_output=is_output)
105+
return data_table_class(container=container, is_output=is_output, lazy_fetch_primary_key=lazy_fetch_primary_key)

mostlyai/sdk/_data/pull.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ def pull(
6060
_LOG.info(f"tgt: {tgt}")
6161
_LOG.info(f"model_type: {model_type}")
6262
_LOG.info(f"max_sample_size: {max_sample_size}")
63-
_LOG.info(f"{schema.tables[tgt].primary_key = }")
6463

6564
# initialize progress counter
6665
tbl_count_rows = 0

mostlyai/sdk/_local/execution/step_pull_training_data.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import logging
1615
from collections.abc import Callable
1716
from pathlib import Path
1817

@@ -22,8 +21,6 @@
2221
from mostlyai.sdk._data.file.utils import make_data_table_from_container
2322
from mostlyai.sdk.domain import Connector, Generator, ModelType
2423

25-
_LOG = logging.getLogger(__name__)
26-
2724

2825
def execute_step_pull_training_data(
2926
*,
@@ -35,8 +32,6 @@ def execute_step_pull_training_data(
3532
update_progress: Callable,
3633
) -> tuple[list[str], int]:
3734
schema = _create_training_schema(generator=generator, connectors=connectors)
38-
_LOG.info(f"execute_step_pull_training_data: {generator = }")
39-
_LOG.info(f"execute_step_pull_training_data: {schema.tables[target_table_name].primary_key = }")
4035

4136
# fetch total rows
4237
tgt_table_total_rows = schema.tables[target_table_name].row_count
@@ -72,7 +67,7 @@ def _create_training_schema(generator: Generator, connectors: list[Connector]) -
7267
container = create_container_from_connector(connector)
7368
container.set_location(table.location)
7469
# create DataTable
75-
data_table = make_data_table_from_container(container)
70+
data_table = make_data_table_from_container(container, lazy_fetch_primary_key=False)
7671
data_table.name = table.name
7772
data_table.primary_key = table.primary_key
7873
if table.columns:

0 commit comments

Comments
 (0)