You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lens.apache.org by pr...@apache.org on 2015/10/27 14:51:24 UTC
lens git commit: LENS-847: Columnar JDBC Rewriter in incorrectly
pushing filter against wrong alias when fact columns map to a single
dimension
Repository: lens
Updated Branches:
refs/heads/master e274c2dfd -> ccf71332f
LENS-847: Columnar JDBC Rewriter in incorrectly pushing filter against wrong alias when fact columns map to a single dimension
Project: http://git-wip-us.apache.org/repos/asf/lens/repo
Commit: http://git-wip-us.apache.org/repos/asf/lens/commit/ccf71332
Tree: http://git-wip-us.apache.org/repos/asf/lens/tree/ccf71332
Diff: http://git-wip-us.apache.org/repos/asf/lens/diff/ccf71332
Branch: refs/heads/master
Commit: ccf71332f90f7dd36eac0a84c3b32f9ff76d2812
Parents: e274c2d
Author: Srikanth Sundarrajan <sr...@hotmail.com>
Authored: Tue Oct 27 19:20:53 2015 +0530
Committer: Rajat Khandelwal <ra...@gmail.com>
Committed: Tue Oct 27 19:20:53 2015 +0530
----------------------------------------------------------------------
.../lens/driver/jdbc/ColumnarSQLRewriter.java | 11 ++++++++---
.../driver/jdbc/TestColumnarSQLRewriter.java | 20 ++++++++++++++++++++
2 files changed, 28 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lens/blob/ccf71332/lens-driver-jdbc/src/main/java/org/apache/lens/driver/jdbc/ColumnarSQLRewriter.java
----------------------------------------------------------------------
diff --git a/lens-driver-jdbc/src/main/java/org/apache/lens/driver/jdbc/ColumnarSQLRewriter.java b/lens-driver-jdbc/src/main/java/org/apache/lens/driver/jdbc/ColumnarSQLRewriter.java
index ccb2b7f..825a039 100644
--- a/lens-driver-jdbc/src/main/java/org/apache/lens/driver/jdbc/ColumnarSQLRewriter.java
+++ b/lens-driver-jdbc/src/main/java/org/apache/lens/driver/jdbc/ColumnarSQLRewriter.java
@@ -673,7 +673,10 @@ public class ColumnarSQLRewriter implements QueryRewriter {
.replaceAll("[(,)]", "");
String dimJoinKeys = HQLParser.getString(right).replaceAll("\\s+", "")
.replaceAll("[(,)]", "");
- String dimTableName = dimJoinKeys.substring(0, dimJoinKeys.indexOf("__"));
+ int dimTableDelimIndex = dimJoinKeys.indexOf("__");
+ String dimTableName = dimJoinKeys.substring(0, dimTableDelimIndex);
+ String dimAlias = dimJoinKeys.
+ substring(dimTableDelimIndex + 3, dimJoinKeys.indexOf('.')).trim();
// Construct part of subquery by referring join condition
// fact.fact_key = dim_table.dim_key
@@ -691,14 +694,16 @@ public class ColumnarSQLRewriter implements QueryRewriter {
// Check the occurrence of dimension table in the filter list and
// combine all filters of same dimension table with and .
// eg. "dim_table.key1 = 'abc' and dim_table.key2 = 'xyz'"
- if (setAllFilters.toString().matches("(.*)" + dimTableName + "(.*)")) {
+ if (setAllFilters.toString().replaceAll("\\s+", "")
+ .matches("(.*)" + dimAlias + "(.*)")) {
factFilters.delete(0, factFilters.length());
// All filters in where clause
for (int i = 0; i < setAllFilters.toArray().length; i++) {
- if (setAllFilters.toArray()[i].toString().matches("(.*)" + dimTableName + ("(.*)"))) {
+ if (setAllFilters.toArray()[i].toString().replaceAll("\\s+", "")
+ .matches("(.*)" + dimAlias + ("(.*)"))) {
String filters2 = setAllFilters.toArray()[i].toString();
filters2 = filters2.replaceAll(
getTableOrAlias(filters2, "alias"),
http://git-wip-us.apache.org/repos/asf/lens/blob/ccf71332/lens-driver-jdbc/src/test/java/org/apache/lens/driver/jdbc/TestColumnarSQLRewriter.java
----------------------------------------------------------------------
diff --git a/lens-driver-jdbc/src/test/java/org/apache/lens/driver/jdbc/TestColumnarSQLRewriter.java b/lens-driver-jdbc/src/test/java/org/apache/lens/driver/jdbc/TestColumnarSQLRewriter.java
index d4d812f..3a00510 100644
--- a/lens-driver-jdbc/src/test/java/org/apache/lens/driver/jdbc/TestColumnarSQLRewriter.java
+++ b/lens-driver-jdbc/src/test/java/org/apache/lens/driver/jdbc/TestColumnarSQLRewriter.java
@@ -142,6 +142,7 @@ public class TestColumnarSQLRewriter {
factColumns.add(new FieldSchema("item_key", "int", ""));
factColumns.add(new FieldSchema("branch_key", "int", ""));
factColumns.add(new FieldSchema("location_key", "int", ""));
+ factColumns.add(new FieldSchema("other_location_key", "int", ""));
factColumns.add(new FieldSchema("dollars_sold", "double", ""));
factColumns.add(new FieldSchema("units_sold", "int", ""));
@@ -233,6 +234,25 @@ public class TestColumnarSQLRewriter {
}
+ @Test
+ public void testPushDownFilterWithCommonDim() throws LensException {
+ String query = "select fact.time_key, time_dim.day_of_week, location_dim_a.location_name, "
+ + "other_location_dim.location_name, sum(fact.dollars_sold) from sales_fact fact inner join "
+ + "time_dim time_dim on fact.time_key = time_dim.time_key inner join location_dim location_dim_a "
+ + "on fact.location_key = location_dim_a.location_key inner join location_dim other_location_dim "
+ + "on fact.other_location_key = other_location_dim.location_key where time_dim.time_key "
+ + "between '2013-01-01' and '2013-01-31' and location_dim_a.location_key = 'some-loc' "
+ + "group by fact.time_key, location_dim_a.location_key, other_location_dim.location_key";
+
+ SessionState.start(hconf);
+ qtest.rewrite(query, conf, hconf);
+ String expected = "sales_fact___fact.time_key in ( select time_dim .time_key from time_dim "
+ + "where ( time_dim. time_key ) between '2013-01-01' and '2013-01-31' ) and "
+ + "sales_fact___fact.location_key in ( select location_dim .location_key from "
+ + "location_dim where (( location_dim. location_key ) = 'some-loc' ) ) and ";
+ Assert.assertEquals(qtest.allSubQueries.toString().trim(), expected.trim());
+ }
+
/**
* Test join cond.
*