You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by qi...@apache.org on 2020/02/27 09:03:12 UTC

[incubator-iotdb] branch fix_andnode created (now 54b6695)

This is an automated email from the ASF dual-hosted git repository.

qiaojialin pushed a change to branch fix_andnode
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git.


      at 54b6695  fix AndNode NullPointer

This branch includes the following new commits:

     new 54b6695  fix AndNode NullPointer

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[incubator-iotdb] 01/01: fix AndNode NullPointer

Posted by qi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

qiaojialin pushed a commit to branch fix_andnode
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git

commit 54b669591a25f06809b02addc7f6fe86c35fb4c1
Author: qiaojialin <64...@qq.com>
AuthorDate: Thu Feb 27 17:02:52 2020 +0800

    fix AndNode NullPointer
---
 .../read/query/timegenerator/node/AndNode.java     | 14 ++++-
 .../read/query/timegenerator/node/LeafNode.java    | 11 ++--
 .../tsfile/read/query/timegenerator/NodeTest.java  | 66 +++++-----------------
 .../iotdb/tsfile/read/reader/FakedBatchReader.java | 55 ++++++++++++++++++
 4 files changed, 90 insertions(+), 56 deletions(-)

diff --git a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/query/timegenerator/node/AndNode.java b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/query/timegenerator/node/AndNode.java
index fa679c1..1b298ba 100644
--- a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/query/timegenerator/node/AndNode.java
+++ b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/query/timegenerator/node/AndNode.java
@@ -58,6 +58,10 @@ public class AndNode implements Node {
     fillLeftCache();
     fillRightCache();
 
+    if (!hasLeftValue() || !hasRightValue()) {
+      return false;
+    }
+
     while (leftTimeColumn.hasCurrent() && rightTimeColumn.hasCurrent()) {
       long leftValue = leftTimeColumn.currentTime();
       long rightValue = rightTimeColumn.currentTime();
@@ -94,6 +98,14 @@ public class AndNode implements Node {
     }
   }
 
+  private boolean hasLeftValue() {
+    return leftTimeColumn != null && leftTimeColumn.hasCurrent();
+  }
+
+  private boolean hasRightValue() {
+    return rightTimeColumn != null && rightTimeColumn.hasCurrent();
+  }
+
   //no more data in cache and has more data in child
   private boolean couldFillCache(TimeColumn timeSeries, Node child) throws IOException {
     return (timeSeries == null || !timeSeries.hasCurrent()) && child.hasNextTimeColumn();
@@ -115,4 +127,4 @@ public class AndNode implements Node {
   public NodeType getType() {
     return NodeType.AND;
   }
-}
+}
\ No newline at end of file
diff --git a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/query/timegenerator/node/LeafNode.java b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/query/timegenerator/node/LeafNode.java
index 3f255af..c0051d8 100644
--- a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/query/timegenerator/node/LeafNode.java
+++ b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/query/timegenerator/node/LeafNode.java
@@ -40,10 +40,13 @@ public class LeafNode implements Node {
     if (hasCached) {
       return true;
     }
-    if (reader.hasNextBatch()) {
-      hasCached = true;
+    while (reader.hasNextBatch()) {
       cacheData = reader.nextBatch();
-      cachedTimeSeries = cacheData.getTimeColumn();
+      if (cacheData.hasCurrent()) {
+        hasCached = true;
+        cachedTimeSeries = cacheData.getTimeColumn();
+        break;
+      }
     }
     return hasCached;
   }
@@ -82,4 +85,4 @@ public class LeafNode implements Node {
     return NodeType.LEAF;
   }
 
-}
+}
\ No newline at end of file
diff --git a/tsfile/src/test/java/org/apache/iotdb/tsfile/read/query/timegenerator/NodeTest.java b/tsfile/src/test/java/org/apache/iotdb/tsfile/read/query/timegenerator/NodeTest.java
index e4ad037..6037993 100644
--- a/tsfile/src/test/java/org/apache/iotdb/tsfile/read/query/timegenerator/NodeTest.java
+++ b/tsfile/src/test/java/org/apache/iotdb/tsfile/read/query/timegenerator/NodeTest.java
@@ -18,15 +18,14 @@
  */
 package org.apache.iotdb.tsfile.read.query.timegenerator;
 
-import org.apache.iotdb.tsfile.file.metadata.ChunkMetaData;
-import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
-import org.apache.iotdb.tsfile.read.common.BatchData;
 import org.apache.iotdb.tsfile.read.common.TimeColumn;
 import org.apache.iotdb.tsfile.read.query.timegenerator.node.AndNode;
 import org.apache.iotdb.tsfile.read.query.timegenerator.node.LeafNode;
 import org.apache.iotdb.tsfile.read.query.timegenerator.node.Node;
 import org.apache.iotdb.tsfile.read.query.timegenerator.node.NodeType;
 import org.apache.iotdb.tsfile.read.query.timegenerator.node.OrNode;
