Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -30,7 +30,6 @@
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.TreeSet;

import javax.annotation.Nonnull;

Expand All @@ -57,7 +56,6 @@
import org.apache.calcite.rel.core.JoinRelType;
import org.apache.calcite.rel.core.Project;
import org.apache.calcite.rel.core.Sort;
import org.apache.calcite.rel.core.Values;
import org.apache.calcite.rel.logical.LogicalCorrelate;
import org.apache.calcite.rel.metadata.RelMdUtil;
import org.apache.calcite.rel.metadata.RelMetadataQuery;
Expand Down Expand Up @@ -112,7 +110,6 @@
import org.slf4j.LoggerFactory;

import com.google.common.base.Preconditions;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
Expand Down Expand Up @@ -461,16 +458,6 @@ public Frame decorrelateRel(Sort rel) {
frame.corDefOutputs);
}

/**
* Rewrites a {@link Values}.
*
* @param rel Values to be rewritten
*/
public Frame decorrelateRel(Values rel) {
// There are no inputs, so rel does not need to be changed.
return null;
}

/**
* Rewrites a {@link Aggregate}.
*
Expand Down
22 changes: 22 additions & 0 deletions ql/src/test/queries/clientpositive/empty_result_correlate2.q
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
set hive.support.concurrency=true;
set hive.txn.manager=org.apache.hadoop.hive.ql.lockmgr.DbTxnManager;

-- To create a HiveValues operator before decorrelation automatic query rewrite with
-- materialized views is used.
-- All tables must be transactional to trigger automatic query rewrite.
create table mv_source (any_col int) stored as orc TBLPROPERTIES ('transactional'='true');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure we should be adding new tests with ACID table format, would it work with iceberg as well?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bug should occur when decorrelating any plan with a Values node. How about adding a unit test in a new class HiveRelDecorrelatorTest instead?

create table t1 (a int, b int) stored as orc TBLPROPERTIES ('transactional'='true');
create table t2 (a int, b int) stored as orc TBLPROPERTIES ('transactional'='true');

-- At least one materialized view must exist.
create materialized view any_mv as
select any_col from mv_source where any_col > 20;

-- Automatic query rewrite traverses the plan and recreates the HiveFilter using RelBuilder.
-- If the condition is always false, it replaces the filter with HiveValues.
explain cbo
select * from t1 where 1 = 2
union
select * from t1
where exists (select a from t2 where t1.a > 10)
;
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
PREHOOK: query: create table mv_source (any_col int) stored as orc TBLPROPERTIES ('transactional'='true')
PREHOOK: type: CREATETABLE
PREHOOK: Output: database:default
PREHOOK: Output: default@mv_source
POSTHOOK: query: create table mv_source (any_col int) stored as orc TBLPROPERTIES ('transactional'='true')
POSTHOOK: type: CREATETABLE
POSTHOOK: Output: database:default
POSTHOOK: Output: default@mv_source
PREHOOK: query: create table t1 (a int, b int) stored as orc TBLPROPERTIES ('transactional'='true')
PREHOOK: type: CREATETABLE
PREHOOK: Output: database:default
PREHOOK: Output: default@t1
POSTHOOK: query: create table t1 (a int, b int) stored as orc TBLPROPERTIES ('transactional'='true')
POSTHOOK: type: CREATETABLE
POSTHOOK: Output: database:default
POSTHOOK: Output: default@t1
PREHOOK: query: create table t2 (a int, b int) stored as orc TBLPROPERTIES ('transactional'='true')
PREHOOK: type: CREATETABLE
PREHOOK: Output: database:default
PREHOOK: Output: default@t2
POSTHOOK: query: create table t2 (a int, b int) stored as orc TBLPROPERTIES ('transactional'='true')
POSTHOOK: type: CREATETABLE
POSTHOOK: Output: database:default
POSTHOOK: Output: default@t2
PREHOOK: query: create materialized view any_mv as
select any_col from mv_source where any_col > 20
PREHOOK: type: CREATE_MATERIALIZED_VIEW
PREHOOK: Input: default@mv_source
PREHOOK: Output: database:default
PREHOOK: Output: default@any_mv
POSTHOOK: query: create materialized view any_mv as
select any_col from mv_source where any_col > 20
POSTHOOK: type: CREATE_MATERIALIZED_VIEW
POSTHOOK: Input: default@mv_source
POSTHOOK: Output: database:default
POSTHOOK: Output: default@any_mv
POSTHOOK: Lineage: any_mv.any_col SIMPLE [(mv_source)mv_source.FieldSchema(name:any_col, type:int, comment:null), ]
Warning: Shuffle Join MERGEJOIN[38][tables = [$hdt$_1, $hdt$_2]] in Stage 'Reducer 5' is a cross product
PREHOOK: query: explain cbo
select * from t1 where 1 = 2
union
select * from t1
where exists (select a from t2 where t1.a > 10)
PREHOOK: type: QUERY
PREHOOK: Input: default@t1
PREHOOK: Input: default@t2
#### A masked pattern was here ####
POSTHOOK: query: explain cbo
select * from t1 where 1 = 2
union
select * from t1
where exists (select a from t2 where t1.a > 10)
POSTHOOK: type: QUERY
POSTHOOK: Input: default@t1
POSTHOOK: Input: default@t2
#### A masked pattern was here ####
CBO PLAN:
HiveProject(a=[$0], b=[$1])
HiveAggregate(group=[{0, 1}])
HiveSemiJoin(condition=[=($3, $2)], joinType=[semi])
HiveProject(a=[$0], b=[$1], $f6=[>($0, 10)])
HiveFilter(condition=[IS NOT NULL($0)])
HiveTableScan(table=[[default, t1]], table:alias=[t1])
HiveProject($f6=[$1])
HiveJoin(condition=[true], joinType=[inner], algorithm=[none], cost=[not available])
HiveProject(DUMMY=[0])
HiveTableScan(table=[[default, t2]], table:alias=[t2])
HiveProject($f6=[$0])
HiveAggregate(group=[{0}])
HiveProject($f6=[CAST(IS NOT NULL($0)):BOOLEAN])
HiveFilter(condition=[>($0, 10)])
HiveTableScan(table=[[default, t1]], table:alias=[t1])

Loading