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&nbsp;count(if(name like '南京%',1 , null)) where name like&nbsp;'南京%'&nbsp; or name like&nbsp;'杭州%'&nbsp; group by ** 这样


------------------&nbsp;原始邮件&nbsp;------------------
发件人:                                                                                                                        "user-zh"                                                                                    <vincent2015qdlg@outlook.com&gt;;
发送时间:&nbsp;2020年9月29日(星期二) 下午5:32
收件人:&nbsp;"user-zh"<user-zh@flink.apache.org&gt;;

主题:&nbsp;Re: flink sql count问题



Hi lemon,
&nbsp;&nbsp;&nbsp; 内部判断if函数可以替换为case when

Best,
Robin


lemon wrote
&gt; 请教各位:
&gt; 我有一个sql任务需要进行count,在count中有一个表达式,只想count符合条件的记录,
&gt; 之前在hive中是这么写的:count(if(name like '南京%',1 , null)),但是flink
&gt; sql中count不能为null,有什么别的方法能实现该功能吗?
&gt; 使用的是flink1.10.1 blink
&gt; &amp;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&nbsp;count(if(name like '南京%',1 , null)) where name
> like&nbsp;'南京%'&nbsp; or name like&nbsp;'杭州%'&nbsp; group by ** 这样
> 
> 
> ------------------&nbsp;原始邮件&nbsp;------------------
> 发件人:                                                                                                                       
> "user-zh"                                                                                   
> <

> vincent2015qdlg@

> &gt;;
> 发送时间:&nbsp;2020年9月29日(星期二) 下午5:32
> 收件人:&nbsp;"user-zh"<

> user-zh@.apache

> &gt;;
> 
> 主题:&nbsp;Re: flink sql count问题
> 
> 
> 
> Hi lemon,
> &nbsp;&nbsp;&nbsp; 内部判断if函数可以替换为case when
> 
> Best,
> Robin
> 
> 
> lemon wrote
> &gt; 请教各位:
> &gt; 我有一个sql任务需要进行count,在count中有一个表达式,只想count符合条件的记录,
> &gt; 之前在hive中是这么写的:count(if(name like '南京%',1 , null)),但是flink
> &gt; sql中count不能为null,有什么别的方法能实现该功能吗?
> &gt; 使用的是flink1.10.1 blink
> &gt; &amp;nbsp;
> 
> 
> 
> 
> 
> --
> Sent from: http://apache-flink.147419.n8.nabble.com/





--
Sent from: http://apache-flink.147419.n8.nabble.com/