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 2016/05/12 08:01:24 UTC

lens git commit: LENS-771 : Add test for multiple chain ref columns having subset chains

Repository: lens
Updated Branches:
  refs/heads/master 3a265f5e6 -> dfd332902


LENS-771 : Add test for multiple chain ref columns having subset chains


Project: http://git-wip-us.apache.org/repos/asf/lens/repo
Commit: http://git-wip-us.apache.org/repos/asf/lens/commit/dfd33290
Tree: http://git-wip-us.apache.org/repos/asf/lens/tree/dfd33290
Diff: http://git-wip-us.apache.org/repos/asf/lens/diff/dfd33290

Branch: refs/heads/master
Commit: dfd332902c24a897b49362ec8f217de664ab3007
Parents: 3a265f5
Author: Amareshwari Sriramadasu <am...@gmail.com>
Authored: Thu May 12 13:30:02 2016 +0530
Committer: Rajat Khandelwal <ra...@gmail.com>
Committed: Thu May 12 13:30:02 2016 +0530

----------------------------------------------------------------------
 .../cube/metadata/ReferencedDimAttribute.java     |  7 ++++++-
 .../org/apache/lens/cube/parse/CubeTestSetup.java |  9 +++++++--
 .../cube/parse/TestDenormalizationResolver.java   | 18 ++++++++++++++++++
 lens-examples/src/main/resources/sales-cube.xml   |  1 +
 .../src/test/resources/yaml/sales-cube.yaml       |  3 +++
 5 files changed, 35 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lens/blob/dfd33290/lens-cube/src/main/java/org/apache/lens/cube/metadata/ReferencedDimAttribute.java
----------------------------------------------------------------------
diff --git a/lens-cube/src/main/java/org/apache/lens/cube/metadata/ReferencedDimAttribute.java b/lens-cube/src/main/java/org/apache/lens/cube/metadata/ReferencedDimAttribute.java
index 4c98d86..4a9dd54 100644
--- a/lens-cube/src/main/java/org/apache/lens/cube/metadata/ReferencedDimAttribute.java
+++ b/lens-cube/src/main/java/org/apache/lens/cube/metadata/ReferencedDimAttribute.java
@@ -42,6 +42,11 @@ public class ReferencedDimAttribute extends BaseDimAttribute {
   public static class ChainRefCol {
     private final String chainName;
     private final String refColumn;
+
+    public ChainRefCol(String chainName, String refColumn) {
+      this.chainName = chainName.toLowerCase();
+      this.refColumn = refColumn.toLowerCase();
+    }
   }
 
   public ReferencedDimAttribute(FieldSchema column, String displayString, String chainName, String refColumn,
@@ -52,7 +57,7 @@ public class ReferencedDimAttribute extends BaseDimAttribute {
   public ReferencedDimAttribute(FieldSchema column, String displayString, String chainName, String refColumn,
     Date startTime, Date endTime, Double cost, Long numOfDistinctValues) throws LensException {
     this(column, displayString,
-      Collections.singletonList(new ChainRefCol(chainName.toLowerCase(), refColumn.toLowerCase())), startTime, endTime,
+      Collections.singletonList(new ChainRefCol(chainName, refColumn)), startTime, endTime,
       cost, numOfDistinctValues);
   }
 

http://git-wip-us.apache.org/repos/asf/lens/blob/dfd33290/lens-cube/src/test/java/org/apache/lens/cube/parse/CubeTestSetup.java
----------------------------------------------------------------------
diff --git a/lens-cube/src/test/java/org/apache/lens/cube/parse/CubeTestSetup.java b/lens-cube/src/test/java/org/apache/lens/cube/parse/CubeTestSetup.java
index c0035a7..b9694d7 100644
--- a/lens-cube/src/test/java/org/apache/lens/cube/parse/CubeTestSetup.java
+++ b/lens-cube/src/test/java/org/apache/lens/cube/parse/CubeTestSetup.java
@@ -983,6 +983,11 @@ public class CubeTestSetup {
       "state country", "cubestatecountry", "name", null, null, null));
     cubeDimensions2.add(new ReferencedDimAttribute(new FieldSchema("citycountry", "string", ""),
       "city country", "cubecitystatecountry", "name", null, null, null));
+    List<ChainRefCol> refCols = new ArrayList<>();
+    refCols.add(new ChainRefCol("cubeState", "countrycapital"));
+    refCols.add(new ChainRefCol("cubeCityStateCountry", "capital"));
+    cubeDimensions2.add(new ReferencedDimAttribute(new FieldSchema("cubeCountryCapital", "String", "ref dim"),
+      "Country capital", refCols, null, null, null, null));
 
     Map<String, String> cubeProperties = new HashMap<>();
     cubeProperties.put(MetastoreUtil.getCubeTimedDimensionListKey(BASE_CUBE_NAME),
@@ -2582,8 +2587,8 @@ public class CubeTestSetup {
         });
       }
     };
-    Dimension countryDim = new Dimension(dimName, dimAttrs, null, joinchains, dimProps, 0L);
-    client.createDimension(countryDim);
+    Dimension stateDim = new Dimension(dimName, dimAttrs, null, joinchains, dimProps, 0L);
+    client.createDimension(stateDim);
 
     String dimTblName = "statetable";
     List<FieldSchema> dimColumns = new ArrayList<FieldSchema>();

http://git-wip-us.apache.org/repos/asf/lens/blob/dfd33290/lens-cube/src/test/java/org/apache/lens/cube/parse/TestDenormalizationResolver.java
----------------------------------------------------------------------
diff --git a/lens-cube/src/test/java/org/apache/lens/cube/parse/TestDenormalizationResolver.java b/lens-cube/src/test/java/org/apache/lens/cube/parse/TestDenormalizationResolver.java
index 51ba636..5505ed4 100644
--- a/lens-cube/src/test/java/org/apache/lens/cube/parse/TestDenormalizationResolver.java
+++ b/lens-cube/src/test/java/org/apache/lens/cube/parse/TestDenormalizationResolver.java
@@ -373,4 +373,22 @@ public class TestDenormalizationResolver extends TestQueryRewrite {
     Assert.assertEquals(getLensExceptionErrorMessageInRewrite("select nonexist.name, msr2 from testCube where "
         + TWO_DAYS_RANGE, conf), "Neither cube nor dimensions accessed in the query");
   }
+
+  @Test
+  public void testCubeQueryMultiChainRefCol() throws Exception {
+    Configuration tConf = new Configuration(conf);
+    tConf.set(CubeQueryConfUtil.DRIVER_SUPPORTED_STORAGES, "C1");
+    String hqlQuery = rewrite("select cubeCountryCapital, msr12 from basecube where " + TWO_DAYS_RANGE,
+      tConf);
+    String joinExpr = " join " + getDbName()
+      + "c1_citytable citydim on basecube.cityid = citydim.id and (citydim.dt = 'latest') "
+      + " join " + getDbName() + "c1_statetable statedim on citydim.stateid = statedim.id and (statedim.dt = 'latest')"
+      + " join " + getDbName() + "c1_countrytable cubecitystatecountry on statedim.countryid ="
+      + " cubecitystatecountry.id";
+    String expected =
+      getExpectedQuery("basecube", "select cubecitystatecountry.capital, sum(basecube.msr12) FROM ",
+        joinExpr, null, " group by cubecitystatecountry.capital ", null,
+        getWhereForHourly2days("basecube", "C1_testfact2_raw_base"));
+    TestCubeRewriter.compareQueries(hqlQuery, expected);
+  }
 }

http://git-wip-us.apache.org/repos/asf/lens/blob/dfd33290/lens-examples/src/main/resources/sales-cube.xml
----------------------------------------------------------------------
diff --git a/lens-examples/src/main/resources/sales-cube.xml b/lens-examples/src/main/resources/sales-cube.xml
index f7e3df0..6de09c0 100644
--- a/lens-examples/src/main/resources/sales-cube.xml
+++ b/lens-examples/src/main/resources/sales-cube.xml
@@ -57,6 +57,7 @@
     <dim_attribute name="customer_city_name" _type="string" description="City name to which the customer belongs"
                    display_string="Customer City">
       <chain_ref_column chain_name="customer_city" ref_col="name" />
+      <chain_ref_column chain_name="customer_details" ref_col="customer_city_name" />
     </dim_attribute>
     <dim_attribute name="customer_interest" _type="string" description="Customer's interest"
                    display_string="Customer Interest">

http://git-wip-us.apache.org/repos/asf/lens/blob/dfd33290/lens-examples/src/test/resources/yaml/sales-cube.yaml
----------------------------------------------------------------------
diff --git a/lens-examples/src/test/resources/yaml/sales-cube.yaml b/lens-examples/src/test/resources/yaml/sales-cube.yaml
index 2f5d7a7..6d6b767 100644
--- a/lens-examples/src/test/resources/yaml/sales-cube.yaml
+++ b/lens-examples/src/test/resources/yaml/sales-cube.yaml
@@ -52,6 +52,9 @@ dimAttributes:
       -
         chainName: customer_city
         refCol: name
+      -
+        chainName: customer_details
+        refCol: customer_city_name
     type: string
   Customer Interest(customer_interest) [Customer's interest]:
     chainRefColumn: