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

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

                Author: ASF GitHub Bot
            Created on: 30/Sep/21 12:50
            Start Date: 30/Sep/21 12:50
    Worklog Time Spent: 10m 
      Work Description: kasakrisz commented on a change in pull request #2663:
URL: https://github.com/apache/hive/pull/2663#discussion_r719371779



##########
File path: 
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/views/HiveInsertOnlyScanWriteIdRule.java
##########
@@ -0,0 +1,56 @@
+/*
+ * 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 org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.rel.RelNode;
+import org.apache.hadoop.hive.ql.io.AcidUtils;
+import org.apache.hadoop.hive.ql.metadata.Table;
+import org.apache.hadoop.hive.ql.optimizer.calcite.RelOptHiveTable;
+import org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveTableScan;
+
+import static 
org.apache.hadoop.hive.conf.Constants.INSERT_ONLY_FETCH_BUCKET_ID;
+
+/**
+ * This rule turns on populating writeId of insert only table scans.
+ */
+public class HiveInsertOnlyScanWriteIdRule extends RelOptRule {
+
+  public static final HiveInsertOnlyScanWriteIdRule INSTANCE = new 
HiveInsertOnlyScanWriteIdRule();
+
+  private HiveInsertOnlyScanWriteIdRule() {
+    super(operand(HiveTableScan.class, none()));
+  }
+
+  @Override
+  public boolean matches(RelOptRuleCall call) {
+    HiveTableScan tableScan = call.rel(0);
+    Table tableMD = ((RelOptHiveTable) tableScan.getTable()).getHiveTableMD();
+    return !tableMD.isMaterializedView() && 
AcidUtils.isInsertOnlyTable(tableMD);
+  }
+
+  @Override
+  public void onMatch(RelOptRuleCall call) {
+    HiveTableScan tableScan = call.rel(0);
+    RelNode newTableScan = call.builder()
+            
.push(tableScan.setTableScanTrait(HiveTableScan.HiveTableScanTrait.FetchInsertOnlyBucketIds))

Review comment:
       I don't want to enable fetching writeId automatically for any non MV 
insert only table.
   If someone execute the query like 
   ```
   SELECT t1.ROW__ID, t1.ROW__ID.writeId, a, b FROM t1;
   ```
   where `t1` is an insert only table 
   the result will contain `0` for ROW__ID.rowId for all records but will 
contain valid values for bucketId and writeId but only for not compacted 
records. This is confusing for users.
   
   But this feature can still be used in case of incremental MV rebuild since 
compaction excludes the use of incremental rebuild.
   
   So the goal was enable writeId fetch just when it is necessary. To control 
it in the AST level the `insertonly.fetch.bucketid` is used. It is a similar 
property like the `acid.fetch.deleted.rows`.
   See #2549
   




-- 
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.

To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


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

    Worklog Id:     (was: 658302)
    Time Spent: 2.5h  (was: 2h 20m)

> Enable incremental rebuild of Materialized views with insert only source 
> tables
> -------------------------------------------------------------------------------
>
>                 Key: HIVE-25546
>                 URL: https://issues.apache.org/jira/browse/HIVE-25546
>             Project: Hive
>          Issue Type: Improvement
>          Components: CBO, Materialized views
>            Reporter: Krisztian Kasa
>            Assignee: Krisztian Kasa
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 2.5h
>  Remaining Estimate: 0h
>
> {code}
> create table t1(a int, b int, c int) stored as parquet TBLPROPERTIES 
> ('transactional'='true', 'transactional_properties'='insert_only');
> create materialized view mat1 stored as orc TBLPROPERTIES 
> ('transactional'='true') as
> select a, b, c from t1 where a > 10;
> {code}
> Currently materialized view *mat1* can not be rebuilt incrementally because 
> it has an insert only source table (t1). Such tables does not have 
> ROW_ID.write_id which is required to identify newly inserted records since 
> the last rebuild.
> HIVE-25406 adds the ability to query write_id.



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

Reply via email to