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

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

commit ef46df96312e6dd7309debd7ccabd207e5c6547f
Author: suyue <[email protected]>
AuthorDate: Thu Mar 21 15:16:20 2019 +0800

    fix bug IOTDB-50
---
 .../query/dataset/DataSetWithoutTimeGenerator.java |  2 +-
 .../iotdb/tsfile/read/ReadOnlyTsFileTest.java      | 49 +++++++++++++++++-----
 .../iotdb/tsfile/utils/TsFileGeneratorForTest.java | 19 +++++----
 3 files changed, 51 insertions(+), 19 deletions(-)

diff --git 
a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/query/dataset/DataSetWithoutTimeGenerator.java
 
b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/query/dataset/DataSetWithoutTimeGenerator.java
index 80af768..fd2346a 100644
--- 
a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/query/dataset/DataSetWithoutTimeGenerator.java
+++ 
b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/query/dataset/DataSetWithoutTimeGenerator.java
@@ -113,7 +113,7 @@ public class DataSetWithoutTimeGenerator extends 
QueryDataSet {
 
       BatchData data = batchDataList.get(i);
 
-      if (data.currentTime() == minTime) {
+      if (data.hasNext() && data.currentTime() == minTime) {
         putValueToField(data, field);
         data.next();
 
diff --git 
a/tsfile/src/test/java/org/apache/iotdb/tsfile/read/ReadOnlyTsFileTest.java 
b/tsfile/src/test/java/org/apache/iotdb/tsfile/read/ReadOnlyTsFileTest.java
index ff8f8b2..3f34fc8 100644
--- a/tsfile/src/test/java/org/apache/iotdb/tsfile/read/ReadOnlyTsFileTest.java
+++ b/tsfile/src/test/java/org/apache/iotdb/tsfile/read/ReadOnlyTsFileTest.java
@@ -19,6 +19,7 @@
 package org.apache.iotdb.tsfile.read;
 
 import java.io.IOException;
+import java.util.ArrayList;
 import org.apache.iotdb.tsfile.common.conf.TSFileDescriptor;
 import org.apache.iotdb.tsfile.exception.write.WriteProcessException;
 import org.apache.iotdb.tsfile.read.common.Path;
@@ -35,34 +36,28 @@ import 
org.apache.iotdb.tsfile.read.filter.factory.FilterFactory;
 import org.apache.iotdb.tsfile.read.query.dataset.QueryDataSet;
 import org.apache.iotdb.tsfile.utils.Binary;
 import org.apache.iotdb.tsfile.utils.TsFileGeneratorForTest;
-import org.junit.After;
 import org.junit.Assert;
-import org.junit.Before;
 import org.junit.Test;
 
 public class ReadOnlyTsFileTest {
 
   private static final String FILE_PATH = 
TsFileGeneratorForTest.outputDataFile;
   private TsFileSequenceReader fileReader;
-  private int rowCount = 1000;
   private ReadOnlyTsFile tsFile;
 
-  @Before
-  public void before() throws InterruptedException, WriteProcessException, 
IOException {
+  @Test
+  public void test1() throws InterruptedException, WriteProcessException, 
IOException {
     TSFileDescriptor.getInstance().getConfig().timeSeriesEncoder = "TS_2DIFF";
+    int rowCount = 1000;
     TsFileGeneratorForTest.generateFile(rowCount, 16 * 1024 * 1024, 10000);
     fileReader = new TsFileSequenceReader(FILE_PATH);
     tsFile = new ReadOnlyTsFile(fileReader);
-  }
-
-  @After
-  public void after() throws IOException {
+    queryTest(rowCount);
     tsFile.close();
     TsFileGeneratorForTest.after();
   }
 
-  @Test
-  public void queryTest() throws IOException {
+  private void queryTest(int rowCount) throws IOException {
     Filter filter = TimeFilter.lt(1480562618100L);
     Filter filter2 = ValueFilter.gt(new Binary("dog"));
     Filter filter3 = FilterFactory
@@ -111,6 +106,38 @@ public class ReadOnlyTsFileTest {
       count++;
     }
     Assert.assertEquals(101, count);
+  }
 
+  @Test
+  public void test2() throws InterruptedException, WriteProcessException, 
IOException {
+    int minRowCount = 1000, maxRowCount=100000;
+    TSFileDescriptor.getInstance().getConfig().timeSeriesEncoder = "TS_2DIFF";
+    TsFileGeneratorForTest.generateFile(minRowCount, maxRowCount, 16 * 1024 * 
1024, 10000);
+    fileReader = new TsFileSequenceReader(FILE_PATH);
+    tsFile = new ReadOnlyTsFile(fileReader);
+    queryTest2();
+    tsFile.close();
+    TsFileGeneratorForTest.after();
+  }
+
+  void queryTest2() throws IOException {
+    ArrayList<Path> paths = new ArrayList<>();
+    paths.add(new Path("d1.s6"));
+    paths.add(new Path("d2.s1"));
+
+    IExpression expression = new 
GlobalTimeExpression(TimeFilter.gt(1480562664760L));
+
+    QueryExpression queryExpression = QueryExpression.create(paths, 
expression);
+
+    QueryDataSet queryDataSet = tsFile.query(queryExpression);
+
+    int cnt = 0;
+    while (queryDataSet.hasNext()) {
+      RowRecord r = queryDataSet.next();
+      //System.out.println(r);
+      cnt++;
+    }
+    Assert.assertEquals(10647, cnt);
   }
 }
+
diff --git 
a/tsfile/src/test/java/org/apache/iotdb/tsfile/utils/TsFileGeneratorForTest.java
 
b/tsfile/src/test/java/org/apache/iotdb/tsfile/utils/TsFileGeneratorForTest.java
index 064f1cc..757ff79 100755
--- 
a/tsfile/src/test/java/org/apache/iotdb/tsfile/utils/TsFileGeneratorForTest.java
+++ 
b/tsfile/src/test/java/org/apache/iotdb/tsfile/utils/TsFileGeneratorForTest.java
@@ -59,17 +59,22 @@ public class TsFileGeneratorForTest {
 
   public static void generateFile(int rowCount, int chunkGroupSize, int 
pageSize)
       throws IOException, InterruptedException, WriteProcessException {
-    TsFileGeneratorForTest.rowCount = rowCount;
+    generateFile(rowCount, rowCount, chunkGroupSize, pageSize);
+  }
+
+  public static void generateFile(int minRowCount, int maxRowCount,int 
chunkGroupSize, int pageSize)
+      throws IOException, InterruptedException, WriteProcessException {
+    TsFileGeneratorForTest.rowCount = maxRowCount;
     TsFileGeneratorForTest.chunkGroupSize = chunkGroupSize;
     TsFileGeneratorForTest.pageSize = pageSize;
-    prepare();
+    prepare(minRowCount, maxRowCount);
     write();
   }
 
-  public static void prepare() throws IOException {
+  public static void prepare(int minrowCount, int maxRowCount) throws 
IOException {
     inputDataFile = "src/test/resources/perTestInputData";
     errorOutputDataFile = "src/test/resources/perTestErrorOutputData.tsfile";
-    generateSampleInputDataFile();
+    generateSampleInputDataFile(minrowCount, maxRowCount);
   }
 
   public static void after() {
@@ -87,7 +92,7 @@ public class TsFileGeneratorForTest {
     }
   }
 
-  static private void generateSampleInputDataFile() throws IOException {
+  static private void generateSampleInputDataFile(int minRowCount, int 
maxRowCount) throws IOException {
     File file = new File(inputDataFile);
     if (file.exists()) {
       file.delete();
@@ -96,7 +101,7 @@ public class TsFileGeneratorForTest {
     FileWriter fw = new FileWriter(file);
 
     long startTime = START_TIMESTAMP;
-    for (int i = 0; i < rowCount; i++) {
+    for (int i = 0; i < maxRowCount; i++) {
       // write d1
       String d1 = "d1," + (startTime + i) + ",s1," + (i * 10 + 1) + ",s2," + 
(i * 10 + 2);
       if (i % 5 == 0) {
@@ -108,7 +113,7 @@ public class TsFileGeneratorForTest {
       if (i % 9 == 0) {
         d1 += ",s5," + "false";
       }
-      if (i % 10 == 0) {
+      if (i % 10 == 0 && i < minRowCount) {
         d1 += ",s6," + ((int) (i / 9.0) * 100) / 100.0;
       }
       if (i % 11 == 0) {

Reply via email to