0
votes

My Requirement is query some snowflake tables from snowflake JAVA UDF. I can able to connect with plan java program using jdbc Snowflake connector , when its comes to snowflake JAVA UDF , am not sure how to read the table from UDF. SInce the UDF itselfs runs in snowflake environment not sure how the jdbc works.

or do we directly query the table.

Please suggest.

Thanks, Kumar

1
I don't understand "query snowflake from java udf". Why would you query data from a database through a UDF function on that database instead of just querying the data with a SELECT statement? - JNevill
Well my UDF needs some data from a table. based on that I need to build the UDF output. I used java UDF to read the a word document toc items , Based on the version the TOC item order are in another table. The first call to UDF get the input file name and the UDF will process the word documents. Here in the UDF I need to compare my TOC items table , where I need to query from UDF. - Kumaresan Natarajan

1 Answers

0
votes

Java UDFs must be self-contained, and cannot call out to external services; see the documentation for more details. You have a couple of options, however:

  • Write a query that reads from the table, and passes input rows to the UDF that performs whatever processing you need. The processing needs to be self-contained, although you can read files from stages if needed for initialization. You can use JDBC APIs inside the UDF if needed for your processing, but you won't be able to use them to talk to remote services (Snowflake or otherwise).
  • Use the Snowpark API, which enables you to write Scala code using the DataFrame API. Operations are transformed into queries, and Snowpark pushes down some computations as Java UDFs as well.
  • (Longer-term) Wait for the availability of Java stored procedures, which were announced at the Snowflake Summit as coming in the future and will provide the ability to use the JDBC API to execute queries against Snowflake.