Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Presto or Trino Custom UDF getting "do not match expected java types error"

I've created a custom udf that is registered but when I try to run select do_protect('[email protected]','Test_EMAIL'); I am getting following error:

io.trino.spi.TrinoException: Exact implementation of do_protect do not match expected java types

Here is my Trino udf. I want to pass two string (VARCHAR) parameters.

@ScalarFunction("do_protect")
@Description("Return encrypted string")
@SqlType(StandardTypes.VARCHAR)
public String protectUDF(@SqlType(StandardTypes.VARCHAR) Slice slice1, @SqlType(StandardTypes.VARCHAR) Slice slice2) throws PrivaceraException {
        logger.info("protectUDF get called...");

        String valueForEncrypt = slice1.toString();
        logger.info("AS :: valueForEncrypt :: "+valueForEncrypt);
        String schemeForEncrypt = slice2.toString();
        logger.info("AS :: schemeForEncrypt :: "+schemeForEncrypt);
}

like image 317
Anand Suryavanshi Avatar asked Sep 21 '25 00:09

Anand Suryavanshi


2 Answers

The answer above is incorrect. The mapping for VARCHAR is Slice. The issue you have is that you used String as the return value type. You should change that to Slice.

like image 170
Greg Fee Avatar answered Sep 22 '25 13:09

Greg Fee


I think the error is in the mapping of VARCHAR to Slice. Instead, I believe it should map to a string, as such:

protectUDF(@SqlType(StandardTypes.VARCHAR) string slice1, @SqlType(StandardTypes.VARCHAR) string slice2)

I found a similar issue on Stack Overflow:

Presto Custom UDF

Which led me to an article that shows the mapping for VARCHAR is String

"CHAR, VARCHAR, and LONGVARCHAR could have been mapped to either String or char[], but String is more appropriate for normal use."

https://www.cis.upenn.edu/~bcpierce/courses/629/jdkdocs/guide/jdbc/getstart/mapping.doc.html

like image 30
MonteCarloSims Avatar answered Sep 22 '25 12:09

MonteCarloSims