zabetak commented on a change in pull request #2663: URL: https://github.com/apache/hive/pull/2663#discussion_r719314095
########## 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 assume that at some point (later in the compilation phase), you check the `HiveTableScan` operator to obtain/use the `FetchInsertOnlyBucketIds` trait. Unless I am missing something you have all the information already inside the `HiveTableScan` (`!tableMD.isMaterializedView() && AcidUtils.isInsertOnlyTable(tableMD)`) to derive it on the fly when needed. I don't understand very well why you need a rule to set it explicitly. Apologies if my reasoning is off but this is my happy break from escalations :) -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
