You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by li...@apache.org on 2016/09/20 13:50:43 UTC

[2/2] kylin git commit: KYLIN-2010 fix unit tests

KYLIN-2010 fix unit tests


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

Branch: refs/heads/KYLIN-2010
Commit: e79e121d28e11809c4d97b96e09f7e71d272cefd
Parents: d5551fe
Author: Yang Li <li...@apache.org>
Authored: Tue Sep 20 21:50:24 2016 +0800
Committer: Yang Li <li...@apache.org>
Committed: Tue Sep 20 21:50:24 2016 +0800

----------------------------------------------------------------------
 .../apache/kylin/cube/kv/RowKeyDecoderTest.java | 11 ++-----
 .../kylin/dict/lookup/LookupStringTable.java    | 22 +-------------
 .../kylin/dict/lookup/LookupTableTest.java      | 31 ++++++++------------
 3 files changed, 16 insertions(+), 48 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kylin/blob/e79e121d/core-cube/src/test/java/org/apache/kylin/cube/kv/RowKeyDecoderTest.java
----------------------------------------------------------------------
diff --git a/core-cube/src/test/java/org/apache/kylin/cube/kv/RowKeyDecoderTest.java b/core-cube/src/test/java/org/apache/kylin/cube/kv/RowKeyDecoderTest.java
index 7b8000c..968f015 100644
--- a/core-cube/src/test/java/org/apache/kylin/cube/kv/RowKeyDecoderTest.java
+++ b/core-cube/src/test/java/org/apache/kylin/cube/kv/RowKeyDecoderTest.java
@@ -24,7 +24,6 @@ import java.io.IOException;
 import java.util.List;
 
 import org.apache.kylin.common.util.Bytes;
-import org.apache.kylin.common.util.DateFormat;
 import org.apache.kylin.common.util.LocalFileMetadataTestCase;
 import org.apache.kylin.cube.CubeInstance;
 import org.apache.kylin.cube.CubeManager;
@@ -58,7 +57,7 @@ public class RowKeyDecoderTest extends LocalFileMetadataTestCase {
 
         rowKeyDecoder.decode(key);
         List<String> values = rowKeyDecoder.getValues();
-        assertEquals("[" + millis("2012-12-15") + ", 11848, Health & Beauty, Fragrances, Women, FP-GTC, 0, 15]", values.toString());
+        assertEquals("[2012-12-15, 11848, Health & Beauty, Fragrances, Women, FP-GTC, 0, 15]", values.toString());
     }
 
     @Test
@@ -71,7 +70,7 @@ public class RowKeyDecoderTest extends LocalFileMetadataTestCase {
 
         rowKeyDecoder.decode(key);
         List<String> values = rowKeyDecoder.getValues();
-        assertEquals("[10000000, " + millis("2012-01-02") + ", 20213, Collectibles, Postcards, US StateCities & Towns, ABIN, 0, -99]", values.toString());
+        assertEquals("[10000000, 2012-01-02, 20213, Collectibles, Postcards, US StateCities & Towns, ABIN, 0, -99]", values.toString());
     }
 
     @Test
@@ -99,11 +98,7 @@ public class RowKeyDecoderTest extends LocalFileMetadataTestCase {
         RowKeyDecoder rowKeyDecoder = new RowKeyDecoder(cube.getFirstSegment());
         rowKeyDecoder.decode(encodedKey);
         List<String> values = rowKeyDecoder.getValues();
-        assertEquals("[" + millis("2012-12-15") + ", 11848, Health & Beauty, Fragrances, Women, \u520a\u767b\u683c\u5f0f, 0, 15]", values.toString());
-    }
-
-    private String millis(String dateStr) {
-        return String.valueOf(DateFormat.stringToMillis(dateStr));
+        assertEquals("[2012-12-15, 11848, Health & Beauty, Fragrances, Women, \u520a\u767b\u683c\u5f0f, 0, 15]", values.toString());
     }
 
 }

http://git-wip-us.apache.org/repos/asf/kylin/blob/e79e121d/core-dictionary/src/main/java/org/apache/kylin/dict/lookup/LookupStringTable.java
----------------------------------------------------------------------
diff --git a/core-dictionary/src/main/java/org/apache/kylin/dict/lookup/LookupStringTable.java b/core-dictionary/src/main/java/org/apache/kylin/dict/lookup/LookupStringTable.java
index f13275c..5fd2d30 100644
--- a/core-dictionary/src/main/java/org/apache/kylin/dict/lookup/LookupStringTable.java
+++ b/core-dictionary/src/main/java/org/apache/kylin/dict/lookup/LookupStringTable.java
@@ -21,7 +21,6 @@ package org.apache.kylin.dict.lookup;
 import java.io.IOException;
 import java.util.Comparator;
 
-import org.apache.kylin.common.util.DateFormat;
 import org.apache.kylin.metadata.datatype.DataType;
 import org.apache.kylin.metadata.model.ColumnDesc;
 import org.apache.kylin.metadata.model.TableDesc;
