bedgay opened a new issue, #23709:
URL: https://github.com/apache/doris/issues/23709

   ### Search before asking
   
   - [X] I had searched in the 
[issues](https://github.com/apache/doris/issues?q=is%3Aissue) and found no 
similar issues.
   
   
   ### Version
   
   Version : doris-2.0.0-rc04
   
   ### What's Wrong?
   
   **问题描述:**
   使用Doris samples/doris-demo/remote-udf-java-demo 
远程UDF做测试时候,发现入参如果是VARCHAR类型一直无法通过测试
     使用的数据结构为官方文档中 [快速开始] 中使用的  demo.example_tbl 
https://doris.apache.org/zh-CN/docs/1.2/get-starting/
   
   **问题在Q&A板块的连接**
   https://github.com/apache/doris/discussions/23707
   
   ### What You Expected?
   
   1、在远程UDF中 VARCHAR的使用方式是否正确
   2、如果VARCHAR的使用方式是正确的,
        远程UDF对 VARCHAR的支持 是否有bug,还是相关的配置不到位
   
   
   ### How to Reproduce?
   
    1、按照官方文档中 [快速开始] 中创建数据库和表,如下:
           `use demo;
   
   CREATE TABLE IF NOT EXISTS demo.example_tbl
   (
       `user_id` LARGEINT NOT NULL COMMENT "用户id",
       `date` DATE NOT NULL COMMENT "数据灌入日期时间",
       `city` VARCHAR(20) COMMENT "用户所在城市",
       `age` SMALLINT COMMENT "用户年龄",
       `sex` TINYINT COMMENT "用户性别",
       `last_visit_date` DATETIME REPLACE DEFAULT "1970-01-01 00:00:00" COMMENT 
"用户最后一次访问时间",
       `cost` BIGINT SUM DEFAULT "0" COMMENT "用户总消费",
       `max_dwell_time` INT MAX DEFAULT "0" COMMENT "用户最大停留时间",
       `min_dwell_time` INT MIN DEFAULT "99999" COMMENT "用户最小停留时间"
   )
   AGGREGATE KEY(`user_id`, `date`, `city`, `age`, `sex`)
   DISTRIBUTED BY HASH(`user_id`) BUCKETS 1
   PROPERTIES (
       "replication_allocation" = "tag.location.default: 1"
   );`
   
   2、IDEA中编写远程UDF函数RPC服务端
         拷贝官方案例做简单修改 samples/doris-demo/remote-udf-java-demo
         核心逻辑为,将VARCHAR的字段都拼接上 "_test"后返回, 核心代码如下:(没有截全)
         ` @Override
       public void fnCall(FunctionService.PFunctionCallRequest request,
                          StreamObserver<FunctionService.PFunctionCallResponse> 
responseObserver) {
           // symbol is functionName
           String functionName = request.getFunctionName();
           logger.info("udaf fnCall request=" + request);
           FunctionService.PFunctionCallResponse.Builder res = 
FunctionService.PFunctionCallResponse.newBuilder();
   
   
           //UDF方法调用
           FunctionService.PFunctionCallResponse resUDF;
           if ("add_int".equals(functionName)) {
   
               List<String> listString = IntStream.range(0, 
request.getArgs(0).getStringValueCount())
                       .mapToObj(i -> (request.getArgs(0).getStringValue(i) + 
"_test") + 1000).collect(Collectors.toList());
               
               resUDF = FunctionService.PFunctionCallResponse.newBuilder()
                       
.setStatus(Types.PStatus.newBuilder().setStatusCode(0).build())
                       .addResult(Types.PValues.newBuilder().setHasNull(false)
   
                               .addAllStringValue(listString)
                               
.setType(Types.PGenericType.newBuilder().setId(Types.PGenericType.TypeId.STRING).build())
   
                               .build()).build();
               
   //            resUDF = FunctionMethodService.add_int(request);
               logger.info("fnCall res=" + res);
               ok(responseObserver, resUDF);
               return;
   
           }`
          截图如下:
          
   
![image](https://github.com/apache/doris/assets/6390717/af7f4f52-1a9a-47ef-bfb0-3bd2164526ab)
         
       3、SQL控制台创建远程UDF函数
       `drop function rpc_add_int(VARCHAR(20));
   CREATE FUNCTION rpc_add_int(VARCHAR(20)) RETURNS VARCHAR(20) PROPERTIES (
     "SYMBOL"="add_int",
     "OBJECT_FILE"="192.168.3.149:9999",
     "TYPE"="RPC"
   );
   select rpc_add_int(city) from demo.example_tbl;`
   
    4、执行报错截图
   
![image](https://github.com/apache/doris/assets/6390717/55e98875-256e-4edb-b532-d5779f552b97)
   
   
   ### Anything Else?
   
   **四、尝试解决**
       1、先上解决结论:
       按照报错提示,顺藤摸瓜到了BE 和 brpc,奈何不是C++程序员,解决路子就此卡主了,暂时失焦没了方向
       
       2、按照执行报错关键字“call to rpc function”,找打了function_rpc.cpp这个类,找到了远程RPC 
的fn_call调用,且错误码来自于response
      路径:doris-master\be\src\vec\functions\function_rpc.cpp
      执行RPC代码:
   
![image](https://github.com/apache/doris/assets/6390717/6d8f98ef-904f-4828-8447-27ffd1f8c620)
     
      3、找到brpc项目,根据报错RPC response 返回的 status 搜索 
brpc项目,在brpc\docs\cn\error_code.md中找打了相关错误码说明:
        EREQUEST 
        1003 
         equest序列化错误,client端和server端都可能设置,
         形式广泛:"Missing required fields in request: …" "Fail to parse request 
message, …" "Bad request"
   
   
![image](https://github.com/apache/doris/assets/6390717/c33f3fe0-90a0-4f65-a9ce-3c791a038139)
   
   ### Are you willing to submit PR?
   
   - [ ] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [X] I agree to follow this project's [Code of 
Conduct](https://www.apache.org/foundation/policies/conduct)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to