Skip to content

Commit

Permalink
perf(datasets): don't connect in __init__ method
Browse files Browse the repository at this point in the history
Signed-off-by: Deepyaman Datta <[email protected]>
  • Loading branch information
deepyaman committed Oct 13, 2023
1 parent 2be42aa commit 54f12b3
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions kedro-datasets/kedro_datasets/snowflake/snowpark_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 54f12b3

Please sign in to comment.