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

Viewed 203

I've created a custom udf that is registered but when I try to run select do_protect('abc@test.com','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);
}

1 Answers

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

Related