【问题标题】:Presto or Trino Custom UDF getting "do not match expected java types error"Presto 或 Trino 自定义 UDF 得到“不匹配预期的 Java 类型错误”
【发布时间】:2022-01-09 19:25:08
【问题描述】:

我创建了一个已注册的自定义 udf,但是当我尝试运行 select do_protect('abc@test.com','Test_EMAIL'); 时出现以下错误:

io.trino.spi.TrinoException:do_protect 的确切实现与预期的 java 类型不匹配

这是我的 Trino udf。我想传递两个字符串(VARCHAR)参数。

@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);
}

【问题讨论】:

    标签: java presto trino presto-jdbc


    【解决方案1】:

    我认为错误在于VARCHARSlice 的映射。相反,我认为它应该映射到string,如下所示:

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

    我在 Stack Overflow 上发现了一个类似的问题:

    Presto Custom UDF

    这让我看到了一篇文章,其中显示了 VARCHAR 的映射是 String

    “CHAR、VARCHAR 和 LONGVARCHAR 可以映射到 String 或 char[],但 String 更适合正常使用。”

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-02
      • 2017-08-28
      • 1970-01-01
      • 2020-05-27
      • 1970-01-01
      • 1970-01-01
      • 2013-10-31
      • 2016-09-18
      相关资源
      最近更新 更多