@@ -33,15 +32,6 @@ import org.apache.kylin.source.ReadableTable;
  */
 public class LookupStringTable extends LookupTable<String> {
 
-    private static final Comparator<String> dateStrComparator = new Comparator<String>() {
-        @Override
-        public int compare(String o1, String o2) {
-            long l1 = Long.parseLong(o1);
-            long l2 = Long.parseLong(o2);
-            return Long.compare(l1, l2);
-        }
-    };
-
     private static final Comparator<String> numStrComparator = new Comparator<String>() {
         @Override
         public int compare(String o1, String o2) {
@@ -58,7 +48,6 @@ public class LookupStringTable extends LookupTable<String> {
         }
     };
 
-    boolean[] colIsDateTime;
     boolean[] colIsNumber;
 
     public LookupStringTable(TableDesc tableDesc, String[] keyColumns, ReadableTable table) throws IOException {
@@ -68,11 +57,9 @@ public class LookupStringTable extends LookupTable<String> {
     @Override
     protected void init() throws IOException {
         ColumnDesc[] cols = tableDesc.getColumns();
-        colIsDateTime = new boolean[cols.length];
         colIsNumber = new boolean[cols.length];
         for (int i = 0; i < cols.length; i++) {
             DataType t = cols[i].getType();
-            colIsDateTime[i] = t.isDateTimeFamily();
             colIsNumber[i] = t.isNumberFamily();
         }
 
@@ -81,19 +68,12 @@ public class LookupStringTable extends LookupTable<String> {
 
     @Override
     protected String[] convertRow(String[] cols) {
-        for (int i = 0; i < cols.length; i++) {
-            if (colIsDateTime[i]) {
-                cols[i] = String.valueOf(DateFormat.stringToMillis(cols[i]));
-            }
-        }
         return cols;
     }
 
     @Override
     protected Comparator<String> getComparator(int idx) {
-        if (colIsDateTime[idx])
-            return dateStrComparator;
-        else if (colIsNumber[idx])
+        if (colIsNumber[idx])
             return numStrComparator;
         else
             return defaultStrComparator;

http://git-wip-us.apache.org/repos/asf/kylin/blob/e79e121d/core-dictionary/src/test/java/org/apache/kylin/dict/lookup/LookupTableTest.java
----------------------------------------------------------------------
diff --git a/core-dictionary/src/test/java/org/apache/kylin/dict/lookup/LookupTableTest.java b/core-dictionary/src/test/java/org/apache/kylin/dict/lookup/LookupTableTest.java
index e4b32db..05592be 100644
--- a/core-dictionary/src/test/java/org/apache/kylin/dict/lookup/LookupTableTest.java
+++ b/core-dictionary/src/test/java/org/apache/kylin/dict/lookup/LookupTableTest.java
@@ -57,60 +57,53 @@ public class LookupTableTest extends LocalFileMetadataTestCase {
     @Test
     public void testScan() throws Exception {
         List<String> values = new ArrayList<String>();
-        values.add(millis("2012-01-24"));
-        values.add(millis("2012-12-30"));
+        values.add("2012-01-24");
+        values.add("2012-12-30");
         List<String> results = lookupTable.scan("CAL_DT", values, "YEAR_BEG_DT");
 
         Assert.assertTrue(results.size() > 0);
         for (String i : results) {
             System.out.println(i);
 
-            Assert.assertEquals(millis("2012-01-01"), i);
+            Assert.assertEquals("2012-01-01", i);
         }
     }
 
     @Test
     public void testMapRange() throws Exception {
-        Pair<String, String> results = lookupTable.mapRange("CAL_DT", millis("2012-01-24"), millis("2012-12-30"), "QTR_BEG_DT");
+        Pair<String, String> results = lookupTable.mapRange("CAL_DT", "2012-01-24", "2012-12-30", "QTR_BEG_DT");
 
         Assert.assertTrue(results != null);
         System.out.println("The first qtr_beg_dt is " + results.getFirst());
         System.out.println("The last qtr_beg_dt is " + results.getSecond());
 
-        Assert.assertEquals(millis("2012-01-01"), results.getFirst());
-        Assert.assertEquals(millis("2012-10-01"), results.getSecond());
+        Assert.assertEquals("2012-01-01", results.getFirst());
+        Assert.assertEquals("2012-10-01", results.getSecond());
     }
 
     @Test
     public void testMapRange2() throws Exception {
-        Pair<String, String> results = lookupTable.mapRange("WEEK_BEG_DT", millis("2013-05-01"), millis("2013-08-01"), "CAL_DT");
+        Pair<String, String> results = lookupTable.mapRange("WEEK_BEG_DT", "2013-05-01", "2013-08-01", "CAL_DT");
 
-        System.out.println(DateFormat.formatToDateStr(Long.parseLong(results.getFirst())));
-        System.out.println(DateFormat.formatToDateStr(Long.parseLong(results.getSecond())));
-
-        Assert.assertEquals(millis("2013-05-05"), results.getFirst());
-        Assert.assertEquals(millis("2013-08-03"), results.getSecond());
+        Assert.assertEquals("2013-05-05", results.getFirst());
+        Assert.assertEquals("2013-08-03", results.getSecond());
     }
 
     @Test
     public void testMapValues() throws Exception {
         Set<String> values = new HashSet<String>();
-        values.add(millis("2012-01-24"));
-        values.add(millis("2012-12-30"));
+        values.add("2012-01-24");
+        values.add("2012-12-30");
         Set<String> results = lookupTable.mapValues("CAL_DT", values, "YEAR_BEG_DT");
 
         Assert.assertTrue(results.size() == 1);
         for (String i : results) {
             System.out.println(i);
 
-            Assert.assertEquals(millis("2012-01-01"), i);
+            Assert.assertEquals("2012-01-01", i);
         }
     }
 
-    private String millis(String dateStr) {
-        return String.valueOf(DateFormat.stringToMillis(dateStr));
-    }
-
     public LookupTable<String> initLookupTable() throws Exception {
 
         MetadataManager metaMgr = MetadataManager.getInstance(config);