JingsongLi commented on a change in pull request #8898: 
[FLINK-12936][table-planner-blink] Support intersect all / minus all to blink 
planner
URL: https://github.com/apache/flink/pull/8898#discussion_r298020612
 
 

 ##########
 File path: 
flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/plan/rules/logical/RewriteIntersectAll.scala
 ##########
 @@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.table.plan.rules.logical
+
+import 
org.apache.flink.table.functions.sql.FlinkSqlOperatorTable.{GREATER_THAN, 
GREATER_THAN_OR_EQUAL, IF}
+
+import org.apache.calcite.plan.{RelOptRule, RelOptRuleCall}
+import org.apache.calcite.rel.core.Intersect
+import org.apache.calcite.sql.`type`.SqlTypeName
+import org.apache.calcite.util.Util
+
+import scala.collection.JavaConversions._
+
+/**
+  * Replaces logical [[Intersect]] operator using a combination of Union, 
Aggregate
+  * and Generate operator.
+  *
+  * Input Query :
+  * {{{
+  *    SELECT c1 FROM ut1 INTERSECT ALL SELECT c1 FROM ut2
+  * }}}
+  *
+  * Rewritten Query:
+  * {{{
+  *   SELECT c1
+  *   FROM (
+  *        SELECT replicate_row(min_count, c1)
+  *        FROM (
+  *             SELECT c1, If (vcol1_cnt > vcol2_cnt, vcol2_cnt, vcol1_cnt) AS 
min_count
+  *             FROM (
+  *                  SELECT   c1, count(vcol1) as vcol1_cnt, count(vcol2) as 
vcol2_cnt
+  *                  FROM (
+  *                       SELECT c1, true as vcol1, null as vcol2 FROM ut1
+  *                       UNION ALL
+  *                       SELECT c1, null as vcol1, true as vcol2 FROM ut2
+  *                       ) AS union_all
+  *                  GROUP BY c1
+  *                  HAVING vcol1_cnt >= 1 AND vcol2_cnt >= 1
 
 Review comment:
   If I want to use `where`, I need use subquery to wrap the results of 
aggregate.
   I choose the first...

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to