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

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


The following commit(s) were added to 
refs/heads/value_filter_query_optimization by this push:
     new a16bbe2  add test
a16bbe2 is described below

commit a16bbe23f98caa1787b7f15d6be11a8d29fb1666
Author: suyue <[email protected]>
AuthorDate: Tue Mar 5 19:01:10 2019 +0800

    add test
---
 .../sequence/SequenceDataReaderByTimestamp.java    | 32 +++++---
 .../sequence/UnSealedTsFilesReaderByTimestamp.java | 22 ++---
 .../query/reader/FakedSeriesReaderByTimestamp.java | 83 +++++++++++++++++++
 .../merge/PriorityMergeReaderByTimestampTest.java  |  4 +
 .../SequenceDataReaderByTimestampTest.java         | 94 ++++++++++++++++++++++
 5 files changed, 217 insertions(+), 18 deletions(-)

diff --git 
a/iotdb/src/main/java/org/apache/iotdb/db/query/reader/sequence/SequenceDataReaderByTimestamp.java
 
b/iotdb/src/main/java/org/apache/iotdb/db/query/reader/sequence/SequenceDataReaderByTimestamp.java
index beaecb6..cf63426 100644
--- 
a/iotdb/src/main/java/org/apache/iotdb/db/query/reader/sequence/SequenceDataReaderByTimestamp.java
+++ 
b/iotdb/src/main/java/org/apache/iotdb/db/query/reader/sequence/SequenceDataReaderByTimestamp.java
@@ -1,15 +1,19 @@
 /**
- * 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
+ * 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
+ *     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
+ * 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.
  */
 
@@ -57,6 +61,16 @@ public class SequenceDataReaderByTimestamp implements 
EngineReaderByTimeStamp {
 
   }
 
