From 54f12b3f0abbe6e65a9cd12fd635723ab2959b3b Mon Sep 17 00:00:00 2001 From: Deepyaman Datta Date: Fri, 13 Oct 2023 06:10:37 +0530 Subject: [PATCH] perf(datasets): don't connect in `__init__` method Signed-off-by: Deepyaman Datta --- .../kedro_datasets/snowflake/snowpark_dataset.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/kedro-datasets/kedro_datasets/snowflake/snowpark_dataset.py b/kedro-datasets/kedro_datasets/snowflake/snowpark_dataset.py index 6fbfa60a0..df2eab564 100644 --- a/kedro-datasets/kedro_datasets/snowflake/snowpark_dataset.py +++ b/kedro-datasets/kedro_datasets/snowflake/snowpark_dataset.py @@ -172,7 +172,6 @@ def __init__( # noqa: PLR0913 {"database": self._database, "schema": self._schema} ) self._connection_parameters = connection_parameters - self._session = self._get_session(self._connection_parameters) self.metadata = metadata @@ -207,10 +206,14 @@ def _get_session(connection_parameters) -> sp.Session: logger.debug("Trying to reuse active snowpark session...") session = sp.context.get_active_session() except sp.exceptions.SnowparkSessionException: - logger.debug("No active snowpark session found. Creating") + logger.debug("No active snowpark session found. Creating...") session = sp.Session.builder.configs(connection_parameters).create() return session + @property + def _session(self) -> sp.Session: + return self._get_session(self._connection_parameters) + def _load(self) -> sp.DataFrame: table_name = [ self._database,