hive-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (Jira)" <j...@apache.org>
Subject [jira] [Work logged] (HIVE-21196) Support semijoin reduction on multiple column join
Date Fri, 07 Aug 2020 22:53:00 GMT

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

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

                Author: ASF GitHub Bot
            Created on: 07/Aug/20 22:52
            Start Date: 07/Aug/20 22:52
    Worklog Time Spent: 10m 
      Work Description: zabetak commented on a change in pull request #1325:
URL: https://github.com/apache/hive/pull/1325#discussion_r467318270



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/optimizer/SemiJoinReductionMerge.java
##########
@@ -0,0 +1,399 @@
+/*
+ * 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;
+
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.ql.exec.ColumnInfo;
+import org.apache.hadoop.hive.ql.exec.FilterOperator;
+import org.apache.hadoop.hive.ql.exec.GroupByOperator;
+import org.apache.hadoop.hive.ql.exec.Operator;
+import org.apache.hadoop.hive.ql.exec.OperatorFactory;
+import org.apache.hadoop.hive.ql.exec.OperatorUtils;
+import org.apache.hadoop.hive.ql.exec.ReduceSinkOperator;
+import org.apache.hadoop.hive.ql.exec.RowSchema;
+import org.apache.hadoop.hive.ql.exec.SelectOperator;
+import org.apache.hadoop.hive.ql.exec.TableScanOperator;
+import org.apache.hadoop.hive.ql.exec.Utilities;
+import org.apache.hadoop.hive.ql.io.AcidUtils;
+import org.apache.hadoop.hive.ql.parse.GenTezUtils;
+import org.apache.hadoop.hive.ql.parse.ParseContext;
+import org.apache.hadoop.hive.ql.parse.RuntimeValuesInfo;
+import org.apache.hadoop.hive.ql.parse.SemanticAnalyzer;
+import org.apache.hadoop.hive.ql.parse.SemanticException;
+import org.apache.hadoop.hive.ql.parse.SemiJoinBranchInfo;
+import org.apache.hadoop.hive.ql.plan.AggregationDesc;
+import org.apache.hadoop.hive.ql.plan.DynamicValue;
+import org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc;
+import org.apache.hadoop.hive.ql.plan.ExprNodeConstantDesc;
+import org.apache.hadoop.hive.ql.plan.ExprNodeDesc;
+import org.apache.hadoop.hive.ql.plan.ExprNodeDynamicValueDesc;
+import org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc;
+import org.apache.hadoop.hive.ql.plan.FilterDesc;
+import org.apache.hadoop.hive.ql.plan.GroupByDesc;
+import org.apache.hadoop.hive.ql.plan.PlanUtils;
+import org.apache.hadoop.hive.ql.plan.ReduceSinkDesc;
+import org.apache.hadoop.hive.ql.plan.SelectDesc;
+import org.apache.hadoop.hive.ql.plan.TableDesc;
+import org.apache.hadoop.hive.ql.udf.generic.GenericUDAFBloomFilter;
+import org.apache.hadoop.hive.ql.udf.generic.GenericUDAFEvaluator;
+import org.apache.hadoop.hive.ql.udf.generic.GenericUDAFMax;
+import org.apache.hadoop.hive.ql.udf.generic.GenericUDAFMin;
+import org.apache.hadoop.hive.ql.udf.generic.GenericUDFBetween;
+import org.apache.hadoop.hive.ql.udf.generic.GenericUDFInBloomFilter;
+import org.apache.hadoop.hive.ql.udf.generic.GenericUDFMurmurHash;
+import org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPAnd;
+import org.apache.hadoop.hive.ql.util.NullOrdering;
+import org.apache.hadoop.hive.serde2.typeinfo.TypeInfo;
+import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory;
+
+import java.util.ArrayDeque;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Deque;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+public class SemiJoinReductionMerge extends Transform {
+
+  public ParseContext transform(ParseContext parseContext) throws SemanticException {
+    Map<ReduceSinkOperator, SemiJoinBranchInfo> map = parseContext.getRsToSemiJoinBranchInfo();
+    if (map.isEmpty()) {
+      return parseContext;
+    }
+    HiveConf hiveConf = parseContext.getConf();
+
+    // Order does not really matter but it is necessary to keep plans stable
+    SortedMap<SJSourceTarget, List<ReduceSinkOperator>> sameTableSJ =
+        new TreeMap<>(Comparator.comparing(SJSourceTarget::toString));
+    for (Map.Entry<ReduceSinkOperator, SemiJoinBranchInfo> smjEntry : map.entrySet())
{
+      TableScanOperator ts = smjEntry.getValue().getTsOp();
+      // Semijoin optimization branch should look like <Parent>-SEL-GB1-RS1-GB2-RS2
+      SelectOperator selOp = OperatorUtils.ancestor(smjEntry.getKey(), SelectOperator.class,
0, 0, 0, 0);
+      assert selOp != null;
+      assert selOp.getParentOperators().size() == 1;
+      Operator<?> source = selOp.getParentOperators().get(0);
+      SJSourceTarget sjKey = new SJSourceTarget(source, ts);
+      List<ReduceSinkOperator> ops = sameTableSJ.computeIfAbsent(sjKey, tableScanOperator
-> new ArrayList<>());
+      ops.add(smjEntry.getKey());
+    }
+    for (Map.Entry<SJSourceTarget, List<ReduceSinkOperator>> sjMergeCandidate
: sameTableSJ.entrySet()) {
+      final List<ReduceSinkOperator> sjBrances = sjMergeCandidate.getValue();
+      if (sjBrances.size() < 2) {
+        continue;
+      }
+      // Order does not really matter but it is necessary to keep plans stable
+      sjBrances.sort(Comparator.comparing(Operator::getIdentifier));

Review comment:
       Done in https://github.com/apache/hive/pull/1325/commits/f387d78447d9d68e2df7b20fdaab7d0c1bac905e




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


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

    Worklog Id:     (was: 468099)
    Time Spent: 3h  (was: 2h 50m)

> Support semijoin reduction on multiple column join
> --------------------------------------------------
>
>                 Key: HIVE-21196
>                 URL: https://issues.apache.org/jira/browse/HIVE-21196
>             Project: Hive
>          Issue Type: Bug
>            Reporter: Deepak Jaiswal
>            Assignee: Stamatis Zampetakis
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 3h
>  Remaining Estimate: 0h
>
> Currently for a query involving join on multiple columns creates  separate semi join
edges for each key which in turn create a bloom filter for each of them, like below,
> EXPLAIN select count(*) from srcpart_date_n7 join srcpart_small_n3 on (srcpart_date_n7.key
= srcpart_small_n3.key1 and srcpart_date_n7.value = srcpart_small_n3.value1)
> {code:java}
> Map 1 <- Reducer 5 (BROADCAST_EDGE)
>         Reducer 2 <- Map 1 (SIMPLE_EDGE), Map 4 (SIMPLE_EDGE)
>         Reducer 3 <- Reducer 2 (CUSTOM_SIMPLE_EDGE)
>         Reducer 5 <- Map 4 (CUSTOM_SIMPLE_EDGE)
> #### A masked pattern was here ####
>       Vertices:
>         Map 1 
>             Map Operator Tree:
>                 TableScan
>                   alias: srcpart_date_n7
>                   filterExpr: (key is not null and value is not null and (key BETWEEN
DynamicValue(RS_7_srcpart_small_n3_key1_min) AND DynamicValue(RS_7_srcpart_small_n3_key1_max)
and in_bloom_filter(key, DynamicValue(RS_7_srcpart_small_n3_key1_bloom_filter)))) (type: boolean)
>                   Statistics: Num rows: 2000 Data size: 356000 Basic stats: COMPLETE
Column stats: COMPLETE
>                   Filter Operator
>                     predicate: ((key BETWEEN DynamicValue(RS_7_srcpart_small_n3_key1_min)
AND DynamicValue(RS_7_srcpart_small_n3_key1_max) and in_bloom_filter(key, DynamicValue(RS_7_srcpart_small_n3_key1_bloom_filter)))
and key is not null and value is not null) (type: boolean)
>                     Statistics: Num rows: 2000 Data size: 356000 Basic stats: COMPLETE
Column stats: COMPLETE
>                     Select Operator
>                       expressions: key (type: string), value (type: string)
>                       outputColumnNames: _col0, _col1
>                       Statistics: Num rows: 2000 Data size: 356000 Basic stats: COMPLETE
Column stats: COMPLETE
>                       Reduce Output Operator
>                         key expressions: _col0 (type: string), _col1 (type: string)
>                         sort order: ++
>                         Map-reduce partition columns: _col0 (type: string), _col1 (type:
string)
>                         Statistics: Num rows: 2000 Data size: 356000 Basic stats: COMPLETE
Column stats: COMPLETE
>             Execution mode: vectorized, llap
>             LLAP IO: all inputs
>         Map 4 
>             Map Operator Tree:
>                 TableScan
>                   alias: srcpart_small_n3
>                   filterExpr: (key1 is not null and value1 is not null) (type: boolean)
>                   Statistics: Num rows: 20 Data size: 3560 Basic stats: PARTIAL Column
stats: PARTIAL
>                   Filter Operator
>                     predicate: (key1 is not null and value1 is not null) (type: boolean)
>                     Statistics: Num rows: 20 Data size: 3560 Basic stats: PARTIAL Column
stats: PARTIAL
>                     Select Operator
>                       expressions: key1 (type: string), value1 (type: string)
>                       outputColumnNames: _col0, _col1
>                       Statistics: Num rows: 20 Data size: 3560 Basic stats: PARTIAL Column
stats: PARTIAL
>                       Reduce Output Operator
>                         key expressions: _col0 (type: string), _col1 (type: string)
>                         sort order: ++
>                         Map-reduce partition columns: _col0 (type: string), _col1 (type:
string)
>                         Statistics: Num rows: 20 Data size: 3560 Basic stats: PARTIAL
Column stats: PARTIAL
>                       Select Operator
>                         expressions: _col0 (type: string)
>                         outputColumnNames: _col0
>                         Statistics: Num rows: 20 Data size: 3560 Basic stats: PARTIAL
Column stats: PARTIAL
>                         Group By Operator
>                           aggregations: min(_col0), max(_col0), bloom_filter(_col0, expectedEntries=20)
>                           mode: hash
>                           outputColumnNames: _col0, _col1, _col2
>                           Statistics: Num rows: 1 Data size: 730 Basic stats: PARTIAL
Column stats: PARTIAL
>                           Reduce Output Operator
>                             sort order: 
>                             Statistics: Num rows: 1 Data size: 730 Basic stats: PARTIAL
Column stats: PARTIAL
>                             value expressions: _col0 (type: string), _col1 (type: string),
_col2 (type: binary)
>             Execution mode: vectorized, llap
>             LLAP IO: all inputs
>         Reducer 2 
>             Execution mode: llap
>             Reduce Operator Tree:
>               Merge Join Operator
>                 condition map:
>                      Inner Join 0 to 1
>                 keys:
>                   0 _col0 (type: string), _col1 (type: string)
>                   1 _col0 (type: string), _col1 (type: string)
>                 Statistics: Num rows: 2200 Data size: 391600 Basic stats: PARTIAL Column
stats: NONE
>                 Group By Operator
>                   aggregations: count()
>                   mode: hash
>                   outputColumnNames: _col0
>                   Statistics: Num rows: 1 Data size: 8 Basic stats: PARTIAL Column stats:
NONE
>                   Reduce Output Operator
>                     sort order: 
>                     Statistics: Num rows: 1 Data size: 8 Basic stats: PARTIAL Column
stats: NONE
>                     value expressions: _col0 (type: bigint)
>         Reducer 3 
>             Execution mode: vectorized, llap
>             Reduce Operator Tree:
>               Group By Operator
>                 aggregations: count(VALUE._col0)
>                 mode: mergepartial
>                 outputColumnNames: _col0
>                 Statistics: Num rows: 1 Data size: 8 Basic stats: PARTIAL Column stats:
NONE
>                 File Output Operator
>                   compressed: false
>                   Statistics: Num rows: 1 Data size: 8 Basic stats: PARTIAL Column stats:
NONE
>                   table:
>                       input format: org.apache.hadoop.mapred.SequenceFileInputFormat
>                       output format: org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat
>                       serde: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
>         Reducer 5 
>             Execution mode: vectorized, llap
>             Reduce Operator Tree:
>               Group By Operator
>                 aggregations: min(VALUE._col0), max(VALUE._col1), bloom_filter(VALUE._col2,
expectedEntries=20)
>                 mode: final
>                 outputColumnNames: _col0, _col1, _col2
>                 Statistics: Num rows: 1 Data size: 730 Basic stats: PARTIAL Column stats:
PARTIAL
>                 Reduce Output Operator
>                   sort order: 
>                   Statistics: Num rows: 1 Data size: 730 Basic stats: PARTIAL Column
stats: PARTIAL
>                   value expressions: _col0 (type: string), _col1 (type: string), _col2
(type: binary)
> {code}
> Instead it should create one branch for a join with one bloom filter.
>  
> The implementation for bloom filter requires getting a hash out of all the key columns
and converting it to a long and feeding it to bloom filter as input. This requires a new UDF
which does this. It will be called at both bloom filter generation and lookup phases.
> The min and max will stay independent as they are today for each columns.
> A vectorized implementation of such UDF is also required.



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

Mime
View raw message