[
https://issues.apache.org/jira/browse/FLINK-30687?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17677122#comment-17677122
]
tanjialiang edited comment on FLINK-30687 at 1/16/23 2:58 AM:
--------------------------------------------------------------
I try to found out how to fix this, i found in
org.apache.flink.table.planner.codegen.agg.AggsHandlerCodeGenerator#createFilterExpression
the filterArg must be >0, but ‘SELECT COUNT( * ) FILTER (WHERE cluster_id = 1)
FROM ${table}’ 's filterArg is 0. I fixed the condition in 'filterArg >= 0',
and it work.
!image-2023-01-16-10-54-04-673.png!
So i want to ask why we can not filterArg=0? Did it some scenes we can not use?
Because 'inputFieldTypes' is a 'scala.collection.Seq' which index is start from
0.
was (Author: JIRAUSER279823):
I try to found out how to fix this, i found in
org.apache.flink.table.planner.codegen.agg.AggsHandlerCodeGenerator#createFilterExpression
the filterArg must be >0, but ‘SELECT COUNT(*) FILTER (WHERE cluster_id = 1)
FROM ${table}’ 's filterArg is 0. I fixed the condition in 'filterArg >= 0',
and it work.
!image-2023-01-16-10-54-04-673.png!
So i want to ask why we can not filterArg=0? Did it some scenes we can not use?
Because 'inputFieldTypes' is a 'scala.collection.Seq' which index is start from
0.
> FILTER not effect in count(*)
> -----------------------------
>
> Key: FLINK-30687
> URL: https://issues.apache.org/jira/browse/FLINK-30687
> Project: Flink
> Issue Type: Bug
> Components: Table SQL / Planner
> Affects Versions: 1.16.0
> Reporter: tanjialiang
> Priority: Major
> Attachments: image-2023-01-16-10-54-04-673.png
>
>
> When i try to using Flink SQL like this, i found 'FILTER(WHERE class_id = 1)'
> is not effect.
> {code:java}
> CREATE TABLE student
> (
> id INT NOT NULL,
> name STRING,
> class_id INT NOT NULL
> )
> WITH (
> 'connector' = 'jdbc',
> 'url' = 'jdbc:mysql://localhost:3306/test',
> 'table-name' = 'student',
> 'username' = 'root',
> 'password' = '12345678'
> );
> SELECT COUNT(*) FILTER (WHERE class_id = 1) FROM student;
> or
> SELECT COUNT(1) FILTER (WHERE class_id = 1) FROM student;{code}
>
> But when i tried Flink SQL like this, it worked.
> {code:java}
> SELECT COUNT(*) FROM student WHERE class_id = 1;
> or
> SELECT COUNT(class_id) FILTER (WHERE class_id = 1) FROM student;{code}
>
> By the way, mysql connector has a bug and fixed in FLINK-27268. Maybe you try
> this demo should cherry-pick this PR first.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)