You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-zh@flink.apache.org by 了不起的盖茨比 <57...@qq.com> on 2020/05/20 08:25:00 UTC
flink1.10.x 解析 arrar 问题
1.blink_planner 定义ddl解析array字段时候,假如select 那个字段可以解析出。
2.blink_planner 当我去定义自己函数时候,数组有长度但是没有元素,flink直接跳过解析
3.如果使用flink-planner那么是正确的
CREATE TABLE sourceTable (
event_time_line array<ROW (
`rule_name` VARCHAR,
`count` VARCHAR
)>
) WITH (
'connector.type' = 'kafka',
'connector.version' = 'universal',
'connector.startup-mode' = 'earliest-offset',
'connector.topic' = 'topic_test_1',
'connector.properties.zookeeper.connect' = 'localhost:2181',
'connector.properties.bootstrap.servers' = 'localhost:9092',
'update-mode' = 'append',
'format.type' = 'json',
'format.derive-schema' = 'true'
);
--可以查出数据
select event_time_line from sourceTable ;
--当我定义自己函数时候,参数value没有传过去,但是数组的size长度过去了
select type_change(event_time_line) from sourceTable ;
public class TypeChange extends ScalarFunction {
/**
* 为null,但是数组有长度,数组里面的字段没有被识别出来,换了默认的planner,可以正常得到值
* @param rows
* @return
*/
public String eval(Row [] rows){
return JSONObject.toJSONString(rows);
}
}
Re: flink1.10.x 解析 arrar 问题
Posted by Benchao Li <li...@gmail.com>.
你可以让你的UDF指定一下输入参数的类型,不指定类型的话,可能会推导出错误的类型,导致拿不到真正的数据
了不起的盖茨比 <57...@qq.com> 于2020年5月20日周三 下午4:25写道:
> 1.blink_planner 定义ddl解析array字段时候,假如select 那个字段可以解析出。
> 2.blink_planner 当我去定义自己函数时候,数组有长度但是没有元素,flink直接跳过解析
>
>
> 3.如果使用flink-planner那么是正确的
>
>
>
> CREATE TABLE sourceTable (
>
> event_time_line array<ROW (
>
> `rule_name` VARCHAR,
>
> `count` VARCHAR
>
> )>
>
> ) WITH (
>
> 'connector.type' = 'kafka',
>
> 'connector.version' = 'universal',
>
> 'connector.startup-mode' = 'earliest-offset',
>
> 'connector.topic' = 'topic_test_1',
>
> 'connector.properties.zookeeper.connect' = 'localhost:2181',
>
> 'connector.properties.bootstrap.servers' = 'localhost:9092',
>
> 'update-mode' = 'append',
>
> 'format.type' = 'json',
>
> 'format.derive-schema' = 'true'
>
> );
>
> --可以查出数据
>
> select event_time_line from sourceTable ;
>
> --当我定义自己函数时候,参数value没有传过去,但是数组的size长度过去了
>
> select type_change(event_time_line) from sourceTable ;
>
>
>
> public class TypeChange extends ScalarFunction {
>
> /**
>
> *
> 为null,但是数组有长度,数组里面的字段没有被识别出来,换了默认的planner,可以正常得到值
>
> * @param rows
>
> * @return
>
> */
>
> public String eval(Row [] rows){
>
> return
> JSONObject.toJSONString(rows);
>
> }
>
>
>
> }
--
Benchao Li
School of Electronics Engineering and Computer Science, Peking University
Tel:+86-15650713730
Email: libenchao@gmail.com; libenchao@pku.edu.cn