diff --git a/fe/src/main/java/com/cloudera/impala/planner/DataSourceScanNode.java b/fe/src/main/java/com/cloudera/impala/planner/DataSourceScanNode.java index aee26b879..14f751a48 100644 --- a/fe/src/main/java/com/cloudera/impala/planner/DataSourceScanNode.java +++ b/fe/src/main/java/com/cloudera/impala/planner/DataSourceScanNode.java @@ -90,6 +90,7 @@ public class DataSourceScanNode extends ScanNode { @Override public void init(Analyzer analyzer) throws InternalException { assignConjuncts(analyzer); + analyzer.enforceSlotEquivalences(tupleIds_.get(0), conjuncts_); prepareDataSource(); computeStats(analyzer); diff --git a/testdata/bin/create-data-source-table.sql b/testdata/bin/create-data-source-table.sql index d5ecc3ebf..f151d0373 100644 --- a/testdata/bin/create-data-source-table.sql +++ b/testdata/bin/create-data-source-table.sql @@ -24,6 +24,7 @@ API_VERSION 'V1'; DROP TABLE IF EXISTS alltypes_datasource; CREATE TABLE alltypes_datasource ( + id INT, bool_col BOOLEAN, tinyint_col TINYINT, smallint_col SMALLINT, diff --git a/testdata/workloads/functional-planner/queries/PlannerTest/data-source-tables.test b/testdata/workloads/functional-planner/queries/PlannerTest/data-source-tables.test index 63a89f4f2..a14ab0406 100644 --- a/testdata/workloads/functional-planner/queries/PlannerTest/data-source-tables.test +++ b/testdata/workloads/functional-planner/queries/PlannerTest/data-source-tables.test @@ -38,3 +38,24 @@ where int_col < 10 and data source predicates: int_col < 10, bool_col != FALSE predicates: double_col > 5.0, string_col IN ('Foo', 'Bar') ==== +# Tests that all predicates from the On-clause are applied (IMPALA-805) +# and that slot equivalences are enforced at lowest possible plan node +# for tables produced by a data source. +select 1 from functional.alltypes_datasource a +inner join functional.alltypes_datasource b +# equivalence class +on a.id = b.id and a.id = b.int_col and a.id = b.bigint_col +and a.tinyint_col = b.id and a.smallint_col = b.id +and a.int_col = b.id and a.bigint_col = b.id +# redundant predicates to test minimal spanning tree of equivalent slots +where a.tinyint_col = a.smallint_col and a.int_col = a.bigint_col +---- PLAN +02:HASH JOIN [INNER JOIN] +| hash predicates: a.id = b.id +| +|--01:SCAN DATA SOURCE [functional.alltypes_datasource b] +|--predicates: b.id = b.int_col, b.id = b.bigint_col +| +00:SCAN DATA SOURCE [functional.alltypes_datasource a] +predicates: a.tinyint_col = a.smallint_col, a.int_col = a.bigint_col, a.id = a.tinyint_col, a.id = a.int_col +==== diff --git a/testdata/workloads/functional-query/queries/QueryTest/data-source-tables.test b/testdata/workloads/functional-query/queries/QueryTest/data-source-tables.test index 71fcac5ac..849d6385c 100644 --- a/testdata/workloads/functional-query/queries/QueryTest/data-source-tables.test +++ b/testdata/workloads/functional-query/queries/QueryTest/data-source-tables.test @@ -3,19 +3,18 @@ # Gets all types including a row with a NULL value. The predicate pushed to # the data source is not actually used, but the second predicate is # evaluated by Impala. -select smallint_col, tinyint_col, int_col, bigint_col, - float_col, bool_col, double_col, string_col, timestamp_col +select * from alltypes_datasource where float_col != 0 and int_col >= 1990 limit 5 ---- RESULTS -90,0,1990,19900,2189,true,1990,'NULL',1970-01-01 00:00:01.990000000 -91,1,1991,19910,2190.10009765625,false,1991,'1991',1970-01-01 00:00:01.991000000 -92,2,1992,19920,2191.199951171875,true,1992,'1992',1970-01-01 00:00:01.992000000 -93,3,1993,19930,2192.300048828125,false,1993,'1993',1970-01-01 00:00:01.993000000 -94,4,1994,19940,2193.39990234375,true,1994,'1994',1970-01-01 00:00:01.994000000 +1990,true,0,90,1990,19900,2189,1990,1970-01-01 00:00:01.990000000,'NULL' +1991,false,1,91,1991,19910,2190.10009765625,1991,1970-01-01 00:00:01.991000000,'1991' +1992,true,2,92,1992,19920,2191.199951171875,1992,1970-01-01 00:00:01.992000000,'1992' +1993,false,3,93,1993,19930,2192.300048828125,1993,1970-01-01 00:00:01.993000000,'1993' +1994,true,4,94,1994,19940,2193.39990234375,1994,1970-01-01 00:00:01.994000000,'1994' ---- TYPES -SMALLINT, TINYINT, INT, BIGINT, FLOAT, BOOLEAN, DOUBLE, STRING, TIMESTAMP +INT, BOOLEAN, TINYINT, SMALLINT, INT, BIGINT, FLOAT, DOUBLE, TIMESTAMP, STRING ==== ---- QUERY # Project a subset of the columns