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 lemon <z_...@foxmail.com> on 2020/09/29 09:50:17 UTC
回复: flink sql count问题
感谢各位的回答,各位的方法我都试了一下,但是都会在下游输出一条结果,一条不符合条件的语句count会在下游输出0
我理解是flink中的count对于每一条数据都会输出一条结果,所以只能把if中的判断条件再放到最后的where中进行过滤
类似于 select count(if(name like '南京%',1 , null)) where name like '南京%' or name like '杭州%' group by ** 这样
------------------ 原始邮件 ------------------
发件人: "user-zh" <vincent2015qdlg@outlook.com>;
发送时间: 2020年9月29日(星期二) 下午5:32
收件人: "user-zh"<user-zh@flink.apache.org>;
主题: Re: flink sql count问题
Hi lemon,
内部判断if函数可以替换为case when
Best,
Robin
lemon wrote
> 请教各位:
> 我有一个sql任务需要进行count,在count中有一个表达式,只想count符合条件的记录,
> 之前在hive中是这么写的:count(if(name like '南京%',1 , null)),但是flink
> sql中count不能为null,有什么别的方法能实现该功能吗?
> 使用的是flink1.10.1 blink
> &nbsp;
--
Sent from: http://apache-flink.147419.n8.nabble.com/
Re: 回复: flink sql count问题
Posted by Robin Zhang <vi...@outlook.com>.
Hi lemon,
不是很理解你的疑问是什么,flink是事件驱动的,所以,来一条数据,就会被处理,走你的逻辑,就会产生一个结果,如果是第一次出现的key,只有一条数据,如果是状态中已经存在的key,会在控制台输出两条数据,一条true的是最终sink的结果。所以,每次输出一条结果有什么问题吗?
Best,
Robin
----------------------------------------------------------------------------------------------------------------
lemon wrote
> 感谢各位的回答,各位的方法我都试了一下,但是都会在下游输出一条结果,一条不符合条件的语句count会在下游输出0
> 我理解是flink中的count对于每一条数据都会输出一条结果,所以只能把if中的判断条件再放到最后的where中进行过滤
> 类似于 select count(if(name like '南京%',1 , null)) where name
> like '南京%' or name like '杭州%' group by ** 这样
>
>
> ------------------ 原始邮件 ------------------
> 发件人:
> "user-zh"
> <
> vincent2015qdlg@
> >;
> 发送时间: 2020年9月29日(星期二) 下午5:32
> 收件人: "user-zh"<
> user-zh@.apache
> >;
>
> 主题: Re: flink sql count问题
>
>
>
> Hi lemon,
> 内部判断if函数可以替换为case when
>
> Best,
> Robin
>
>
> lemon wrote
> > 请教各位:
> > 我有一个sql任务需要进行count,在count中有一个表达式,只想count符合条件的记录,
> > 之前在hive中是这么写的:count(if(name like '南京%',1 , null)),但是flink
> > sql中count不能为null,有什么别的方法能实现该功能吗?
> > 使用的是flink1.10.1 blink
> > &nbsp;
>
>
>
>
>
> --
> Sent from: http://apache-flink.147419.n8.nabble.com/
--
Sent from: http://apache-flink.147419.n8.nabble.com/