Skip to content

Commit

Permalink
Removed the pandas library as a requirement (#232)
Browse files Browse the repository at this point in the history
* Removed the pandas library as a requirement, since its usage was minimal.

* resolving merge conflicts

* Fixed indents from merge conflict.

---------

Co-authored-by: Tiji Mathew <tiji.mathew@snowflake.com>
  • Loading branch information
rosspb3 and sfc-gh-tmathew authored Apr 2, 2024
1 parent 8a8ed31 commit d5c3aea
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 28 deletions.
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Jinja2~=3.0
pandas~=1.3
PyYAML~=6.0
snowflake-connector-python>=2.8,<4.0
48 changes: 22 additions & 26 deletions schemachange/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import serialization
from jinja2.loaders import BaseLoader
from pandas import DataFrame

# region Global Variables
# metadata
Expand Down Expand Up @@ -357,13 +356,15 @@ def set_connection_args(self):

if self.verbose:
print(_log_auth_type % "Oauth Access Token")

self.conArgs["token"] = oauth_token
self.conArgs["authenticator"] = "oauth"
# External Browswer based SSO
elif snowflake_authenticator.lower() == "externalbrowser":
self.conArgs["authenticator"] = "externalbrowser"
if self.verbose:
print(_log_auth_type % "External Browser")

# IDP based Authentication, limited to Okta
elif snowflake_authenticator.lower()[:8] == "https://":

Expand All @@ -373,6 +374,7 @@ def set_connection_args(self):

self.conArgs["password"] = snowflake_password
self.conArgs["authenticator"] = snowflake_authenticator.lower()

elif snowflake_authenticator.lower() == "snowflake":
self.conArgs["authenticator"] = default_authenticator
# if authenticator is not a supported method or the authenticator variable is defined but not specified
Expand Down Expand Up @@ -471,21 +473,21 @@ def create_change_history_table_if_missing(self, change_history_table):
query = self._q_ch_ddl_table.format(**change_history_table)
self.execute_snowflake_query(query)

def fetch_r_scripts_checksum(self, change_history_table):
def fetch_r_scripts_checksum(self, change_history_table) -> Dict[str, str]:
"""
Fetches the checksum of the last executed R script from the change history table.
return: a dictionary with the script name as key and the last successfully installed script checksum as value
"""
# Note: Query only fetches last successfully installed checksum for R scripts
query = self._q_ch_r_checksum.format(**change_history_table)
results = self.execute_snowflake_query(query)

# Collect all the results into a dict
d_script_checksum = DataFrame(columns=["script_name", "checksum"])
script_names = []
checksums = []
d_script_checksum = {}
for cursor in results:
for row in cursor:
script_names.append(row[0])
checksums.append(row[1])
d_script_checksum[row[0]] = row[1]

d_script_checksum["script_name"] = script_names
d_script_checksum["checksum"] = checksums
return d_script_checksum

def fetch_change_history(self, change_history_table):
Expand Down Expand Up @@ -675,24 +677,18 @@ def deploy_command(config):
# Compute the checksum for the script
checksum_current = hashlib.sha224(content.encode("utf-8")).hexdigest()

# check if R file was already executed
if (r_scripts_checksum is not None) and script_name in list(
r_scripts_checksum["script_name"]
):
checksum_last = list(
r_scripts_checksum.loc[
r_scripts_checksum["script_name"] == script_name, "checksum"
]
)[0]
else:
checksum_last = ""
# check if R file was already executed
if r_scripts_checksum and (script_name in r_scripts_checksum):
checksum_last = r_scripts_checksum[script_name]
else:
checksum_last = ""

# check if there is a change of the checksum in the script
if checksum_current == checksum_last:
if config["verbose"]:
print(_log_skip_r.format(**script))
scripts_skipped += 1
continue
# check if there is a change of the checksum in the script
if checksum_current == checksum_last:
if config["verbose"]:
print(_log_skip_r.format(**script))
scripts_skipped += 1
continue

print(_log_apply.format(**script))
if not config["dry_run"]:
Expand Down
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ classifiers =
packages = schemachange
install_requires =
jinja2~=3.0
pandas~=1.3
pyyaml~=6.0
snowflake-connector-python>=2.8,<4.0
python_requires = >=3.8
Expand Down

0 comments on commit d5c3aea

Please sign in to comment.