def push_jar_to_snowflake(cur=None, deployment_id=None, path_to_jar=None):
"""description: method to push local jar file to snowflake instance
inputs:
cur : snowflake.connector
SnowflakeCursor
deployment_id : str
id of deployment to pull jar file
returns:
None : copies local jar file to snowflake and creates a function to return an object or table
"""
## Update this path to match the Scoring Code jar's location
put_jar_query = "PUT 'file://{0}' '@~/jars/' AUTO_COMPRESS=FALSE;".format(
os.path.join(path_to_jar, 'scoringcode_{0}.jar'.format(deployment_id))
)
cur.execute(put_jar_query)
# ---------------- #
# Create the UDF #
# ---------------- #
create_udf = '''
CREATE OR REPLACE FUNCTION datarobot_deployment_{0}(RowValue OBJECT)
RETURNS OBJECT
LANGUAGE JAVA
IMPORTS=('@~/jars/scoringcode_{0}.jar')
HANDLER='com.datarobot.prediction.simple.ClassificationPredictor.score';
'''.format(deployment_id)
print(create_udf)
cur.execute(create_udf)
see Automate downloading scoring jar file from a DR deployment? to download jar file.