LENS-1502 : Fixt in virtual fact properties.
authorRajitha R <rajithar@apache.org>
Wed, 27 Jun 2018 11:10:11 +0000 (16:40 +0530)
committerRajitha.R <rajithar@IM0318-L0.corp.inmobi.com>
Wed, 27 Jun 2018 11:10:11 +0000 (16:40 +0530)
lens-cube/src/main/java/org/apache/lens/cube/parse/StorageCandidate.java
lens-cube/src/test/java/org/apache/lens/cube/parse/TestVirtualFactQueries.java
lens-cube/src/test/resources/schema/cubes/base/testcube2.xml
lens-cube/src/test/resources/schema/cubes/base/virtualcube.xml
lens-cube/src/test/resources/schema/facts/testfact9_base.xml
lens-cube/src/test/resources/schema/facts/virtual/virtualfact2.xml [new file with mode: 0644]
lens_bk [new submodule]

index b48be7f..193ce6b 100644 (file)
@@ -315,11 +315,12 @@ public class StorageCandidate implements Candidate, CandidateTable {
 
   public Optional<Date> getColumnStartTime(String column) {
     Date startTime = null;
-    for (String key : this.getFact().getSourceFactProperties().keySet()) {
+    Map<String, String> propertiesMap = this.getFact().getSourceFactProperties();
+    for (String key : propertiesMap.keySet()) {
       if (key.contains(MetastoreConstants.FACT_COL_START_TIME_PFX)) {
         String propCol = StringUtils.substringAfter(key, MetastoreConstants.FACT_COL_START_TIME_PFX);
         if (column.equals(propCol)) {
-          startTime = MetastoreUtil.getDateFromProperty(getTable().getProperties().get(key), false, true);
+          startTime = MetastoreUtil.getDateFromProperty(propertiesMap.get(key), false, true);
         }
       }
     }
@@ -329,11 +330,12 @@ public class StorageCandidate implements Candidate, CandidateTable {
   @Override
   public Optional<Date> getColumnEndTime(String column) {
     Date endTime = null;
-    for (String key : this.getFact().getSourceFactProperties().keySet()) {
+    Map<String, String> propertiesMap = this.getFact().getSourceFactProperties();
+    for (String key : propertiesMap.keySet()) {
       if (key.contains(MetastoreConstants.FACT_COL_END_TIME_PFX)) {
         String propCol = StringUtils.substringAfter(key, MetastoreConstants.FACT_COL_END_TIME_PFX);
         if (column.equals(propCol)) {
-          endTime = MetastoreUtil.getDateFromProperty(getTable().getProperties().get(key), false, true);
+          endTime = MetastoreUtil.getDateFromProperty(propertiesMap.get(key), false, true);
         }
       }
     }
index fe6b20d..e2f1074 100644 (file)
@@ -33,6 +33,7 @@ import org.apache.lens.server.api.error.LensException;
 
 import org.apache.hadoop.conf.Configuration;
 
+import org.testng.Assert;
 import org.testng.annotations.BeforeTest;
 import org.testng.annotations.Test;
 
@@ -66,6 +67,36 @@ public class TestVirtualFactQueries extends TestQueryRewrite {
     compareQueries(hql, expected);
   }
 
+
+  @Test
+  public void testVirtualFactColStartTimeQuery() {
+    try {
+        rewriteCtx("select dim1,SUM(msr1) from virtualcube where " + TWO_DAYS_RANGE, getConfWithStorages("C1"));
+        Assert.fail("Should not come here..Column Start time feature is failing..");
+    }catch (LensException e) {
+      if(e.getErrorCode() == 3024) {
+        System.out.println("Expected flow :" + e.getMessage());
+      }else {
+        Assert.fail("Exception not as expected");
+      }
+    }
+  }
+
+  @Test
+  public void testVirtualFactColEndTimeQuery() {
+    try {
+      rewriteCtx("select dim2,SUM(msr1) from virtualcube where " + TWO_DAYS_RANGE, getConfWithStorages("C1"));
+      Assert.fail("Should not come here..Column End time feature is failing..");
+    }catch (LensException e) {
+      if(e.getErrorCode() == 3024) {
+        System.out.println("Expected flow :" + e.getMessage());
+      }else {
+        Assert.fail("Exception not as expected");
+      }
+    }
+  }
+
+
   @Test
   public void testVirtualFactMonthQuery() throws Exception {
 
index 237e85a..8d80a03 100644 (file)
@@ -22,7 +22,7 @@
 <x_base_cube name="testcube2" xmlns="uri:lens:cube:0.1">
   <properties>
     <property name="cube.timedim.partition.d_time" value="dt"/>
-    <property name="cube.testcube.timed.dimensions.list" value="d_time"/>
+    <property name="cube.testcube2.timed.dimensions.list" value="d_time"/>
   </properties>
   <measures>
     <measure _type="FLOAT" default_aggr="SUM" unit="RS" name="msr1" display_string="Measure1"
@@ -30,4 +30,9 @@
     <measure _type="FLOAT" default_aggr="SUM" unit="RS" name="msr4" display_string="Measure4"
              description="fourth measure"/>
   </measures>
+  <dim_attributes>
+    <dim_attribute name="dim1" _type="string" />
+    <dim_attribute name="dim2" _type="string" />
+  </dim_attributes>
+
 </x_base_cube>
index 187ac29..38315ab 100644 (file)
@@ -35,6 +35,7 @@
   </measures>
   <dim_attributes>
     <dim_attribute _type="string" name="dim1" description="basedim"/>
+    <dim_attribute _type="string" name="dim2" description="basedim"/>
     <dim_attribute _type="int" name="cityid" description="basedim"/>
     <dim_attribute name="stateid" _type="int" description="state id"/>
   </dim_attributes>
index 9c94fe2..10222ca 100644 (file)
@@ -21,7 +21,8 @@
 -->
 <x_fact_table name="testfact9_base" cube_name="testcube2" weight="5.0" xmlns="uri:lens:cube:0.1">
   <columns>
-
+    <column name="dim1" _type="string" comment="first dim" start_time="2099-01-01"/>
+    <column name="dim2" _type="string" comment="second dim" end_time="2017-01-01"/>
     <column name="msr1" _type="float" comment="first measure"/>
     <column name="msr4" _type="float" comment="fourth measure"/>
   </columns>
diff --git a/lens-cube/src/test/resources/schema/facts/virtual/virtualfact2.xml b/lens-cube/src/test/resources/schema/facts/virtual/virtualfact2.xml
new file mode 100644 (file)
index 0000000..b796336
--- /dev/null
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements. See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership. The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License. You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied. See the License for the
+  specific language governing permissions and limitations
+  under the License.
+
+-->
+<x_virtual_fact_table source_fact_name="testfact9_base" cube_name="virtualcube" name="virtualfact2" xmlns="uri:lens:cube:0.1"
+                      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="uri:lens:cube:0.1 cube-0.1.xsd ">
+  <properties>
+    <property name="cube.fact.virtualfact1.valid.columns"
+              value="dim1,dim2,msr1"/>
+  </properties>
+</x_virtual_fact_table>
diff --git a/lens_bk b/lens_bk
new file mode 160000 (submodule)
index 0000000..d0d9adf
--- /dev/null
+++ b/lens_bk
@@ -0,0 +1 @@
+Subproject commit d0d9adf35ca476f28cb872285097309cdb6e55a6