簡體   English   中英

KSQL:UDF 不接受參數 (STRING, STRING)

[英]KSQL: UDF does not accept parameters (STRING, STRING)

我在嘗試使用 UDF 設置 ETL 管道時遇到了 KSQL 問題。 在 ETL 過程的某個時刻,我需要從數據中的描述字段 (VARCHAR) 中分離出特定信息。 上下文的一個虛構示例:

description = "物種=dog.sex=male.color=blonde.age=10。" (真實數據格式相同)

我編寫了一個簡單的 UDF 來按需隔離任何信息。 它看起來像這樣:

package com.my.package;

/** IMPORTS **/
import io.confluent.ksql.function.udf.Udf;
import io.confluent.ksql.function.udf.UdfDescription;

/** ClASS DEFINITION **/
@UdfDescription(name = "extract_from_description",
                author = "Me",
                version = "0.0.1",
                description = "Given a description and a request for information, isolates and returns the requested information. Pass requested tag as 'tag='".) 
public class Extract_From_Description {

    @Udf(description = "Given a description and a request for information, isolates and returns the requested information. Pass requested tag as 'tag='.)
    public String extract_from_description(final String description, final String request) {
        return description.split(request)[1].split("\\.")[0];
    }
}

我可以很好地上傳和注冊該函數,它在我運行時被正確列出和描述:

ksql> list functions;
ksql> describe function EXTRACT_FROM_DESCRIPTION;

我調用這樣的函數來創建一個新的流:

CREATE STREAM result AS
    SELECT recordId,
           OtherVariables,
           EXTRACT_FROM_DESCRIPTION(description, 'species=') AS species
    FROM parent_stream
    EMIT CHANGES;

在那里我得到一個我無法理解的錯誤:

函數“extract_from_description”不接受參數(STRING、STRING)。 有效的替代方案是:

顯然,KSQL 無法正確解釋函數的輸入應該是什么(看起來它不需要輸入?),我不知道為什么。 我通讀了文檔,看看我是否以一種奇怪的方式定義了我的函數,但在示例和我的函數之間找不到任何差異。 我確實注意到應該有幾種方法來定義函數接受的輸入並嘗試了所有方法,但結果總是相同的。

我使用 Maven 為這個函數 (JDK1.8.0_201) 創建 jar 文件。 誰能幫我弄清楚發生了什么?

TL;DR:我的 KSQL UDF 不接受 (String, String) 類型的輸入,即使函數指定輸入應該是 (String, String) 類型

發現問題,在這里為可能遇到相同問題的任何人回答。 您需要使用@UdfParameter 指定參數,如下所示:

import io.confluent.ksql.function.udf.UdfParameter; // add this to the list of imports

// add @UdfParameter(name) to each input variable
public String extract_from_description(@UdfParameter(value = "description") final String description, @UdfParameter(value = "request") final String request){
           
  function body

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM