Reading a file inside teradata judf

Database
Teradata Employee

Reading a file inside teradata judf

 

Is it possible to read a file inside JUDF?  The file is embedded inside the jar and read as a stream using the below code.

 

 

InputStream in  = this.getClass().getClassLoader().getResourceAsStream("<FILE_LOC>");

 The code works fine when executed outside but the input stream object "inis coming as null in UDF.

 

 

5 REPLIES
Teradata Employee

Re: Reading a file inside teradata judf

This might work: this.getClassLoader().getResourceAsStream("<FILE_LOC>").

Teradata Employee

Re: Reading a file inside teradata judf

I was not able to execute the line of code which you shared because of missing ClassLoader function in "this" object. Tried all the suggestions that from the link but facing the same. 

Tags (1)
Teradata Employee

Re: Reading a file inside teradata judf

If no one else replies soon, I'd recommend opening an incident with Teradata - that should result in a definite answer from an expert.

Teradata Employee

Re: Reading a file inside teradata judf

From the "be careful what you ask for" department...

 

If there are 100 AMPs on your system and 1M rows in the table on which you run the select that invokes the JUDF, the result will be 1M file opens, 100 concurrently. A UDF is invoked for each row of the query set and is invoked independently on each AMP.

 

For that reason, UDFs don't generally do external operations.

Teradata Employee

Re: Reading a file inside teradata judf

The UDF I was building was for encrypying and decrypting the data. For that purpose was planning to keep the key inside a jks file.

Thanks for the details everyone, will try a different approach.