[ 
https://issues.apache.org/jira/browse/HIVE-24992?focusedWorklogId=590287&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-590287
 ]

ASF GitHub Bot logged work on HIVE-24992:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 28/Apr/21 10:50
            Start Date: 28/Apr/21 10:50
    Worklog Time Spent: 10m 
      Work Description: kasakrisz commented on a change in pull request #2196:
URL: https://github.com/apache/hive/pull/2196#discussion_r622058477



##########
File path: 
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/views/HiveAggregateInsertDeleteIncrementalRewritingRule.java
##########
@@ -0,0 +1,200 @@
+/*
+ * 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.hadoop.hive.ql.optimizer.calcite.rules.views;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.Aggregate;
+import org.apache.calcite.rel.core.AggregateCall;
+import org.apache.calcite.rel.core.Union;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.sql.SqlAggFunction;
+import org.apache.calcite.sql.SqlKind;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.tools.RelBuilder;
+import org.apache.hadoop.hive.ql.optimizer.calcite.HiveRelFactories;
+
+import 
org.apache.hadoop.hive.ql.optimizer.calcite.rules.HiveHepExtractRelNodeRule;
+
+/**
+ * This rule will perform a rewriting to prepare the plan for incremental
+ * view maintenance in case there exist aggregation operator, so we can
+ * avoid the INSERT OVERWRITE and use a MERGE statement instead.
+ *
+ * In particular, the INSERT OVERWRITE maintenance will look like this
+ * (in SQL):
+ * INSERT OVERWRITE mv
+ * SELECT a, b, SUM(s) as s, SUM(c) AS c
+ * FROM (
+ *   SELECT * from mv --OLD DATA
+ *   UNION ALL
+ *   SELECT a, b, SUM(x) AS s, COUNT(*) AS c --NEW DATA
+ *   FROM TAB_A
+ *   JOIN TAB_B ON (TAB_A.a = TAB_B.z)
+ *   WHERE TAB_A.ROW_ID > 5
+ *   GROUP BY a, b) inner_subq
+ * GROUP BY a, b;
+ *
+ * We need to transform that into:
+ * MERGE INTO mv
+ * USING (
+ *   SELECT a, b, SUM(x) AS s, COUNT(*) AS c --NEW DATA
+ *   FROM TAB_A
+ *   JOIN TAB_B ON (TAB_A.a = TAB_B.z)
+ *   WHERE TAB_A.ROW_ID > 5
+ *   GROUP BY a, b) source
+ * ON (mv.a <=> source.a AND mv.b <=> source.b)
+ * WHEN MATCHED AND mv.c + source.c &lt;&gt; 0
+ *   THEN UPDATE SET mv.s = mv.s + source.s, mv.c = mv.c + source.c
+ * WHEN NOT MATCHED
+ *   THEN INSERT VALUES (source.a, source.b, s, c);
+ * WHEN MATCHED AND countStar = 0 THEN DELETE

Review comment:
       fixed




-- 
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:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 590287)
    Time Spent: 1h  (was: 50m)

> Incremental rebuild of MV having aggregate in presence of delete operation
> --------------------------------------------------------------------------
>
>                 Key: HIVE-24992
>                 URL: https://issues.apache.org/jira/browse/HIVE-24992
>             Project: Hive
>          Issue Type: Improvement
>          Components: Materialized views
>            Reporter: Krisztian Kasa
>            Assignee: Krisztian Kasa
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 1h
>  Remaining Estimate: 0h
>
> Extension of HIVE-24854: handle cases when the Materialized view definition 
> has aggregation like
> {code}
> CREATE MATERIALIZED VIEW cmv_mat_view_n5 DISABLE REWRITE TBLPROPERTIES 
> ('transactional'='true') AS
>   SELECT cmv_basetable_n5.a, cmv_basetable_2_n2.c, sum(cmv_basetable_2_n2.d)
>   FROM cmv_basetable_n5 JOIN cmv_basetable_2_n2 ON (cmv_basetable_n5.a = 
> cmv_basetable_2_n2.a)
>   WHERE cmv_basetable_2_n2.c > 10.0
>   GROUP BY cmv_basetable_n5.a, cmv_basetable_2_n2.c;
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to