+import org.apache.iotdb.tsfile.read.reader.FakedBatchReader;
+import org.apache.iotdb.tsfile.read.reader.IBatchReader;
 import org.apache.iotdb.tsfile.read.reader.series.AbstractFileSeriesReader;
 import org.junit.Assert;
 import org.junit.Test;
@@ -44,13 +43,17 @@ public class NodeTest {
 
   @Test
   public void testLeafNode() throws IOException {
-    int index = 0;
     long[] timestamps = new long[]{1, 2, 3, 4, 5, 6, 7};
-    AbstractFileSeriesReader seriesReader = new FakedFileSeriesReader(timestamps);
-    Node leafNode = new LeafNode(seriesReader);
-    while (leafNode.hasNextTimeColumn()) {
-      Assert.assertEquals(timestamps[index++], leafNode.nextTimeColumn().currentTime());
+    IBatchReader batchReader = new FakedBatchReader(timestamps);
+    Node leafNode = new LeafNode(batchReader);
+
+    Assert.assertTrue(leafNode.hasNextTimeColumn());
+    TimeColumn timeColumn = leafNode.nextTimeColumn();
+    for (long timestamp : timestamps) {
+      Assert.assertEquals(timestamp, timeColumn.currentTime());
+      timeColumn.next();
     }
+    Assert.assertFalse(leafNode.hasNextTimeColumn());
   }
 
   @Test
@@ -69,8 +72,8 @@ public class NodeTest {
 
   private void testOr(long[] ret, long[] left, long[] right) throws IOException {
     int index = 0;
-    Node orNode = new OrNode(new LeafNode(new FakedFileSeriesReader(left)),
-        new LeafNode(new FakedFileSeriesReader(right)));
+    Node orNode = new OrNode(new LeafNode(new FakedBatchReader(left)),
+        new LeafNode(new FakedBatchReader(right)));
     while (orNode.hasNextTimeColumn()) {
       TimeColumn timeSeries = orNode.nextTimeColumn();
       while (timeSeries.hasCurrent()) {
@@ -93,8 +96,8 @@ public class NodeTest {
 
   private void testAnd(long[] ret, long[] left, long[] right) throws IOException {
     int index = 0;
-    Node andNode = new AndNode(new LeafNode(new FakedFileSeriesReader(left)),
-        new LeafNode(new FakedFileSeriesReader(right)));
+    Node andNode = new AndNode(new LeafNode(new FakedBatchReader(left)),
+        new LeafNode(new FakedBatchReader(right)));
     while (andNode.hasNextTimeColumn()) {
       TimeColumn timeSeries = andNode.nextTimeColumn();
       while (timeSeries.hasCurrent()) {
@@ -106,44 +109,5 @@ public class NodeTest {
     Assert.assertEquals(ret.length, index);
   }
 
-  private static class FakedFileSeriesReader extends AbstractFileSeriesReader {
-
-    BatchData data;
-    boolean hasCachedData;
-
-    public FakedFileSeriesReader(long[] timestamps) {
-      super(null, null, null);
-      data = new BatchData(TSDataType.INT32);
-      for (long time : timestamps) {
-        data.putInt(time, 1);
-      }
-      hasCachedData = true;
-    }
-
-    @Override
-    public boolean hasNextBatch() {
-      return hasCachedData;
-    }
-
-    @Override
-    public BatchData nextBatch() {
-      hasCachedData = false;
-      return data;
-    }
 
-    @Override
-    protected void initChunkReader(ChunkMetaData chunkMetaData) throws IOException {
-
-    }
-
-    @Override
-    protected boolean chunkSatisfied(ChunkMetaData chunkMetaData) {
-      return false;
-    }
-
-    @Override
-    public void close() {
-
-    }
-  }
 }
diff --git a/tsfile/src/test/java/org/apache/iotdb/tsfile/read/reader/FakedBatchReader.java b/tsfile/src/test/java/org/apache/iotdb/tsfile/read/reader/FakedBatchReader.java
new file mode 100644
index 0000000..3ed5df0
--- /dev/null
+++ b/tsfile/src/test/java/org/apache/iotdb/tsfile/read/reader/FakedBatchReader.java
@@ -0,0 +1,55 @@
+/*
+ * 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.apache.iotdb.tsfile.read.reader;
+
+import java.io.IOException;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.read.common.BatchData;
+
+public class FakedBatchReader implements IBatchReader {
+
+  private BatchData data;
+  private boolean hasCached = false;
+
+  public FakedBatchReader(long[] timestamps) {
+    data = new BatchData(TSDataType.INT32);
+    for (long time : timestamps) {
+      data.putInt(time, 1);
+      hasCached = true;
+    }
+  }
+
+  @Override
+  public boolean hasNextBatch() {
+    return hasCached;
+  }
+
+  @Override
+  public BatchData nextBatch() throws IOException {
+    if (data == null || !data.hasCurrent()) {
+      throw new IOException("no next batch");
+    }
+    hasCached = false;
+    return data;
+  }
+
+  @Override
+  public void close() {
+  }
+}
\ No newline at end of file