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

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

                Author: ASF GitHub Bot
            Created on: 11/Mar/20 18:57
            Start Date: 11/Mar/20 18:57
    Worklog Time Spent: 10m 
      Work Description: vineetgarg02 commented on pull request #943: HIVE-22962
URL: https://github.com/apache/hive/pull/943#discussion_r391186386
 
 

 ##########
 File path: 
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/RelFieldTrimmer.java
 ##########
 @@ -0,0 +1,1124 @@
+/*
+ * 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;
+
+import org.apache.calcite.linq4j.Ord;
+import org.apache.calcite.plan.RelOptCluster;
+import org.apache.calcite.plan.RelOptUtil;
+import org.apache.calcite.rel.RelCollation;
+import org.apache.calcite.rel.RelCollations;
+import org.apache.calcite.rel.RelFieldCollation;
+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.CorrelationId;
+import org.apache.calcite.rel.core.Filter;
+import org.apache.calcite.rel.core.Join;
+import org.apache.calcite.rel.core.JoinRelType;
+import org.apache.calcite.rel.core.Project;
+import org.apache.calcite.rel.core.SetOp;
+import org.apache.calcite.rel.core.Sort;
+import org.apache.calcite.rel.core.TableScan;
+import org.apache.calcite.rel.logical.LogicalTableFunctionScan;
+import org.apache.calcite.rel.logical.LogicalTableModify;
+import org.apache.calcite.rel.logical.LogicalValues;
+import org.apache.calcite.rel.metadata.RelMetadataQuery;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.rel.type.RelDataTypeField;
+import org.apache.calcite.rel.type.RelDataTypeImpl;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexCorrelVariable;
+import org.apache.calcite.rex.RexDynamicParam;
+import org.apache.calcite.rex.RexFieldAccess;
+import org.apache.calcite.rex.RexLiteral;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.rex.RexPermuteInputsShuttle;
+import org.apache.calcite.rex.RexUtil;
+import org.apache.calcite.rex.RexVisitor;
+import org.apache.calcite.sql.SqlExplainFormat;
+import org.apache.calcite.sql.SqlExplainLevel;
+import org.apache.calcite.sql2rel.CorrelationReferenceFinder;
+import org.apache.calcite.tools.RelBuilder;
+import org.apache.calcite.util.Bug;
+import org.apache.calcite.util.ImmutableBitSet;
+import org.apache.calcite.util.Pair;
+import org.apache.calcite.util.ReflectUtil;
+import org.apache.calcite.util.ReflectiveVisitor;
+import org.apache.calcite.util.Util;
+import org.apache.calcite.util.mapping.IntPair;
+import org.apache.calcite.util.mapping.Mapping;
+import org.apache.calcite.util.mapping.MappingType;
+import org.apache.calcite.util.mapping.Mappings;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This class comes from Calcite almost as-is. The only change concerns
+ * the dispatcher and the builder, so the trimmer is thread-safe and can
+ * be reused across different queries. Definition follows.
+ *
+ * <p>Transformer that walks over a tree of relational expressions, replacing 
each
+ * {@link RelNode} with a 'slimmed down' relational expression that projects
+ * only the columns required by its consumer.
+ *
+ * <p>Uses multi-methods to fire the right rule for each type of relational
+ * expression. This allows the transformer to be extended without having to
+ * add a new method to RelNode, and without requiring a collection of rule
+ * classes scattered to the four winds.
+ */
+public class RelFieldTrimmer implements ReflectiveVisitor {
+  //~ Static fields/initializers ---------------------------------------------
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(RelFieldTrimmer.class);
+
+  protected static final ThreadLocal<RelBuilder> REL_BUILDER =
+      new ThreadLocal<>();
+
+  //~ Instance fields --------------------------------------------------------
+
+  protected final HiveReflectUtil.ClassMethodDispatcher<TrimResult, RelNode> 
trimFieldsDispatcher;
+
+  //~ Constructors -----------------------------------------------------------
+
+  /**
+   * Creates a RelFieldTrimmer.
+   */
+  protected RelFieldTrimmer(boolean useLMFBasedDispatcher) {
+    if (useLMFBasedDispatcher) {
+      this.trimFieldsDispatcher =
+          HiveReflectUtil.createMethodDispatcher(
+              TrimResult.class,
+              this,
+              "trimFields",
+              RelNode.class,
+              ImmutableBitSet.class,
+              Set.class);
+    } else {
+      this.trimFieldsDispatcher =
 
 Review comment:
   Is this still around only for testing/benchmarking? If so a comment would be 
helpful
 
----------------------------------------------------------------
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: 401682)
    Time Spent: 20m  (was: 10m)

> Reuse HiveRelFieldTrimmer instance across queries
> -------------------------------------------------
>
>                 Key: HIVE-22962
>                 URL: https://issues.apache.org/jira/browse/HIVE-22962
>             Project: Hive
>          Issue Type: Improvement
>          Components: CBO
>            Reporter: Jesus Camacho Rodriguez
>            Assignee: Jesus Camacho Rodriguez
>            Priority: Major
>              Labels: pull-request-available
>         Attachments: HIVE-22962.01.patch, HIVE-22962.02.patch, 
> HIVE-22962.03.patch, HIVE-22962.04.patch, HIVE-22962.05.patch, 
> HIVE-22962.06.patch, HIVE-22962.patch
>
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> Currently we create multiple {{HiveRelFieldTrimmer}} instances per query. 
> {{HiveRelFieldTrimmer}} uses a method dispatcher that has a built-in caching 
> mechanism: given a certain object, it stores the method that was called for 
> the object class. However, by instantiating the trimmer multiple times per 
> query and across queries, we create a new dispatcher with each instantiation, 
> thus effectively removing the caching mechanism that is built within the 
> dispatcher.
> This issue is to reutilize the same {{HiveRelFieldTrimmer}} instance within a 
> single query and across queries.



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

Reply via email to