I have a pipeline wherein i need to call Snowflake stored procedure in AWS Glue job using Python shell.
Can anyone please suggest the appropriate code for the same.
Thanks
I have a pipeline wherein i need to call Snowflake stored procedure in AWS Glue job using Python shell.
Can anyone please suggest the appropriate code for the same.
Thanks
For DDL/DML statement executions, the Snowflake Spark Connector offers a utility function: net.snowflake.spark.snowflake.Utils.runQuery(…)
Since its a Java class not offered directly within the Python libraries, you'll need to call it through the Py4J interface within Spark driver's runtime:
# A direct call:
sc._gateway.jvm.net.snowflake.spark.snowflake.Utils.runQuery(sfOptions, "CALL SF_TEST_DB.STRUCTURED.TEST()")
# Alternatively, using an import style:
from py4j.java_gateway import java_import
java_import(sc._gateway.jvm, "net.snowflake.spark.snowflake.Utils")
Utils = sc._gateway.jvm.Utils
Utils.runQuery(sfOptions, "CALL SF_TEST_DB.STRUCTURED.TEST()")
There is a caveat though. Quoting from the documentation:
The
runQuerymethod returns onlyTRUEorFALSE. It is intended for statements that do not return a result set, for example DDL statements likeCREATE TABLEand DML statements likeINSERT,UPDATE, andDELETE. It is not useful for statements that return a result set, such asSELECTorSHOW.
Was able to connect to snowflake using python connector in AWS glue. Please refer to the link below to build external python library package for snowflake connector to be used in AWS glue https://github.com/snowflakedb/snowflake-connector-python/blob/HEAD/test/README.rst
Thanks