You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@carbondata.apache.org by ch...@apache.org on 2016/07/20 10:13:54 UTC

[26/50] [abbrv] incubator-carbondata git commit: [Bug] Fix query without data load null pointer exception on hdfs (#826)

[Bug] Fix query without data load null pointer exception on hdfs (#826)

fix query without data load null pointer exception

* add test cases


Project: http://git-wip-us.apache.org/repos/asf/incubator-carbondata/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-carbondata/commit/6b8d35db
Tree: http://git-wip-us.apache.org/repos/asf/incubator-carbondata/tree/6b8d35db
Diff: http://git-wip-us.apache.org/repos/asf/incubator-carbondata/diff/6b8d35db

Branch: refs/heads/master
Commit: 6b8d35dba8d4354afe0165d12d442cc27df415c9
Parents: 00ff214
Author: Zhangshunyu <zh...@huawei.com>
Authored: Mon Jul 18 14:39:56 2016 +0800
Committer: Kumar Vishal <ku...@gmail.com>
Committed: Mon Jul 18 12:09:56 2016 +0530

----------------------------------------------------------------------
 .../allqueries/TestQueryWithoutDataLoad.scala   | 63 ++++++++++++++++++++
 .../lcm/status/SegmentStatusManager.java        | 10 +++-
 2 files changed, 70 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/6b8d35db/integration/spark/src/test/scala/org/carbondata/spark/testsuite/allqueries/TestQueryWithoutDataLoad.scala
----------------------------------------------------------------------
diff --git a/integration/spark/src/test/scala/org/carbondata/spark/testsuite/allqueries/TestQueryWithoutDataLoad.scala b/integration/spark/src/test/scala/org/carbondata/spark/testsuite/allqueries/TestQueryWithoutDataLoad.scala
new file mode 100644
index 0000000..b9f9f53
--- /dev/null
+++ b/integration/spark/src/test/scala/org/carbondata/spark/testsuite/allqueries/TestQueryWithoutDataLoad.scala
@@ -0,0 +1,63 @@
+/*
+ * 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.
+ */
+
+package org.carbondata.spark.testsuite.allqueries
+
+import org.apache.spark.sql.Row
+import org.apache.spark.sql.common.util.CarbonHiveContext._
+import org.apache.spark.sql.common.util.QueryTest
+import org.scalatest.BeforeAndAfterAll
+
+/*
+ * Test Class for query without data load
+ *
+ */
+class TestQueryWithoutDataLoad extends QueryTest with BeforeAndAfterAll {
+  override def beforeAll {
+    sql("drop table if exists no_load")
+    sql("""
+        CREATE TABLE no_load(imei string, age int, productdate timestamp, gamePointId double)
+        STORED BY 'org.apache.carbondata.format'
+        TBLPROPERTIES('DICTIONARY_EXCLUDE'='productdate', 'DICTIONARY_INCLUDE'='gamePointId')
+      """)
+  }
+
+  test("test query without data load") {
+    checkAnswer(
+      sql("select count(*) from no_load"), Seq(Row(0))
+    )
+    checkAnswer(
+      sql("select * from no_load"), Seq.empty
+    )
+    checkAnswer(
+      sql("select imei, count(age) from no_load group by imei"), Seq.empty
+    )
+    checkAnswer(
+      sql("select imei, sum(age) from no_load group by imei"), Seq.empty
+    )
+    checkAnswer(
+      sql("select imei, avg(age) from no_load group by imei"), Seq.empty
+    )
+  }
+
+  override def afterAll {
+    sql("drop table no_load")
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/6b8d35db/processing/src/main/java/org/carbondata/lcm/status/SegmentStatusManager.java
----------------------------------------------------------------------
diff --git a/processing/src/main/java/org/carbondata/lcm/status/SegmentStatusManager.java b/processing/src/main/java/org/carbondata/lcm/status/SegmentStatusManager.java
index d5b06f6..e6220d8 100644
--- a/processing/src/main/java/org/carbondata/lcm/status/SegmentStatusManager.java
+++ b/processing/src/main/java/org/carbondata/lcm/status/SegmentStatusManager.java
@@ -81,12 +81,16 @@ public class SegmentStatusManager {
   /**
    * This method will return last modified time of tablestatus file
    */
-  public long getTableStatusLastModifiedTime() {
+  public long getTableStatusLastModifiedTime() throws IOException {
     String tableStatusPath = CarbonStorePath.getCarbonTablePath(
         absoluteTableIdentifier.getStorePath(), absoluteTableIdentifier.getCarbonTableIdentifier())
           .getTableStatusFilePath();
-    return FileFactory.getCarbonFile(tableStatusPath, FileFactory.getFileType(tableStatusPath))
-      .getLastModifiedTime();
+    if (!FileFactory.isFileExist(tableStatusPath, FileFactory.getFileType(tableStatusPath))) {
+      return 0L;
+    } else {
+      return FileFactory.getCarbonFile(tableStatusPath, FileFactory.getFileType(tableStatusPath))
+          .getLastModifiedTime();
+    }
   }
 
   /**