You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2020/01/03 10:11:48 UTC

[GitHub] [flink] cshuo opened a new pull request #10760: [FLINK-15466][table-planner] Fix bug of `FlinkAggregateExpandDistinct…

cshuo opened a new pull request #10760: [FLINK-15466][table-planner] Fix bug of `FlinkAggregateExpandDistinct…
URL: https://github.com/apache/flink/pull/10760
 
 
   ## What is the purpose of the change
   
   Fix bug of `FlinkAggregateExpandDistinctAggregatesRule`; it'll generate wrong plan for cases where distinct aggregate calls with filter are used.
   
   ## Brief change log
     - This PR mainly fix bugs of `FlinkAggregateExpandDistinctAggregatesRule`.
   
   ## Verifying this change
   
   This change added tests and can be verified as follows:
   
     - Added integration tests in `DistinctAggregateITCaseBase` for end-to-end test.
     - Added tests in `DistinctAggregateTest` that validates the plan for cases with distinct aggregate calls with filter.
   
   ## Does this pull request potentially affect one of the following parts:
   
     - Dependencies (does it add or upgrade a dependency): (no)
     - The public API, i.e., is any changed class annotated with `@Public(Evolving)`: (no)
     - The serializers: (no)
     - The runtime per-record code paths (performance sensitive): (no)
     - Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Yarn/Mesos, ZooKeeper: (no)
     - The S3 file system connector: (no)
   
   ## Documentation
   
     - Does this pull request introduce a new feature? (no)
   

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] flinkbot edited a comment on issue #10760: [FLINK-15466][table-planner] Fix bug of `FlinkAggregateExpandDistinct…

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on issue #10760: [FLINK-15466][table-planner] Fix bug of `FlinkAggregateExpandDistinct…
URL: https://github.com/apache/flink/pull/10760#issuecomment-570537755
 
 
   <!--
   Meta data
   Hash:1d4e987c1b33f2352f76469b73bc1c0ae39ef6b6 Status:FAILURE URL:https://travis-ci.com/flink-ci/flink/builds/142981507 TriggerType:PUSH TriggerID:1d4e987c1b33f2352f76469b73bc1c0ae39ef6b6
   Hash:1d4e987c1b33f2352f76469b73bc1c0ae39ef6b6 Status:CANCELED URL:https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=4072 TriggerType:PUSH TriggerID:1d4e987c1b33f2352f76469b73bc1c0ae39ef6b6
   Hash:a1a1050925ee174aafd73f365bba300e194d95f1 Status:SUCCESS URL:https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=4157 TriggerType:PUSH TriggerID:a1a1050925ee174aafd73f365bba300e194d95f1
   Hash:a1a1050925ee174aafd73f365bba300e194d95f1 Status:PENDING URL:https://travis-ci.com/flink-ci/flink/builds/143363381 TriggerType:PUSH TriggerID:a1a1050925ee174aafd73f365bba300e194d95f1
   -->
   ## CI report:
   
   * 1d4e987c1b33f2352f76469b73bc1c0ae39ef6b6 Travis: [FAILURE](https://travis-ci.com/flink-ci/flink/builds/142981507) Azure: [CANCELED](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=4072) 
   * a1a1050925ee174aafd73f365bba300e194d95f1 Travis: [PENDING](https://travis-ci.com/flink-ci/flink/builds/143363381) Azure: [SUCCESS](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=4157) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] godfreyhe commented on a change in pull request #10760: [FLINK-15466][table-planner] Fix bug of `FlinkAggregateExpandDistinct…

Posted by GitBox <gi...@apache.org>.
godfreyhe commented on a change in pull request #10760: [FLINK-15466][table-planner] Fix bug of `FlinkAggregateExpandDistinct…
URL: https://github.com/apache/flink/pull/10760#discussion_r363181207
 
 

 ##########
 File path: flink-table/flink-table-planner-blink/src/test/scala/org/apache/flink/table/planner/plan/batch/sql/agg/DistinctAggregateTest.scala
 ##########
 @@ -82,4 +83,39 @@ class DistinctAggregateTest extends TableTestBase {
     util.verifyPlan(sqlQuery)
   }
 
+  @Test
+  def testSingleDistinctWithFilter(): Unit = {
+    val sqlQuery = "SELECT d, COUNT(DISTINCT c) FILTER (WHERE a > 0) FROM MyTable2 GROUP BY d"
+    util.verifyPlan(sqlQuery)
+  }
+
+  @Test
+  def testMultiDistinctOnSameColumnWithFilter(): Unit = {
+    val sqlQuery = "SELECT d, COUNT(DISTINCT c), COUNT(DISTINCT c) FILTER (WHERE a > 10),\n" +
+      "COUNT(DISTINCT c) FILTER (WHERE a < 10) FROM MyTable2 GROUP BY d"
+    util.verifyPlan(sqlQuery)
+  }
+
+  @Test
+  def TestMultiDistinctOnDifferentColumnWithFilter(): Unit = {
+    val sqlQuery = "SELECT d, COUNT(DISTINCT c), COUNT(DISTINCT c) FILTER (WHERE a > 0),\n" +
+      "COUNT(DISTINCT b) FILTER (WHERE b > 1) FROM MyTable2 GROUP BY d"
+    util.verifyPlan(sqlQuery)
+  }
+
+  @Test
+  def TestMultiDistinctWithFilterAndNonDistinctAgg(): Unit = {
+    val sqlQuery = "SELECT d, COUNT(DISTINCT c), COUNT(DISTINCT c) FILTER (WHERE a > 0),\n" +
+      "MAX(e), MIN(e) FROM MyTable2 GROUP BY d"
+    util.verifyPlan(sqlQuery)
+  }
+
+  @Test
+  def testMultiDistinctAndNonDistinctAggWithFilter(): Unit = {
+    val sqlQuery = "SELECT d, MAX(e), MAX(e) FILTER (WHERE a < 10), COUNT(DISTINCT c),\n" +
+      "COUNT(DISTINCT c) FILTER (WHERE a > 5), COUNT(DISTINCT b) FILTER (WHERE b > 3)\n" +
+      "FROM MyTable2 GROUP BY d"
+    util.verifyPlan(sqlQuery)
+  }
+
 
 Review comment:
   actually, It's better to extract a common test case base named `DistinctAggregateTestBase` (like `AggregateReduceGroupingTestBase`)

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] flinkbot edited a comment on issue #10760: [FLINK-15466][table-planner] Fix bug of `FlinkAggregateExpandDistinct…

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on issue #10760: [FLINK-15466][table-planner] Fix bug of `FlinkAggregateExpandDistinct…
URL: https://github.com/apache/flink/pull/10760#issuecomment-570537755
 
 
   <!--
   Meta data
   Hash:1d4e987c1b33f2352f76469b73bc1c0ae39ef6b6 Status:FAILURE URL:https://travis-ci.com/flink-ci/flink/builds/142981507 TriggerType:PUSH TriggerID:1d4e987c1b33f2352f76469b73bc1c0ae39ef6b6
   Hash:1d4e987c1b33f2352f76469b73bc1c0ae39ef6b6 Status:CANCELED URL:https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=4072 TriggerType:PUSH TriggerID:1d4e987c1b33f2352f76469b73bc1c0ae39ef6b6
   Hash:a1a1050925ee174aafd73f365bba300e194d95f1 Status:PENDING URL:https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=4157 TriggerType:PUSH TriggerID:a1a1050925ee174aafd73f365bba300e194d95f1
   Hash:a1a1050925ee174aafd73f365bba300e194d95f1 Status:PENDING URL:https://travis-ci.com/flink-ci/flink/builds/143363381 TriggerType:PUSH TriggerID:a1a1050925ee174aafd73f365bba300e194d95f1
   -->
   ## CI report:
   
   * 1d4e987c1b33f2352f76469b73bc1c0ae39ef6b6 Travis: [FAILURE](https://travis-ci.com/flink-ci/flink/builds/142981507) Azure: [CANCELED](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=4072) 
   * a1a1050925ee174aafd73f365bba300e194d95f1 Travis: [PENDING](https://travis-ci.com/flink-ci/flink/builds/143363381) Azure: [PENDING](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=4157) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] flinkbot edited a comment on issue #10760: [FLINK-15466][table-planner] Fix bug of `FlinkAggregateExpandDistinct…

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on issue #10760: [FLINK-15466][table-planner] Fix bug of `FlinkAggregateExpandDistinct…
URL: https://github.com/apache/flink/pull/10760#issuecomment-570537755
 
 
   <!--
   Meta data
   Hash:1d4e987c1b33f2352f76469b73bc1c0ae39ef6b6 Status:PENDING URL:https://travis-ci.com/flink-ci/flink/builds/142981507 TriggerType:PUSH TriggerID:1d4e987c1b33f2352f76469b73bc1c0ae39ef6b6
   Hash:1d4e987c1b33f2352f76469b73bc1c0ae39ef6b6 Status:CANCELED URL:https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=4072 TriggerType:PUSH TriggerID:1d4e987c1b33f2352f76469b73bc1c0ae39ef6b6
   -->
   ## CI report:
   
   * 1d4e987c1b33f2352f76469b73bc1c0ae39ef6b6 Travis: [PENDING](https://travis-ci.com/flink-ci/flink/builds/142981507) Azure: [CANCELED](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=4072) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] cshuo commented on a change in pull request #10760: [FLINK-15466][table-planner] Fix bug of `FlinkAggregateExpandDistinct…

Posted by GitBox <gi...@apache.org>.
cshuo commented on a change in pull request #10760: [FLINK-15466][table-planner] Fix bug of `FlinkAggregateExpandDistinct…
URL: https://github.com/apache/flink/pull/10760#discussion_r363139651
 
 

 ##########
 File path: flink-table/flink-table-planner-blink/src/test/scala/org/apache/flink/table/planner/plan/batch/sql/agg/DistinctAggregateTest.scala
 ##########
 @@ -82,4 +83,39 @@ class DistinctAggregateTest extends TableTestBase {
     util.verifyPlan(sqlQuery)
   }
 
+  @Test
+  def testSingleDistinctWithFilter(): Unit = {
+    val sqlQuery = "SELECT d, COUNT(DISTINCT c) FILTER (WHERE a > 0) FROM MyTable2 GROUP BY d"
+    util.verifyPlan(sqlQuery)
+  }
+
+  @Test
+  def testMultiDistinctOnSameColumnWithFilter(): Unit = {
+    val sqlQuery = "SELECT d, COUNT(DISTINCT c), COUNT(DISTINCT c) FILTER (WHERE a > 10),\n" +
+      "COUNT(DISTINCT c) FILTER (WHERE a < 10) FROM MyTable2 GROUP BY d"
+    util.verifyPlan(sqlQuery)
+  }
+
+  @Test
+  def TestMultiDistinctOnDifferentColumnWithFilter(): Unit = {
+    val sqlQuery = "SELECT d, COUNT(DISTINCT c), COUNT(DISTINCT c) FILTER (WHERE a > 0),\n" +
+      "COUNT(DISTINCT b) FILTER (WHERE b > 1) FROM MyTable2 GROUP BY d"
+    util.verifyPlan(sqlQuery)
+  }
+
+  @Test
+  def TestMultiDistinctWithFilterAndNonDistinctAgg(): Unit = {
+    val sqlQuery = "SELECT d, COUNT(DISTINCT c), COUNT(DISTINCT c) FILTER (WHERE a > 0),\n" +
+      "MAX(e), MIN(e) FROM MyTable2 GROUP BY d"
+    util.verifyPlan(sqlQuery)
+  }
+
+  @Test
+  def testMultiDistinctAndNonDistinctAggWithFilter(): Unit = {
+    val sqlQuery = "SELECT d, MAX(e), MAX(e) FILTER (WHERE a < 10), COUNT(DISTINCT c),\n" +
+      "COUNT(DISTINCT c) FILTER (WHERE a > 5), COUNT(DISTINCT b) FILTER (WHERE b > 3)\n" +
+      "FROM MyTable2 GROUP BY d"
+    util.verifyPlan(sqlQuery)
+  }
+
 
 Review comment:
   > please move these cases to `FlinkAggregateExpandDistinctAggregatesRuleTest`
   
   I noticed there are common distinct tests between `FlinkAggregateExpandDistinctAggregatesRuleTest` and `DistinctAggregateTest`, it's better to reserve them here, and copy them to `FlinkAggregateExpandDistinctAggregatesRuleTest` as well?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] godfreyhe commented on a change in pull request #10760: [FLINK-15466][table-planner] Fix bug of `FlinkAggregateExpandDistinct…

Posted by GitBox <gi...@apache.org>.
godfreyhe commented on a change in pull request #10760: [FLINK-15466][table-planner] Fix bug of `FlinkAggregateExpandDistinct…
URL: https://github.com/apache/flink/pull/10760#discussion_r363135100
 
 

 ##########
 File path: flink-table/flink-table-planner-blink/src/main/java/org/apache/flink/table/planner/plan/rules/logical/FlinkAggregateExpandDistinctAggregatesRule.java
 ##########
 @@ -471,10 +474,24 @@ private void rewriteUsingGroupingSets(RelOptRuleCall call,
 			final RexNode nodeZ = nodes.remove(nodes.size() - 1);
 			for (Map.Entry<ImmutableBitSet, Integer> entry : filters.entrySet()) {
 				final long v = groupValue(fullGroupSet, entry.getKey());
-				nodes.add(
+				// Remap and get the filterArg of the distinct aggregate call.
 
 Review comment:
   Get and remap xx ?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] flinkbot edited a comment on issue #10760: [FLINK-15466][table-planner] Fix bug of `FlinkAggregateExpandDistinct…

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on issue #10760: [FLINK-15466][table-planner] Fix bug of `FlinkAggregateExpandDistinct…
URL: https://github.com/apache/flink/pull/10760#issuecomment-570537755
 
 
   <!--
   Meta data
   Hash:1d4e987c1b33f2352f76469b73bc1c0ae39ef6b6 Status:FAILURE URL:https://travis-ci.com/flink-ci/flink/builds/142981507 TriggerType:PUSH TriggerID:1d4e987c1b33f2352f76469b73bc1c0ae39ef6b6
   Hash:1d4e987c1b33f2352f76469b73bc1c0ae39ef6b6 Status:CANCELED URL:https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=4072 TriggerType:PUSH TriggerID:1d4e987c1b33f2352f76469b73bc1c0ae39ef6b6
   Hash:a1a1050925ee174aafd73f365bba300e194d95f1 Status:UNKNOWN URL:TBD TriggerType:PUSH TriggerID:a1a1050925ee174aafd73f365bba300e194d95f1
   -->
   ## CI report:
   
   * 1d4e987c1b33f2352f76469b73bc1c0ae39ef6b6 Travis: [FAILURE](https://travis-ci.com/flink-ci/flink/builds/142981507) Azure: [CANCELED](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=4072) 
   * a1a1050925ee174aafd73f365bba300e194d95f1 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] flinkbot commented on issue #10760: [FLINK-15466][table-planner] Fix bug of `FlinkAggregateExpandDistinct…

Posted by GitBox <gi...@apache.org>.
flinkbot commented on issue #10760: [FLINK-15466][table-planner] Fix bug of `FlinkAggregateExpandDistinct…
URL: https://github.com/apache/flink/pull/10760#issuecomment-570528439
 
 
   Thanks a lot for your contribution to the Apache Flink project. I'm the @flinkbot. I help the community
   to review your pull request. We will use this comment to track the progress of the review.
   
   
   ## Automated Checks
   Last check on commit 1d4e987c1b33f2352f76469b73bc1c0ae39ef6b6 (Fri Jan 03 10:13:54 UTC 2020)
   
   **Warnings:**
    * No documentation files were touched! Remember to keep the Flink docs up to date!
    * **This pull request references an unassigned [Jira ticket](https://issues.apache.org/jira/browse/FLINK-15466).** According to the [code contribution guide](https://flink.apache.org/contributing/contribute-code.html), tickets need to be assigned before starting with the implementation work.
   
   
   <sub>Mention the bot in a comment to re-run the automated checks.</sub>
   ## Review Progress
   
   * ❓ 1. The [description] looks good.
   * ❓ 2. There is [consensus] that the contribution should go into to Flink.
   * ❓ 3. Needs [attention] from.
   * ❓ 4. The change fits into the overall [architecture].
   * ❓ 5. Overall code [quality] is good.
   
   Please see the [Pull Request Review Guide](https://flink.apache.org/contributing/reviewing-prs.html) for a full explanation of the review process.<details>
    The Bot is tracking the review progress through labels. Labels are applied according to the order of the review items. For consensus, approval by a Flink committer of PMC member is required <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot approve description` to approve one or more aspects (aspects: `description`, `consensus`, `architecture` and `quality`)
    - `@flinkbot approve all` to approve all aspects
    - `@flinkbot approve-until architecture` to approve everything until `architecture`
    - `@flinkbot attention @username1 [@username2 ..]` to require somebody's attention
    - `@flinkbot disapprove architecture` to remove an approval you gave earlier
   </details>

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] cshuo commented on issue #10760: [FLINK-15466][table-planner] Fix bug of `FlinkAggregateExpandDistinct…

Posted by GitBox <gi...@apache.org>.
cshuo commented on issue #10760: [FLINK-15466][table-planner] Fix bug of `FlinkAggregateExpandDistinct…
URL: https://github.com/apache/flink/pull/10760#issuecomment-572376100
 
 
   @godfreyhe I've made some changes. CC @KurtYoung, would you have a look too?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] godfreyhe commented on a change in pull request #10760: [FLINK-15466][table-planner] Fix bug of `FlinkAggregateExpandDistinct…

Posted by GitBox <gi...@apache.org>.
godfreyhe commented on a change in pull request #10760: [FLINK-15466][table-planner] Fix bug of `FlinkAggregateExpandDistinct…
URL: https://github.com/apache/flink/pull/10760#discussion_r363135740
 
 

 ##########
 File path: flink-table/flink-table-planner-blink/src/test/scala/org/apache/flink/table/planner/plan/batch/sql/agg/DistinctAggregateTest.scala
 ##########
 @@ -82,4 +83,39 @@ class DistinctAggregateTest extends TableTestBase {
     util.verifyPlan(sqlQuery)
   }
 
+  @Test
+  def testSingleDistinctWithFilter(): Unit = {
+    val sqlQuery = "SELECT d, COUNT(DISTINCT c) FILTER (WHERE a > 0) FROM MyTable2 GROUP BY d"
+    util.verifyPlan(sqlQuery)
+  }
+
+  @Test
+  def testMultiDistinctOnSameColumnWithFilter(): Unit = {
+    val sqlQuery = "SELECT d, COUNT(DISTINCT c), COUNT(DISTINCT c) FILTER (WHERE a > 10),\n" +
+      "COUNT(DISTINCT c) FILTER (WHERE a < 10) FROM MyTable2 GROUP BY d"
+    util.verifyPlan(sqlQuery)
+  }
+
+  @Test
+  def TestMultiDistinctOnDifferentColumnWithFilter(): Unit = {
+    val sqlQuery = "SELECT d, COUNT(DISTINCT c), COUNT(DISTINCT c) FILTER (WHERE a > 0),\n" +
+      "COUNT(DISTINCT b) FILTER (WHERE b > 1) FROM MyTable2 GROUP BY d"
+    util.verifyPlan(sqlQuery)
+  }
+
+  @Test
+  def TestMultiDistinctWithFilterAndNonDistinctAgg(): Unit = {
+    val sqlQuery = "SELECT d, COUNT(DISTINCT c), COUNT(DISTINCT c) FILTER (WHERE a > 0),\n" +
+      "MAX(e), MIN(e) FROM MyTable2 GROUP BY d"
+    util.verifyPlan(sqlQuery)
+  }
+
+  @Test
+  def testMultiDistinctAndNonDistinctAggWithFilter(): Unit = {
+    val sqlQuery = "SELECT d, MAX(e), MAX(e) FILTER (WHERE a < 10), COUNT(DISTINCT c),\n" +
+      "COUNT(DISTINCT c) FILTER (WHERE a > 5), COUNT(DISTINCT b) FILTER (WHERE b > 3)\n" +
+      "FROM MyTable2 GROUP BY d"
+    util.verifyPlan(sqlQuery)
+  }
+
 
 Review comment:
   please move these cases to `FlinkAggregateExpandDistinctAggregatesRuleTest` 

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] godfreyhe commented on a change in pull request #10760: [FLINK-15466][table-planner] Fix bug of `FlinkAggregateExpandDistinct…

Posted by GitBox <gi...@apache.org>.
godfreyhe commented on a change in pull request #10760: [FLINK-15466][table-planner] Fix bug of `FlinkAggregateExpandDistinct…
URL: https://github.com/apache/flink/pull/10760#discussion_r363136157
 
 

 ##########
 File path: flink-table/flink-table-planner-blink/src/main/java/org/apache/flink/table/planner/plan/rules/logical/FlinkAggregateExpandDistinctAggregatesRule.java
 ##########
 @@ -471,10 +474,24 @@ private void rewriteUsingGroupingSets(RelOptRuleCall call,
 			final RexNode nodeZ = nodes.remove(nodes.size() - 1);
 			for (Map.Entry<ImmutableBitSet, Integer> entry : filters.entrySet()) {
 				final long v = groupValue(fullGroupSet, entry.getKey());
-				nodes.add(
+				// Remap and get the filterArg of the distinct aggregate call.
+				int distinctAggCallFilterArg = remap(fullGroupSet,
+					groupSetToDistinctAggCallFilterArg.getOrDefault(entry.getKey(), -1));
+				if (distinctAggCallFilterArg < 0) {
+					nodes.add(
 						relBuilder.alias(
-								relBuilder.equals(nodeZ, relBuilder.literal(v)),
-								"$g_" + v));
+							relBuilder.equals(nodeZ, relBuilder.literal(v)),
+							"$g_" + v));
+				} else {
+					RexBuilder rexBuilder = aggregate.getCluster().getRexBuilder();
+					// merge the filter of the distinct aggregate call itself.
+					nodes.add(relBuilder.alias(
 
 Review comment:
   it's better to extract `nodes.add(relBuilder.alias(project, "$g_" + v)` as common part

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] flinkbot commented on issue #10760: [FLINK-15466][table-planner] Fix bug of `FlinkAggregateExpandDistinct…

Posted by GitBox <gi...@apache.org>.
flinkbot commented on issue #10760: [FLINK-15466][table-planner] Fix bug of `FlinkAggregateExpandDistinct…
URL: https://github.com/apache/flink/pull/10760#issuecomment-570537755
 
 
   <!--
   Meta data
   Hash:1d4e987c1b33f2352f76469b73bc1c0ae39ef6b6 Status:UNKNOWN URL:TBD TriggerType:PUSH TriggerID:1d4e987c1b33f2352f76469b73bc1c0ae39ef6b6
   -->
   ## CI report:
   
   * 1d4e987c1b33f2352f76469b73bc1c0ae39ef6b6 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] godfreyhe commented on a change in pull request #10760: [FLINK-15466][table-planner] Fix bug of `FlinkAggregateExpandDistinct…

Posted by GitBox <gi...@apache.org>.
godfreyhe commented on a change in pull request #10760: [FLINK-15466][table-planner] Fix bug of `FlinkAggregateExpandDistinct…
URL: https://github.com/apache/flink/pull/10760#discussion_r363135904
 
 

 ##########
 File path: flink-table/flink-table-planner-blink/src/test/scala/org/apache/flink/table/planner/plan/batch/sql/agg/DistinctAggregateTest.scala
 ##########
 @@ -82,4 +83,39 @@ class DistinctAggregateTest extends TableTestBase {
     util.verifyPlan(sqlQuery)
   }
 
+  @Test
+  def testSingleDistinctWithFilter(): Unit = {
+    val sqlQuery = "SELECT d, COUNT(DISTINCT c) FILTER (WHERE a > 0) FROM MyTable2 GROUP BY d"
+    util.verifyPlan(sqlQuery)
+  }
+
+  @Test
+  def testMultiDistinctOnSameColumnWithFilter(): Unit = {
+    val sqlQuery = "SELECT d, COUNT(DISTINCT c), COUNT(DISTINCT c) FILTER (WHERE a > 10),\n" +
+      "COUNT(DISTINCT c) FILTER (WHERE a < 10) FROM MyTable2 GROUP BY d"
+    util.verifyPlan(sqlQuery)
+  }
+
+  @Test
+  def TestMultiDistinctOnDifferentColumnWithFilter(): Unit = {
+    val sqlQuery = "SELECT d, COUNT(DISTINCT c), COUNT(DISTINCT c) FILTER (WHERE a > 0),\n" +
+      "COUNT(DISTINCT b) FILTER (WHERE b > 1) FROM MyTable2 GROUP BY d"
+    util.verifyPlan(sqlQuery)
+  }
+
+  @Test
+  def TestMultiDistinctWithFilterAndNonDistinctAgg(): Unit = {
+    val sqlQuery = "SELECT d, COUNT(DISTINCT c), COUNT(DISTINCT c) FILTER (WHERE a > 0),\n" +
+      "MAX(e), MIN(e) FROM MyTable2 GROUP BY d"
+    util.verifyPlan(sqlQuery)
+  }
+
+  @Test
+  def testMultiDistinctAndNonDistinctAggWithFilter(): Unit = {
+    val sqlQuery = "SELECT d, MAX(e), MAX(e) FILTER (WHERE a < 10), COUNT(DISTINCT c),\n" +
+      "COUNT(DISTINCT c) FILTER (WHERE a > 5), COUNT(DISTINCT b) FILTER (WHERE b > 3)\n" +
+      "FROM MyTable2 GROUP BY d"
+    util.verifyPlan(sqlQuery)
+  }
+
 
 Review comment:
   please add some cases without `GROUP BY`

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] flinkbot edited a comment on issue #10760: [FLINK-15466][table-planner] Fix bug of `FlinkAggregateExpandDistinct…

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on issue #10760: [FLINK-15466][table-planner] Fix bug of `FlinkAggregateExpandDistinct…
URL: https://github.com/apache/flink/pull/10760#issuecomment-570537755
 
 
   <!--
   Meta data
   Hash:1d4e987c1b33f2352f76469b73bc1c0ae39ef6b6 Status:FAILURE URL:https://travis-ci.com/flink-ci/flink/builds/142981507 TriggerType:PUSH TriggerID:1d4e987c1b33f2352f76469b73bc1c0ae39ef6b6
   Hash:1d4e987c1b33f2352f76469b73bc1c0ae39ef6b6 Status:CANCELED URL:https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=4072 TriggerType:PUSH TriggerID:1d4e987c1b33f2352f76469b73bc1c0ae39ef6b6
   -->
   ## CI report:
   
   * 1d4e987c1b33f2352f76469b73bc1c0ae39ef6b6 Travis: [FAILURE](https://travis-ci.com/flink-ci/flink/builds/142981507) Azure: [CANCELED](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=4072) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] flinkbot edited a comment on issue #10760: [FLINK-15466][table-planner] Fix bug of `FlinkAggregateExpandDistinct…

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on issue #10760: [FLINK-15466][table-planner] Fix bug of `FlinkAggregateExpandDistinct…
URL: https://github.com/apache/flink/pull/10760#issuecomment-570537755
 
 
   <!--
   Meta data
   Hash:1d4e987c1b33f2352f76469b73bc1c0ae39ef6b6 Status:PENDING URL:https://travis-ci.com/flink-ci/flink/builds/142981507 TriggerType:PUSH TriggerID:1d4e987c1b33f2352f76469b73bc1c0ae39ef6b6
   Hash:1d4e987c1b33f2352f76469b73bc1c0ae39ef6b6 Status:PENDING URL:https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=4072 TriggerType:PUSH TriggerID:1d4e987c1b33f2352f76469b73bc1c0ae39ef6b6
   -->
   ## CI report:
   
   * 1d4e987c1b33f2352f76469b73bc1c0ae39ef6b6 Travis: [PENDING](https://travis-ci.com/flink-ci/flink/builds/142981507) Azure: [PENDING](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=4072) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] flinkbot edited a comment on issue #10760: [FLINK-15466][table-planner] Fix bug of `FlinkAggregateExpandDistinct…

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on issue #10760: [FLINK-15466][table-planner] Fix bug of `FlinkAggregateExpandDistinct…
URL: https://github.com/apache/flink/pull/10760#issuecomment-570537755
 
 
   <!--
   Meta data
   Hash:1d4e987c1b33f2352f76469b73bc1c0ae39ef6b6 Status:FAILURE URL:https://travis-ci.com/flink-ci/flink/builds/142981507 TriggerType:PUSH TriggerID:1d4e987c1b33f2352f76469b73bc1c0ae39ef6b6
   Hash:1d4e987c1b33f2352f76469b73bc1c0ae39ef6b6 Status:CANCELED URL:https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=4072 TriggerType:PUSH TriggerID:1d4e987c1b33f2352f76469b73bc1c0ae39ef6b6
   Hash:a1a1050925ee174aafd73f365bba300e194d95f1 Status:SUCCESS URL:https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=4157 TriggerType:PUSH TriggerID:a1a1050925ee174aafd73f365bba300e194d95f1
   Hash:a1a1050925ee174aafd73f365bba300e194d95f1 Status:FAILURE URL:https://travis-ci.com/flink-ci/flink/builds/143363381 TriggerType:PUSH TriggerID:a1a1050925ee174aafd73f365bba300e194d95f1
   -->
   ## CI report:
   
   * 1d4e987c1b33f2352f76469b73bc1c0ae39ef6b6 Travis: [FAILURE](https://travis-ci.com/flink-ci/flink/builds/142981507) Azure: [CANCELED](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=4072) 
   * a1a1050925ee174aafd73f365bba300e194d95f1 Travis: [FAILURE](https://travis-ci.com/flink-ci/flink/builds/143363381) Azure: [SUCCESS](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=4157) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] KurtYoung merged pull request #10760: [FLINK-15466][table-planner] Fix bug of `FlinkAggregateExpandDistinct…

Posted by GitBox <gi...@apache.org>.
KurtYoung merged pull request #10760: [FLINK-15466][table-planner] Fix bug of `FlinkAggregateExpandDistinct…
URL: https://github.com/apache/flink/pull/10760
 
 
   

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services