Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
8b921a1
HIVE-26524: Use Calcite to remove sections of a query plan known neve…
kasakrisz Sep 1, 2022
5b19c25
fix code style issues
kasakrisz Sep 9, 2022
38c7c7b
fix javadocs
kasakrisz Sep 9, 2022
f055805
cast nulls to the types defined in the schema to handle grand total a…
kasakrisz Sep 13, 2022
479f11f
add type params like char(10)
kasakrisz Sep 13, 2022
6065079
handle withing group clause in CBO plan
kasakrisz Sep 15, 2022
1e145ba
handle null literal in empty plan
kasakrisz Sep 15, 2022
bb16a0d
handle values in HiveOpConverter
kasakrisz Sep 15, 2022
5eb640b
update q tests
kasakrisz Sep 15, 2022
4b38c04
refac: extract cast
kasakrisz Sep 19, 2022
2e2f713
revert HiveRelFieldTrimmer
kasakrisz Sep 19, 2022
4a78519
support Within group in HiveRelFieldTrimmer
kasakrisz Sep 19, 2022
ccf61f3
revert q.out change
kasakrisz Sep 19, 2022
76f51a1
fix HiveRewriteToDataSketchesRules percentile_disc
kasakrisz Sep 19, 2022
1686372
update q.out
kasakrisz Sep 20, 2022
1d6e7f3
cleanup
kasakrisz Sep 20, 2022
8c7be3d
fix grand total aggregate on empty values in HiveOpConverter
kasakrisz Sep 20, 2022
c24ccc4
add ColumnExpression Map to select op
kasakrisz Sep 20, 2022
1854845
cleanup
kasakrisz Sep 20, 2022
24e0aaf
handle full outer join on tables with not null constraints defined
kasakrisz Sep 21, 2022
3be92cb
Update ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/…
kasakrisz Sep 22, 2022
353830d
Update ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/transl…
kasakrisz Sep 22, 2022
ca18f9e
change formal parameter list indentation
kasakrisz Sep 22, 2022
f94172a
copy latest version of PruneEmptyRules from CALCITE-5294
kasakrisz Sep 22, 2022
94f876d
make convertFieldCollationsToASTNode private
kasakrisz Sep 22, 2022
0e17035
copy latest version of PruneEmptyRules from CALCITE-5294
kasakrisz Sep 22, 2022
cb3223b
track Calcite contributions
kasakrisz Sep 22, 2022
3ce2418
add UT
kasakrisz Sep 22, 2022
a4ac4a5
copy latest version of PruneEmptyRules from CALCITE-5294
kasakrisz Sep 23, 2022
2f041d5
format TestASTConverter
kasakrisz Sep 23, 2022
332b224
copy latest version of PruneEmptyRules from CALCITE-5294
kasakrisz Sep 26, 2022
8f3401a
remove unused import
kasakrisz Sep 26, 2022
322f188
always create new instance in HiveValues.copy
kasakrisz Sep 30, 2022
cc04fb1
fix links in javadocs
kasakrisz Sep 30, 2022
aec509a
support complex types in empty plan
kasakrisz Sep 30, 2022
cfe1297
remove redundant LOG msg
kasakrisz Sep 30, 2022
1f23baa
refactor HiveValuesVisitor
kasakrisz Oct 3, 2022
2cbcaa5
HiveRemoveEmptySingleRules: only Hive* ops are supported
kasakrisz Oct 3, 2022
dfd04cc
ASTConverter: throw exception when trying to convert non-empty HiveVa…
kasakrisz Oct 3, 2022
ee55eb7
TestASTConverter: remove redundant assert and add assertion for compl…
kasakrisz Oct 3, 2022
ad73b48
ASTConverter.emptyPlan: javadocs
kasakrisz Oct 3, 2022
c977888
HiveValuesVisitor: javadocs
kasakrisz Oct 3, 2022
0abb5a2
ASTConverter: fix javadocs
kasakrisz Oct 3, 2022
1579377
HiveRemoveEmptySingleRules: support semijoin
kasakrisz Oct 4, 2022
0f910f7
use isCBOExecuted() instead of query the config HIVE_CBO_ENABLED
kasakrisz Oct 5, 2022
4cb4e69
add CBO test for within group
kasakrisz Oct 5, 2022
673b4ea
transform Within group clause in ASTConverter
kasakrisz Oct 6, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ POSTHOOK: query: LOAD DATA LOCAL INPATH '../../data/files/smbbucket_1.txt' INTO
POSTHOOK: type: LOAD
#### A masked pattern was here ####
POSTHOOK: Output: default@src_a_data
Warning: Shuffle Join JOIN[12][tables = [$hdt$_0, $hdt$_1]] in Stage 'Stage-1:MAPRED' is a cross product
PREHOOK: query: SELECT /*+ MAPJOIN(src1, src2) */ *
FROM src_a_data src1
RIGHT OUTER JOIN src_a_data src2 ON (src1.key = src2.key AND src1.key < 10 AND src2.key > 10)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,15 @@ POSTHOOK: Input: default@blobstore_target
100
PREHOOK: query: INSERT OVERWRITE TABLE blobstore_target SELECT key FROM blobstore_source WHERE FALSE
PREHOOK: type: QUERY
PREHOOK: Input: _dummy_database@_dummy_table
PREHOOK: Input: default@blobstore_source
PREHOOK: Output: default@blobstore_target
POSTHOOK: query: INSERT OVERWRITE TABLE blobstore_target SELECT key FROM blobstore_source WHERE FALSE
POSTHOOK: type: QUERY
POSTHOOK: Input: _dummy_database@_dummy_table
POSTHOOK: Input: default@blobstore_source
POSTHOOK: Output: default@blobstore_target
POSTHOOK: Lineage: blobstore_target.key SIMPLE [(blobstore_source)blobstore_source.FieldSchema(name:key, type:int, comment:null), ]
POSTHOOK: Lineage: blobstore_target.key SIMPLE []
PREHOOK: query: SELECT COUNT(*) FROM blobstore_target
PREHOOK: type: QUERY
PREHOOK: Input: default@blobstore_target
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,15 @@ POSTHOOK: Input: default@hdfs_target
100
PREHOOK: query: INSERT OVERWRITE TABLE hdfs_target SELECT key FROM blobstore_source WHERE FALSE
PREHOOK: type: QUERY
PREHOOK: Input: _dummy_database@_dummy_table
PREHOOK: Input: default@blobstore_source
PREHOOK: Output: default@hdfs_target
POSTHOOK: query: INSERT OVERWRITE TABLE hdfs_target SELECT key FROM blobstore_source WHERE FALSE
POSTHOOK: type: QUERY
POSTHOOK: Input: _dummy_database@_dummy_table
POSTHOOK: Input: default@blobstore_source
POSTHOOK: Output: default@hdfs_target
POSTHOOK: Lineage: hdfs_target.key SIMPLE [(blobstore_source)blobstore_source.FieldSchema(name:key, type:int, comment:null), ]
POSTHOOK: Lineage: hdfs_target.key SIMPLE []
PREHOOK: query: SELECT COUNT(*) FROM hdfs_target
PREHOOK: type: QUERY
PREHOOK: Input: default@hdfs_target
Expand Down
10 changes: 10 additions & 0 deletions ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/Bug.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,14 @@ public final class Bug {
* Whether <a href="https://issues.apache.org/jira/browse/CALCITE-4704">CALCITE-4704</a> is fixed.
*/
public static final boolean CALCITE_4704_FIXED = false;

/**
* Whether <a href="https://issues.apache.org/jira/browse/CALCITE-5293">CALCITE-5293</a> is fixed.
*/
public static final boolean CALCITE_5293_FIXED = false;

/**
* Whether <a href="https://issues.apache.org/jira/browse/CALCITE-5294">CALCITE-5294</a> is fixed.
*/
public static final boolean CALCITE_5294_FIXED = false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveProject;
import org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveSqlFunction;
import org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveTableFunctionScan;
import org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveValues;
import org.apache.hadoop.hive.ql.optimizer.calcite.translator.ExprNodeConverter;
import org.apache.hadoop.hive.ql.optimizer.calcite.translator.SqlFunctionConverter;
import org.apache.hadoop.hive.ql.optimizer.calcite.translator.TypeConverter;
Expand Down Expand Up @@ -609,7 +610,7 @@ public static Pair<RelNode, RelNode> getTopLevelSelect(final RelNode rootRel) {
RelNode originalProjRel = null;

while (tmpRel != null) {
if (tmpRel instanceof HiveProject || tmpRel instanceof HiveTableFunctionScan) {
if (tmpRel instanceof HiveProject || tmpRel instanceof HiveTableFunctionScan || tmpRel instanceof HiveValues) {
originalProjRel = tmpRel;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.apache.calcite.plan.RelOptCluster;
import org.apache.calcite.plan.RelOptSchema;
import org.apache.calcite.plan.RelOptUtil;
import org.apache.calcite.rel.RelCollations;
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.core.CorrelationId;
import org.apache.calcite.rel.core.Join;
Expand Down Expand Up @@ -121,22 +120,6 @@ public RelBuilder filter(Iterable<? extends RexNode> predicates) {
return this;
}

/**
* Empty relationship can be expressed in many different ways, e.g.,
* filter(cond=false), empty LogicalValues(), etc. Calcite default implementation
* uses empty LogicalValues(); however, currently there is not an equivalent to
* this expression in Hive. Thus, we use limit 0, since Hive already includes
* optimizations that will do early pruning of the result tree when it is found,
* e.g., GlobalLimitOptimizer.
*/
@Override
public RelBuilder empty() {
final RelNode input = build();
final RelNode sort = HiveRelFactories.HIVE_SORT_FACTORY.createSort(
input, RelCollations.of(), null, literal(0));
return this.push(sort);
}

public static SqlFunction getFloorSqlFunction(TimeUnitRange flag) {
switch (flag) {
case YEAR:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.apache.calcite.rel.core.RelFactories.SortFactory;
import org.apache.calcite.rel.hint.RelHint;
import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.rex.RexLiteral;
import org.apache.calcite.rex.RexNode;
import org.apache.calcite.rex.RexUtil;
import org.apache.calcite.sql.SqlKind;
Expand All @@ -48,11 +49,13 @@
import org.apache.calcite.util.ImmutableBitSet;
import org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveAggregate;
import org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveAntiJoin;
import org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveValues;
import org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveExcept;
import org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveFilter;
import org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveIntersect;
import org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveJoin;
import org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveProject;
import org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveRelNode;
import org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveSemiJoin;
import org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveSortExchange;
import org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveSortLimit;
Expand All @@ -79,6 +82,9 @@ public class HiveRelFactories {
public static final RelFactories.SortExchangeFactory HIVE_SORT_EXCHANGE_FACTORY =
new HiveSortExchangeFactoryImpl();

public static final RelFactories.ValuesFactory HIVE_VALUES_FACTORY =
new HiveValuesFactoryImpl();

public static final AggregateFactory HIVE_AGGREGATE_FACTORY =
new HiveAggregateFactoryImpl();

Expand All @@ -94,6 +100,7 @@ public class HiveRelFactories {
HIVE_SEMI_JOIN_FACTORY,
HIVE_SORT_FACTORY,
HIVE_SORT_EXCHANGE_FACTORY,
HIVE_VALUES_FACTORY,
HIVE_AGGREGATE_FACTORY,
HIVE_SET_OP_FACTORY));

Expand Down Expand Up @@ -203,6 +210,14 @@ public RelNode createSortExchange(RelNode input, RelDistribution distribution, R
}
}

private static class HiveValuesFactoryImpl implements RelFactories.ValuesFactory {
@Override
public RelNode createValues(RelOptCluster cluster, RelDataType rowType, List<ImmutableList<RexLiteral>> tuples) {
return new HiveValues(
cluster, rowType, ImmutableList.copyOf(tuples), cluster.traitSetOf(HiveRelNode.CONVENTION));
}
}

private static class HiveAggregateFactoryImpl implements AggregateFactory {
@Override
public RelNode createAggregate(RelNode child, List<RelHint> hints,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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.reloperators;

import com.google.common.collect.ImmutableList;
import org.apache.calcite.plan.RelOptCluster;
import org.apache.calcite.plan.RelTraitSet;
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.core.Values;
import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.rex.RexLiteral;

import java.util.List;

/**
* Subclass of {@link org.apache.calcite.rel.core.Values}.
* Specialized to Hive engine.
*/
public class HiveValues extends Values {

public HiveValues(RelOptCluster cluster, RelDataType rowType, ImmutableList<ImmutableList<RexLiteral>> tuples,
RelTraitSet traits) {
super(cluster, rowType, tuples, traits);
}

@Override
public RelNode copy(RelTraitSet traitSet, List<RelNode> inputs) {
return new HiveValues(getCluster(), getRowType(), tuples, getTraitSet());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.apache.calcite.plan.RelOptTable;
import org.apache.calcite.plan.RelOptUtil;
import org.apache.calcite.rel.RelCollation;
import org.apache.calcite.rel.RelCollations;
import org.apache.calcite.rel.RelDistribution;
import org.apache.calcite.rel.RelFieldCollation;
import org.apache.calcite.rel.RelNode;
Expand Down Expand Up @@ -614,6 +615,7 @@ public TrimResult trimFields(Aggregate aggregate, ImmutableBitSet fieldsUsed, Se
if (aggCall.filterArg >= 0) {
aggCallFieldsUsedBuilder.set(aggCall.filterArg);
}
aggCallFieldsUsedBuilder.addAll(RelCollations.ordinals(aggCall.collation));
}

// transform if group by contain constant keys
Expand Down Expand Up @@ -717,9 +719,12 @@ public TrimResult trimFields(Aggregate aggregate, ImmutableBitSet fieldsUsed, Se
final RexNode filterArg = aggCall.filterArg < 0 ? null
: relBuilder.field(Mappings.apply(inputMapping, aggCall.filterArg));
RelBuilder.AggCall newAggCall =
relBuilder.aggregateCall(aggCall.getAggregation(),
aggCall.isDistinct(), aggCall.isApproximate(),
filterArg, aggCall.name, args);
relBuilder.aggregateCall(aggCall.getAggregation(), args)
.distinct(aggCall.isDistinct())
.filter(filterArg)
.approximate(aggCall.isApproximate())
.sort(relBuilder.fields(aggCall.collation))
.as(aggCall.name);
Comment thread
kasakrisz marked this conversation as resolved.
mapping.set(j, updatedGroupCount + newAggCallList.size());
newAggCallList.add(newAggCall);
}
Expand Down
Loading