+  /**
+   * This method is used only in unit test.
+   * @param seriesReaders
+   */
+  public SequenceDataReaderByTimestamp(List<EngineReaderByTimeStamp> 
seriesReaders){
+    this.seriesReaders = seriesReaders;
+    nextSeriesReaderIndex = 0;
+  }
+
+
   @Override
   public Object getValueInTimestamp(long timestamp) throws IOException {
     Object value = null;
diff --git 
a/iotdb/src/main/java/org/apache/iotdb/db/query/reader/sequence/UnSealedTsFilesReaderByTimestamp.java
 
b/iotdb/src/main/java/org/apache/iotdb/db/query/reader/sequence/UnSealedTsFilesReaderByTimestamp.java
index bf73bee..4cd0dfb 100644
--- 
a/iotdb/src/main/java/org/apache/iotdb/db/query/reader/sequence/UnSealedTsFilesReaderByTimestamp.java
+++ 
b/iotdb/src/main/java/org/apache/iotdb/db/query/reader/sequence/UnSealedTsFilesReaderByTimestamp.java
@@ -1,15 +1,19 @@
 /**
- * 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
+ * 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
+ *     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
+ * 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.
  */
 
diff --git 
a/iotdb/src/test/java/org/apache/iotdb/db/query/reader/FakedSeriesReaderByTimestamp.java
 
b/iotdb/src/test/java/org/apache/iotdb/db/query/reader/FakedSeriesReaderByTimestamp.java
new file mode 100644
index 0000000..ae7f496
--- /dev/null
+++ 
b/iotdb/src/test/java/org/apache/iotdb/db/query/reader/FakedSeriesReaderByTimestamp.java
@@ -0,0 +1,83 @@
+/**
+ * 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.db.query.reader;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import org.apache.iotdb.db.query.reader.merge.EngineReaderByTimeStamp;
+import org.apache.iotdb.db.utils.TimeValuePair;
+import org.apache.iotdb.db.utils.TsPrimitiveType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+
+public class FakedSeriesReaderByTimestamp implements EngineReaderByTimeStamp {
+  private Iterator<TimeValuePair> iterator;
+  private boolean hasCachedTimeValuePair = false;
+  private TimeValuePair cachedTimeValuePair;
+
+  public FakedSeriesReaderByTimestamp(long startTime, int size, int interval, 
int modValue) {
+    long time = startTime;
+    List<TimeValuePair> list = new ArrayList<>();
+    for (int i = 0; i < size; i++) {
+      list.add(
+          new TimeValuePair(time, TsPrimitiveType.getByType(TSDataType.INT64, 
time % modValue)));
+      time += interval;
+    }
+    iterator = list.iterator();
+  }
+
+  @Override
+  public Object getValueInTimestamp(long timestamp) throws IOException {
+    if(hasCachedTimeValuePair){
+      if(timestamp == cachedTimeValuePair.getTimestamp()){
+        hasCachedTimeValuePair = false;
+        return cachedTimeValuePair.getValue().getValue();
+      }
+      else if(timestamp > cachedTimeValuePair.getTimestamp()){
+        hasCachedTimeValuePair = false;
+      }
+      else {
+        return null;
+      }
+    }
+    while(iterator.hasNext()){
+      cachedTimeValuePair = iterator.next();
+      if(timestamp == cachedTimeValuePair.getTimestamp()){
+        return cachedTimeValuePair.getValue().getValue();
+      }
+      else if(timestamp < cachedTimeValuePair.getTimestamp()){
+        hasCachedTimeValuePair = true;
+        break;
+      }
+    }
+    return null;
+  }
+
+  @Override
+  public boolean hasNext() throws IOException {
+    return hasCachedTimeValuePair || iterator.hasNext();
+  }
+
+  @Override
+  public void close() throws IOException {
+
+  }
+}
diff --git 
a/iotdb/src/test/java/org/apache/iotdb/db/query/reader/merge/PriorityMergeReaderByTimestampTest.java
 
b/iotdb/src/test/java/org/apache/iotdb/db/query/reader/merge/PriorityMergeReaderByTimestampTest.java
index 9593f31..2a5104c 100644
--- 
a/iotdb/src/test/java/org/apache/iotdb/db/query/reader/merge/PriorityMergeReaderByTimestampTest.java
+++ 
b/iotdb/src/test/java/org/apache/iotdb/db/query/reader/merge/PriorityMergeReaderByTimestampTest.java
@@ -53,6 +53,10 @@ public class PriorityMergeReaderByTimestampTest {
     Random random = new Random();
     for (long time = 4; time < 1080 + 200 * 13 + 600; ) {
       Long value = (Long) priorityReader.getValueInTimestamp(time);
+      if(time < 1080 + 199 * 13){
+        Assert.assertTrue(priorityReader.hasNext());
+      }
+
       //System.out.println("time = " + time + " value = " + value);
       if (time < 100) {
         // null
diff --git 
a/iotdb/src/test/java/org/apache/iotdb/db/query/reader/sequence/SequenceDataReaderByTimestampTest.java
 
b/iotdb/src/test/java/org/apache/iotdb/db/query/reader/sequence/SequenceDataReaderByTimestampTest.java
new file mode 100644
index 0000000..6706653
--- /dev/null
+++ 
b/iotdb/src/test/java/org/apache/iotdb/db/query/reader/sequence/SequenceDataReaderByTimestampTest.java
@@ -0,0 +1,94 @@
+/**
+ * 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.db.query.reader.sequence;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+import org.apache.iotdb.db.query.reader.FakedSeriesReaderByTimestamp;
+import org.apache.iotdb.db.query.reader.merge.EngineReaderByTimeStamp;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class SequenceDataReaderByTimestampTest {
+
+  /**
+   * Test hasNext() and getValueInTimestamp(long timestamp) method in 
SequenceDataReaderByTimestamp.
+   */
+  @Test
+  public void text() throws IOException {
+    List<EngineReaderByTimeStamp> readers = new ArrayList<>();
+    FakedSeriesReaderByTimestamp sealedTsFile = new 
FakedSeriesReaderByTimestamp(100,1000, 7, 11);
+    FakedSeriesReaderByTimestamp unsealedTsFile = new 
FakedSeriesReaderByTimestamp(100 + 1005 *7,100, 17, 3);
+    FakedSeriesReaderByTimestamp dataInMemory = new 
FakedSeriesReaderByTimestamp(100 + 1005 *7 + 100 * 17,60, 19, 23);
+    readers.add(sealedTsFile);
+    readers.add(unsealedTsFile);
+    readers.add(dataInMemory);
+    SequenceDataReaderByTimestamp sequenceReader = new 
SequenceDataReaderByTimestamp(readers);
+
+    long startTime = 100l;
+    long endTime = 100 + 1005 *7 + 100 * 17 + 59 * 19;
+    Random random = new Random();
+    for(long time = startTime - 50; time < endTime + 50; time++){
+      if(time < endTime){
+        Assert.assertTrue(sequenceReader.hasNext());
+      }
+      time += 1 + random.nextInt(10);
+      Object value = sequenceReader.getValueInTimestamp(time);
+      if(time < 100){
+        Assert.assertNull(value);
+      }
+      //sealed tsfile
+      else if(time < 100 + 1005 *7){
+        if((time - 100) % 7 != 0 || time > 100 + 999*7){
+          Assert.assertNull(value);
+        }
+        else {
+          Assert.assertEquals(time % 11, value);
+        }
+      }
+      //unsealed tsfile
+      else if(time < 100 + 1005 *7 + 100 * 17){
+        if((time - (100 + 1005 *7)) % 17 != 0 ){
+          Assert.assertNull(value);
+        }
+        else {
+          Assert.assertEquals(time % 3, value);
+        }
+      }
+      //memory data
+      else if(time < 100 + 1005 *7 + 100 * 17 + 60 * 19){
+        if((time - (100 + 1005 *7 + 100 * 17)) % 19 != 0 ){
+          Assert.assertNull(value);
+        }
+        else {
+          Assert.assertEquals(time % 23, value);
+        }
+      }
+      else {
+        Assert.assertNull(value);
+      }
+    }
+
+
+  }
+
+}

Reply via email to