Repository: lens
Updated Branches:
  refs/heads/master a6d6294d8 -> a079ad3f3


http://git-wip-us.apache.org/repos/asf/lens/blob/a079ad3f/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 db09a4b..6b5fb6a 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
@@ -26,10 +26,12 @@ import java.net.URLClassLoader;
 import java.util.*;
 
 import org.apache.lens.cube.parse.HQLParser;
+import org.apache.lens.cube.parse.TestQuery;
 import org.apache.lens.server.api.LensConfConstants;
 import org.apache.lens.server.api.error.LensException;
 
 import org.apache.commons.lang3.StringUtils;
+
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hive.conf.HiveConf;
 import org.apache.hadoop.hive.metastore.api.Database;
@@ -90,28 +92,8 @@ public class TestColumnarSQLRewriter {
    * @param expected the expected
    * @param actual   the actual
    */
-  private void compareQueries(String expected, String actual) {
-    if (expected == null && actual == null) {
-      return;
-    } else if (expected == null) {
-      Assert.fail();
-    } else if (actual == null) {
-      Assert.fail("Rewritten query is null");
-    }
-    String expectedTrimmed = expected.replaceAll("\\W", "");
-    String actualTrimmed = actual.replaceAll("\\W", "");
-
-    if (!expectedTrimmed.equalsIgnoreCase(actualTrimmed)) {
-      String method = null;
-      for (StackTraceElement trace : Thread.currentThread().getStackTrace()) {
-        if (trace.getMethodName().startsWith("test")) {
-          method = trace.getMethodName() + ":" + trace.getLineNumber();
-        }
-      }
-
-      System.err.println("__FAILED__ " + method + "\n\tExpected: " + expected 
+ "\n\t---------\n\tActual: " + actual);
-    }
-    Assert.assertTrue(expectedTrimmed.equalsIgnoreCase(actualTrimmed));
+  private void compareQueries(String actual, String expected) {
+    assertEquals(new TestQuery(actual), new TestQuery(expected));
   }
 
   /*
@@ -154,7 +136,7 @@ public class TestColumnarSQLRewriter {
   public void setup() throws Exception {
     qtest.init(conf);
 
-    List<FieldSchema> factColumns = new ArrayList<FieldSchema>();
+    List<FieldSchema> factColumns = new ArrayList<>();
     factColumns.add(new FieldSchema("item_key", "int", ""));
     factColumns.add(new FieldSchema("branch_key", "int", ""));
     factColumns.add(new FieldSchema("location_key", "int", ""));
@@ -270,9 +252,9 @@ public class TestColumnarSQLRewriter {
     SessionState.start(hconf);
 
     String rwq = qtest.rewrite(query, conf, hconf);
-    String expected = "inner join (select day_of_week, day, time_key from 
time_dim) time_dim___time_dim "
+    String expected = "inner join (select time_key, day_of_week, day from 
time_dim) time_dim___time_dim "
       + "on (( sales_fact___fact . time_key ) = "
-      + "( time_dim___time_dim . time_key ))  inner join (select 
location_name, location_key from location_dim) "
+      + "( time_dim___time_dim . time_key ))  inner join (select location_key, 
location_name from location_dim) "
       + "location_dim___location_dim on "
       + "((( sales_fact___fact . location_key ) = ( 
location_dim___location_dim . location_key )) "
       + "and (( location_dim___location_dim . location_name ) =  'test123' ))";
@@ -437,12 +419,12 @@ public class TestColumnarSQLRewriter {
         + "format(avg(( sales_fact___fact . dollars_sold )),  
'##################.###' ), "
         + "min(( sales_fact___fact . dollars_sold )), max(( sales_fact___fact 
. dollars_sold )) "
         + "from sales_fact sales_fact___fact  inner join "
-        + "(select day_of_week, day, time_key from time_dim) 
time_dim___time_dim on "
+        + "(select time_key, day_of_week, day from time_dim) 
time_dim___time_dim on "
         + "(( sales_fact___fact . time_key ) = ( time_dim___time_dim . 
time_key ))  inner join "
-        + "(select location_name, location_key from location_dim) 
location_dim___location_dim "
+        + "(select location_key, location_name from location_dim) 
location_dim___location_dim "
         + "on (( sales_fact___fact . location_key ) = "
-        + "( location_dim___location_dim . location_key ))  inner join (select 
item_name, "
-        + "item_key from item_dim) item_dim___item_dim "
+        + "( location_dim___location_dim . location_key ))  inner join (select 
item_key, "
+        + "item_name from item_dim) item_dim___item_dim "
         + "on ((( sales_fact___fact . item_key ) = ( item_dim___item_dim . 
item_key )) and "
         + "(( location_dim___location_dim . location_name ) =  'test123' ))  
where "
         + "(( time_dim___time_dim . time_key ) between date_add( '2013-01-01' 
, interval 1  day) "
@@ -491,9 +473,9 @@ public class TestColumnarSQLRewriter {
     String expected = "select ( sales_fact___fact . time_key ), ( 
time_dim___time_dim . day_of_week ), "
         + "( time_dim___time_dim . day ),  case  when (sum(( sales_fact___fact 
. dollars_sold )) =  0 ) "
         + "then  0.0  else sum(( sales_fact___fact . dollars_sold )) end  
dollars_sold  from sales_fact s"
-        + "ales_fact___fact  inner join (select day_of_week, day, time_key 
from time_dim) "
+        + "ales_fact___fact  inner join (select time_key, day_of_week, day 
from time_dim) "
         + "time_dim___time_dim on (( sales_fact___fact . time_key ) "
-        + "= ( time_dim___time_dim . time_key ))  inner join (select 
location_name, location_key from location_dim) "
+        + "= ( time_dim___time_dim . time_key ))  inner join (select 
location_key, location_name from location_dim) "
         + "location_dim___location_dim on "
         + "((( sales_fact___fact . location_key ) = ( 
location_dim___location_dim . location_key )) and "
         + "(( location_dim___location_dim . location_name ) =  'test123' ))  
where ( time_dim___time_dim . time_key ) "
@@ -502,10 +484,10 @@ public class TestColumnarSQLRewriter {
         + "asc  union all select ( sales_fact___fact . time_key ), ( 
time_dim___time_dim . day_of_week ), "
         + "( time_dim___time_dim . day ),  case  when (sum(( sales_fact___fact 
. dollars_sold )) =  0 ) then  0.0  "
         + "else sum(( sales_fact___fact . dollars_sold )) end  dollars_sold  
from sales_fact sales_fact___fact  "
-        + "inner join (select day_of_week, day, time_key from time_dim) 
time_dim___time_dim "
+        + "inner join (select time_key, day_of_week, day from time_dim) 
time_dim___time_dim "
         + "on (( sales_fact___fact . time_key ) = "
-        + "( time_dim___time_dim . time_key ))  inner join (select 
location_name, "
-        + "location_key from location_dim) location_dim___location_dim on "
+        + "( time_dim___time_dim . time_key ))  inner join (select 
location_key, "
+        + "location_name from location_dim) location_dim___location_dim on "
         + "((( sales_fact___fact . location_key ) = ( 
location_dim___location_dim . location_key )) and "
         + "(( location_dim___location_dim . location_name ) =  'test123' ))  
where ( time_dim___time_dim . time_key ) "
         + "between  '2013-02-01'  and  '2013-02-05'  group by ( 
sales_fact___fact . time_key ), "
@@ -513,9 +495,9 @@ public class TestColumnarSQLRewriter {
         + "select ( sales_fact___fact . time_key ), ( time_dim___time_dim . 
day_of_week ), "
         + "( time_dim___time_dim . day ),  case  when (sum(( sales_fact___fact 
. dollars_sold )) =  0 ) then  0.0  "
         + "else sum(( sales_fact___fact . dollars_sold )) end  dollars_sold  
from sales_fact sales_fact___fact  "
-        + "inner join (select day_of_week, day, time_key from time_dim) "
+        + "inner join (select time_key, day_of_week, day from time_dim) "
         + "time_dim___time_dim on (( sales_fact___fact . time_key ) = "
-        + "( time_dim___time_dim . time_key ))  inner join (select 
location_name, location_key from location_dim) "
+        + "( time_dim___time_dim . time_key ))  inner join (select 
location_key, location_name from location_dim) "
         + "location_dim___location_dim on "
         + "((( sales_fact___fact . location_key ) = ( 
location_dim___location_dim . location_key )) and "
         + "(( location_dim___location_dim . location_name ) =  'test123' ))  
where "
@@ -567,13 +549,13 @@ public class TestColumnarSQLRewriter {
         + "dollars_sold , round(sum(( sales_fact___fact . units_sold )),  2 ), 
"
         + "avg(( sales_fact___fact . dollars_sold )), "
         + "min(( sales_fact___fact . dollars_sold )), max(( sales_fact___fact 
. dollars_sold )),  location_name , "
-        + " from sales_fact sales_fact___fact  inner join (select day_of_week, 
day, time_key "
+        + " from sales_fact sales_fact___fact  inner join (select time_key, 
day_of_week, day"
         + "from time_dim) time_dim___time_dim "
         + "on (( sales_fact___fact . time_key ) = ( time_dim___time_dim . 
time_key ))  "
-        + "inner join (select location_name, location_key from location_dim) "
+        + "inner join (select location_key, location_name from location_dim) "
         + "location_dim___location_dim on (( sales_fact___fact . location_key 
) = "
-        + "( location_dim___location_dim . location_key ))  inner join (select 
item_name, "
-        + "item_key from item_dim) item_dim___item_dim on "
+        + "( location_dim___location_dim . location_key ))  inner join (select 
item_key, "
+        + "item_name from item_dim) item_dim___item_dim on "
         + "((( sales_fact___fact . item_key ) = ( item_dim___item_dim . 
item_key )) and "
         + "(( location_dim___location_dim . location_name ) =  'test123' ))  
where (( time_dim___time_dim . time_key ) "
         + "between  '2013-01-01'  and  '2013-01-31'  and (( 
item_dim___item_dim . item_name ) =  'item_1' )) "
@@ -606,8 +588,8 @@ public class TestColumnarSQLRewriter {
         + "( time_dim___time_dim . day ), ( item_dim___item_dim . item_key ), 
sum(alias1) dollars_sold , "
         + "round(sum(alias2),  2 ), avg(alias6) avg_dollars_sold, min(alias4), 
max(alias5) max_dollars_sold,  "
         + "location_name , (avg(alias6) /  1.0 ) "
-        + "from  (select sales_fact___fact.time_key, 
sales_fact___fact.dollars_sold, sales_fact___fact.location_key, "
-        + "sales_fact___fact.item_key,sum( case  when (( sales_fact___fact . 
dollars_sold ) =  0 ) then  0.0  end ) "
+        + "from  (select sales_fact___fact.time_key, 
sales_fact___fact.location_key, sales_fact___fact.item_key,"
+        + "sales_fact___fact.dollars_sold, sum( case  when (( 
sales_fact___fact . dollars_sold ) =  0 ) then 0.0  end )"
         + "as alias1, sum(( sales_fact___fact . units_sold )) as alias2, avg(( 
sales_fact___fact . dollars_sold )) "
         + "as alias3, min(( sales_fact___fact . dollars_sold )) as alias4, "
         + "max(( sales_fact___fact . dollars_sold )) as alias5, "
@@ -617,14 +599,14 @@ public class TestColumnarSQLRewriter {
         + "and sales_fact___fact.location_key in  (  select location_dim 
.location_key from "
         + "location_dim where (( location_dim. location_name ) =  'test123' ) 
) and sales_fact___fact.item_key in  "
         + "(  select item_dim .item_key from item_dim where (( item_dim. 
item_name ) =  'item_1' ) )  "
-        + "group by sales_fact___fact.time_key, 
sales_fact___fact.dollars_sold, "
-        + "sales_fact___fact.location_key, sales_fact___fact.item_key) 
sales_fact___fact  "
-        + "inner join (select day_of_week, day, time_key from time_dim) "
+        + "group by sales_fact___fact.time_key, 
sales_fact___fact.location_key, "
+        + "sales_fact___fact.item_key, sales_fact___fact.dollars_sold) 
sales_fact___fact  "
+        + "inner join (select time_key, day_of_week, day from time_dim) "
         + "time_dim___time_dim on (( sales_fact___fact . time_key ) = "
-        + "( time_dim___time_dim . time_key ))  inner join (select 
location_name, "
-        + "location_key from location_dim) location_dim___location_dim "
+        + "( time_dim___time_dim . time_key ))  inner join (select 
location_key, "
+        + "location_name from location_dim) location_dim___location_dim "
         + "on (( sales_fact___fact . location_key ) = ( 
location_dim___location_dim . location_key ))  "
-        + "inner join (select item_name, item_key from item_dim) 
item_dim___item_dim "
+        + "inner join (select item_key, item_name from item_dim) 
item_dim___item_dim "
         + "on ((( sales_fact___fact . item_key ) = "
         + "( item_dim___item_dim . item_key )) and (( 
location_dim___location_dim . location_name ) =  'test123' ))  "
         + "where (( time_dim___time_dim . time_key ) between  '2013-01-01'  
and  '2013-01-31'  "
@@ -662,9 +644,9 @@ public class TestColumnarSQLRewriter {
         + "sales_fact___fact.location_key, sales_fact___fact.item_key) 
sales_fact___fact  inner "
         + "join (select time_key from time_dim) time_dim___time_dim on (( 
sales_fact___fact . time_key ) = "
         + "( time_dim___time_dim . time_key ))  inner join "
-        + "(select location_name, location_key from location_dim) 
location_dim___location_dim on "
+        + "(select location_key, location_name from location_dim) 
location_dim___location_dim on "
         + "(( sales_fact___fact . location_key ) = ( 
location_dim___location_dim . location_key ))  "
-        + "inner join (select item_name, item_key from item_dim) 
item_dim___item_dim "
+        + "inner join (select item_key, item_name from item_dim) 
item_dim___item_dim "
         + "on ((( sales_fact___fact . item_key ) = "
         + "( item_dim___item_dim . item_key )) and  inner )  inner join "
         + "(select branch_key from branch_dim) branch_dim___branch_dim on "
@@ -715,9 +697,9 @@ public class TestColumnarSQLRewriter {
         + "( time_dim___time_dim . day ),  case  when (sum(( 
sales_fact__db_sales_fact_fact . dollars_sold )) =  0 ) "
         + "then  0.0  else sum(( sales_fact__db_sales_fact_fact . dollars_sold 
)) end  dollars_sold  "
         + "from db.sales_fact sales_fact__db_sales_fact_fact  inner join "
-        + "(select day_of_week, day, time_key from time_dim) 
time_dim___time_dim "
+        + "(select time_key, day_of_week, day from time_dim) 
time_dim___time_dim "
         + "on (( sales_fact__db_sales_fact_fact . time_key ) = ( 
time_dim___time_dim . time_key ))  "
-        + "inner join (select location_name, location_key from 
db.location_dim) location_dim__db_location_dim_ld on "
+        + "inner join (select location_key, location_name from 
db.location_dim) location_dim__db_location_dim_ld on "
         + "((( sales_fact__db_sales_fact_fact . location_key ) = ( 
location_dim__db_location_dim_ld . location_key )) "
         + "and (( location_dim__db_location_dim_ld . location_name ) =  
'test123' ))  where "
         + "( time_dim___time_dim . time_key ) between  '2013-01-01'  and  
'2013-01-31'  "
@@ -743,10 +725,10 @@ public class TestColumnarSQLRewriter {
     String actual = qtest.rewrite(query, conf, hconf);
     String expected = "select ( dim1___dim1 . date ) date , sum(alias1) msr1 , 
( dim2___dim2 . name ) dim2_name , "
         + "( dim3___dim3 . name ) dim3_name , ( dim4___dim4 . name ) dim4_name 
 "
-        + "from  (select fact___f.dim2_id, fact___f.dim1_id, 
fact___f.dim3_id,sum(( fact___f . msr1 )) "
+        + "from  (select fact___f.dim1_id, fact___f.dim2_id, 
fact___f.dim3_id,sum(( fact___f . msr1 )) "
         + "as alias1 from fact fact___f where fact___f.dim1_id in  (  select 
dim1 .id from dim1 where "
         + "(( dim1. date ) =  '2014-11-25 00:00:00' ) )  "
-        + "group by fact___f.dim2_id, fact___f.dim1_id, fact___f.dim3_id) "
+        + "group by fact___f.dim1_id, fact___f.dim2_id, fact___f.dim3_id) "
         + "fact___f  inner join (select id, date from dim1) "
         + "dim1___dim1 on (( fact___f . dim1_id ) = ( dim1___dim1 . id ))  "
         + "inner join (select id, id_2, name from dim2) dim2___dim2 "
@@ -773,11 +755,11 @@ public class TestColumnarSQLRewriter {
 
     String actual = qtest.rewrite(query, conf, hconf);
     String expected = "select ( dim1___dim1 . date ) date , sum(alias1) msr1 , 
( dim2___dim2 . name ) "
-        + "dim2_name  from  (select fact___f.dim2_id, fact___f.dim1_id, 
fact___f.m4, fact___f.m3, "
-        + "fact___f.m2,sum(( fact___f . msr1 )) as alias1 from fact fact___f 
where ( fact___f . m4 ) "
+        + "dim2_name  from  (select fact___f.dim1_id, fact___f.m2, 
fact___f.dim2_id, fact___f.m3, fact___f.m4, "
+        + "sum(( fact___f . msr1 )) as alias1 from fact fact___f where ( 
fact___f . m4 ) "
         + "is not null  and (( fact___f . m2 ) =  '1234' ) and (( fact___f . 
m3 ) >  3000 ) and "
         + "fact___f.dim1_id in  (  select dim1 .id from dim1 where (( dim1. 
date ) =  '2014-11-25 00:00:00' ) )  "
-        + "group by fact___f.dim2_id, fact___f.dim1_id, fact___f.m4, 
fact___f.m3, fact___f.m2) fact___f  "
+        + "group by fact___f.dim1_id, fact___f.m2, fact___f.dim2_id, 
fact___f.m3, fact___f.m4) fact___f  "
         + "inner join (select id, date from dim1) dim1___dim1 on ((( fact___f 
. dim1_id ) = ( dim1___dim1 . id )) and "
         + "(( fact___f . m2 ) =  '1234' ))  inner join (select id, name from 
dim2) "
         + "dim2___dim2 on ((( fact___f . dim2_id ) = "
@@ -800,13 +782,14 @@ public class TestColumnarSQLRewriter {
     SessionState.start(hconf);
 
     String actual = qtest.rewrite(query, conf, hconf);
+
     String expected = "select ( dim1___dim1 . date ) dim1_date , sum(alias1) 
msr1 , "
         + "( dim2___dim2 . name ) dim2_name  "
-        + "from  (select fact___f.dim2_id, fact___f.dim1_id, fact___f.m4, 
fact___f.m3, fact___f.m2,"
+        + "from  (select fact___f.dim1_id, fact___f.m2, fact___f.dim2_id, 
fact___f.m3, fact___f.m4"
         + "sum(( fact___f . msr1 )) as alias1 from fact fact___f where ( 
fact___f . m4 ) "
         + "is not null  and (( fact___f . m2 ) =  '1234' ) and (( fact___f . 
m3 ) >  3000 ) "
         + "and fact___f.dim1_id in  (  select dim1 .id from dim1 where (( 
dim1. date ) =  '2014-11-25 00:00:00' ) )  "
-        + "group by fact___f.dim2_id, fact___f.dim1_id, fact___f.m4, 
fact___f.m3, fact___f.m2) fact___f  "
+        + "group by fact___f.dim1_id, fact___f.m2, fact___f.dim2_id, 
fact___f.m3, fact___f.m4) fact___f  "
         + "inner join (select id, date from dim1) dim1___dim1 on ((( fact___f 
. dim1_id ) = ( dim1___dim1 . id )) "
         + "and (( fact___f . m2 ) =  '1234' ))  inner join (select id, name 
from dim2) "
         + "dim2___dim2 on ((( fact___f . dim2_id ) "
@@ -830,11 +813,12 @@ public class TestColumnarSQLRewriter {
 
     String actual = qtest.rewrite(query, conf, hconf);
     String expected = "select ( dim1___dim1 . date ) dim1_date , sum(alias1) 
msr1 , "
-        + "( dim2___dim2 . name ) dim2_name  from  (select fact___f.dim2_id, 
fact___f.dim1_id, fact___f.dim3_id, "
-        + "fact___f.m4, fact___f.m2,sum(( fact___f . msr1 )) as alias1 from 
fact fact___f where ( fact___f . m4 ) "
+        + "( dim2___dim2 . name ) dim2_name  from  (select fact___f.dim1_id, 
fact___f.m2, fact___f.dim2_id,"
+        + "fact___f.dim3_id, "
+        + "fact___f.m4, sum(( fact___f . msr1 )) as alias1 from fact fact___f 
where ( fact___f . m4 ) "
         + "is not null  and (( fact___f . m2 ) =  '1234' ) and 
fact___f.dim1_id in  (  select dim1 .id from dim1 "
-        + "where (( dim1. date ) =  '2014-11-25 00:00:00' ) )  group by 
fact___f.dim2_id, fact___f.dim1_id, "
-        + "fact___f.dim3_id, fact___f.m4, fact___f.m2) fact___f  inner join 
(select id, date from dim1) dim1___dim1 on "
+        + "where (( dim1. date ) =  '2014-11-25 00:00:00' ) ) group by 
fact___f.dim1_id, fact___f.m2, fact___f.dim2_id,"
+        + "fact___f.dim3_id, fact___f.m4) fact___f  inner join (select id, 
date from dim1) dim1___dim1 on "
         + "((( fact___f . dim1_id ) = ( dim1___dim1 . id )) and (( fact___f . 
m2 ) =  '1234' ))  "
         + "inner join (select id, name from dim2) dim2___dim2 on ((( fact___f 
. dim2_id ) = ( dim2___dim2 . id )) "
         + "and (( fact___f . dim3_id ) = ( dim2___dim2 . id )))  where ((( 
dim1___dim1 . date ) =  "

Reply via email to