You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lens.apache.org by am...@apache.org on 2014/11/26 12:08:00 UTC
incubator-lens git commit: LENS-61 : Fixes errors in JDBC driver for
querying non aggregated columns ( Sushil Mohanty via amareshwari)
Repository: incubator-lens
Updated Branches:
refs/heads/master 28a1b37be -> f942e4bda
LENS-61 : Fixes errors in JDBC driver for querying non aggregated columns ( Sushil Mohanty via amareshwari)
Project: http://git-wip-us.apache.org/repos/asf/incubator-lens/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-lens/commit/f942e4bd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-lens/tree/f942e4bd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-lens/diff/f942e4bd
Branch: refs/heads/master
Commit: f942e4bda405eec59214982836696aadfda79661
Parents: 28a1b37
Author: Amareshwari Sriramdasu <am...@inmobi.com>
Authored: Wed Nov 26 16:37:48 2014 +0530
Committer: Amareshwari Sriramdasu <am...@inmobi.com>
Committed: Wed Nov 26 16:37:48 2014 +0530
----------------------------------------------------------------------
.../lens/driver/jdbc/ColumnarSQLRewriter.java | 10 ++++--
.../driver/jdbc/TestColumnarSQLRewriter.java | 36 ++++++++++++++++++++
2 files changed, 44 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/f942e4bd/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 bfc9a35..20031db 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
@@ -643,7 +643,7 @@ public class ColumnarSQLRewriter implements QueryRewriter {
// Construct the final fact in-line query with keys,
// measures and individual sub queries built.
- if (whereTree == null || joinTree == null || allSubQueries.length() == 0) {
+ if (whereTree == null || joinTree == null || allSubQueries.length() == 0 || aggColumn.isEmpty()) {
LOG.info("@@@Query not eligible for inner subquery rewrite");
// construct query without fact sub query
constructQuery(selectTree, fromTree, whereTree, groupByTree, havingTree, orderByTree, limit, joinTree);
@@ -674,6 +674,7 @@ public class ColumnarSQLRewriter implements QueryRewriter {
for (Map.Entry<String, String> entry : mapAggTabAlias.entrySet()) {
selectTree = selectTree.replace(entry.getKey(), entry.getValue());
+
if (orderByTree != null) {
orderByTree = orderByTree.replace(entry.getKey(), entry.getValue());
}
@@ -681,6 +682,11 @@ public class ColumnarSQLRewriter implements QueryRewriter {
havingTree = havingTree.replace(entry.getKey(), entry.getValue());
}
}
+ //for subquery with count function should be replaced with sum in outer query
+ if (selectTree.toLowerCase().matches("(.*)count\\((.*)")) {
+ System.out.println(selectTree);
+ selectTree = selectTree.replaceAll("count\\(", "sum\\(");
+ }
// construct query with fact sub query
constructQuery(selectTree, fromTree, whereTree, groupByTree, havingTree, orderByTree, limit, joinTree);
@@ -821,7 +827,7 @@ public class ColumnarSQLRewriter implements QueryRewriter {
}
return queryReplacedUdf;
}
-
+
// Replace Lens database names with storage's proper DB and table name based
// on table properties.
/**
http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/f942e4bd/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 07f4050..6823ada 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
@@ -560,6 +560,42 @@ public class TestColumnarSQLRewriter {
compareQueries(expected, actual);
}
+
+@Test
+ public void testNoAggCol() throws ParseException, SemanticException, LensException {
+
+ String query = "SELECT distinct ( location_dim . id ) FROM location_dim " +
+ "location_dim join time_dim time_dim on location_dim.time_id = time_dim.id " +
+ "WHERE ( time_dim . full_date ) between '2013-01-01 00:00:00' and '2013-01-04 00:00:00' LIMIT 10 ";
+
+ SessionState.start(conf);
+
+ String actual = qtest.rewrite(query, conf);
+ String expected = "select distinct ( location_dim . id ) from location_dim location_dim " +
+ "inner join time_dim time_dim on (( location_dim . time_id ) = ( time_dim . id )) " +
+ "where ( time_dim . full_date ) between '2013-01-01 00:00:00' and '2013-01-04 00:00:00' limit 10";
+ compareQueries(expected, actual);
+
+ }
+
+@Test
+public void testCountReplace() throws ParseException, SemanticException, LensException {
+
+ String query = "SELECT count(location_dim.name) FROM location_dim " +
+ "location_dim join time_dim time_dim on location_dim.time_id = time_dim.id " +
+ "WHERE ( time_dim . full_date ) between '2013-01-01 00:00:00' and '2013-01-04 00:00:00' LIMIT 10 ";
+
+ SessionState.start(conf);
+
+ String actual = qtest.rewrite(query, conf);
+ String expected = "select sum(count_location_dim_name) from (select location_dim.time_id,count(( location_dim . name )) " +
+ "as count_location_dim_name from location_dim location_dim where location_dim.time_id in " +
+ "( select time_dim.id from time_dim where ( time_dim . full_date ) between " +
+ "'2013-01-01 00:00:00' and '2013-01-04 00:00:00' ) group by location_dim.time_id) " +
+ "location_dim inner join time_dim time_dim on (( location_dim . time_id ) = ( time_dim . id )) " +
+ "where ( time_dim . full_date ) between '2013-01-01 00:00:00' and '2013-01-04 00:00:00' limit 10";
+ compareQueries(expected, actual);
+}
/**
* Test replace db name.