You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by su...@apache.org on 2019/06/24 01:27:52 UTC

[incubator-iotdb] branch feature_async_close_tsfile updated: add unseq tests (#202)

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

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


The following commit(s) were added to refs/heads/feature_async_close_tsfile by this push:
     new 1383ad3  add unseq tests (#202)
1383ad3 is described below

commit 1383ad3861e94a711f2a90f3ab27e59a445cae26
Author: RUI, LEI <33...@users.noreply.github.com>
AuthorDate: Mon Jun 24 09:27:48 2019 +0800

    add unseq tests (#202)
---
 .../reader/merge/EngineReaderByTimeStamp.java      |  3 +
 ...reateByTimestampReadersOfSelectedPathsTest.java | 97 ++++++++++++++++++++++
 .../query/reader/unsequence/UnseqReaderTest.java   | 89 ++++++++++++++++++++
 3 files changed, 189 insertions(+)

diff --git a/iotdb/src/main/java/org/apache/iotdb/db/query/reader/merge/EngineReaderByTimeStamp.java b/iotdb/src/main/java/org/apache/iotdb/db/query/reader/merge/EngineReaderByTimeStamp.java
index 65a8849..93daff8 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/query/reader/merge/EngineReaderByTimeStamp.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/query/reader/merge/EngineReaderByTimeStamp.java
@@ -25,6 +25,9 @@ public interface EngineReaderByTimeStamp {
   /**
    * Given a timestamp, the reader is supposed to return the corresponding value in the timestamp.
    * If no value in this timestamp, null will be returned.
+   *
+   * Note that when the higher layer needs to call this function multiple times, it is required that the timestamps
+   * be in strictly increasing order.
    */
   Object getValueInTimestamp(long timestamp) throws IOException;
 
diff --git a/iotdb/src/test/java/org/apache/iotdb/db/query/reader/unsequence/CreateByTimestampReadersOfSelectedPathsTest.java b/iotdb/src/test/java/org/apache/iotdb/db/query/reader/unsequence/CreateByTimestampReadersOfSelectedPathsTest.java
new file mode 100644
index 0000000..6a712fd
--- /dev/null
+++ b/iotdb/src/test/java/org/apache/iotdb/db/query/reader/unsequence/CreateByTimestampReadersOfSelectedPathsTest.java
@@ -0,0 +1,97 @@
+/**
+ * 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.unsequence;
+
+import org.apache.iotdb.db.engine.MetadataManagerHelper;
+import org.apache.iotdb.db.engine.filenodeV2.FileNodeManagerV2;
+import org.apache.iotdb.db.exception.FileNodeManagerException;
+import org.apache.iotdb.db.qp.physical.crud.InsertPlan;
+import org.apache.iotdb.db.query.factory.SeriesReaderFactoryImpl;
+import org.apache.iotdb.db.query.reader.merge.EngineReaderByTimeStamp;
+import org.apache.iotdb.db.utils.EnvironmentUtils;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.read.common.Path;
+import org.apache.iotdb.tsfile.write.record.TSRecord;
+import org.apache.iotdb.tsfile.write.record.datapoint.DataPoint;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class CreateByTimestampReadersOfSelectedPathsTest {
+    private String systemDir = "data/info";
+    private String deviceId = "root.vehicle.d0";
+    private String measurementId = "s0";
+
+    @Before
+    public void setUp() throws Exception {
+        MetadataManagerHelper.initMetadata();
+        EnvironmentUtils.envSetUp();
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        EnvironmentUtils.cleanEnv();
+        EnvironmentUtils.cleanDir(systemDir);
+    }
+
+    @Test
+    public void testUnSeqReaderWithoutFilter() throws IOException, FileNodeManagerException {
+        // write
+        for (int j = 1; j <= 10; j++) {
+            TSRecord record = new TSRecord(j, deviceId);
+            record.addTuple(DataPoint.getDataPoint(TSDataType.INT32, measurementId, String.valueOf(j)));
+            FileNodeManagerV2.getInstance().insert(new InsertPlan(record));
+            FileNodeManagerV2.getInstance().asyncFlushAndSealAllFiles();
+        }
+
+        for (int j = 10; j >= 1; j--) {
+            TSRecord record = new TSRecord(j, deviceId);
+            record.addTuple(DataPoint.getDataPoint(TSDataType.INT32, measurementId, String.valueOf(j)));
+            FileNodeManagerV2.getInstance().insert(new InsertPlan(record));
+            FileNodeManagerV2.getInstance().asyncFlushAndSealAllFiles();
+        }
+        TSRecord record = new TSRecord(2, deviceId);
+        record.addTuple(DataPoint.getDataPoint(TSDataType.INT32, measurementId, String.valueOf(100)));
+        FileNodeManagerV2.getInstance().insert(new InsertPlan(record));
+        FileNodeManagerV2.getInstance().asyncFlushAndSealAllFiles();
+
+        // query
+        List<Path> paths = new ArrayList<>();
+        paths.add(new Path(deviceId, measurementId));
+        List<EngineReaderByTimeStamp> readers = SeriesReaderFactoryImpl.getInstance().
+                createByTimestampReadersOfSelectedPaths(paths, EnvironmentUtils.TEST_QUERY_CONTEXT);
+        Assert.assertEquals(1, readers.size());
+        EngineReaderByTimeStamp reader = readers.get(0);
+
+        for (long time = 1; time <= 10; time++) {
+            // NOTE that the timestamps should be in be in strictly increasing order.
+            int value = (Integer) reader.getValueInTimestamp(time);
+            if (time == 2) {
+                Assert.assertEquals(100, value);
+            } else {
+                Assert.assertEquals(time, value);
+            }
+        }
+    }
+}
diff --git a/iotdb/src/test/java/org/apache/iotdb/db/query/reader/unsequence/UnseqReaderTest.java b/iotdb/src/test/java/org/apache/iotdb/db/query/reader/unsequence/UnseqReaderTest.java
new file mode 100644
index 0000000..e838d63
--- /dev/null
+++ b/iotdb/src/test/java/org/apache/iotdb/db/query/reader/unsequence/UnseqReaderTest.java
@@ -0,0 +1,89 @@
+/**
+ * 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.unsequence;
+
+import org.apache.iotdb.db.engine.querycontext.QueryDataSourceV2;
+import org.apache.iotdb.db.query.factory.SeriesReaderFactoryImpl;
+import org.apache.iotdb.db.query.reader.IPointReader;
+import org.apache.iotdb.db.query.reader.ReaderTestHelper;
+import org.apache.iotdb.db.utils.EnvironmentUtils;
+import org.apache.iotdb.db.utils.TimeValuePair;
+import org.apache.iotdb.tsfile.read.common.Path;
+import org.apache.iotdb.tsfile.read.filter.TimeFilter;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.IOException;
+
+public class UnseqReaderTest extends ReaderTestHelper {
+    @Override
+    protected void insertData() {
+        for (int j = 1; j <= 10; j++) {
+            insertOneRecord(j, j);
+        }
+        fileNodeProcessorV2.getWorkSequenceTsFileProcessor().asyncFlush();
+
+        for (int j = 10; j >= 1; j--) {
+            insertOneRecord(j, j);
+        }
+        fileNodeProcessorV2.getWorkSequenceTsFileProcessor().asyncFlush();
+
+        insertOneRecord(2, 100);
+    }
+
+    @Test
+    public void testUnSeqReaderWithGlobalTimeFilter() throws IOException {
+        Path path = new Path(deviceId, measurementId);
+        QueryDataSourceV2 queryDataSource = fileNodeProcessorV2.query(deviceId, measurementId);
+        IPointReader reader = SeriesReaderFactoryImpl.getInstance().createUnSeqReader(path,
+                queryDataSource.getUnseqResources(), EnvironmentUtils.TEST_QUERY_CONTEXT, TimeFilter.eq(4));
+        int cnt = 0;
+        while (reader.hasNext()) {
+            cnt++;
+            TimeValuePair timeValuePair = reader.next();
+            Assert.assertEquals(4, timeValuePair.getTimestamp());
+            Assert.assertEquals(4, timeValuePair.getValue().getInt());
+        }
+        Assert.assertEquals(1, cnt);
+    }
+
+    @Test
+    public void testUnSeqReaderWithoutFilter() throws IOException {
+        Path path = new Path(deviceId, measurementId);
+        QueryDataSourceV2 queryDataSource = fileNodeProcessorV2.query(deviceId, measurementId);
+        IPointReader reader = SeriesReaderFactoryImpl.getInstance().createUnSeqReader(path,
+                queryDataSource.getUnseqResources(), EnvironmentUtils.TEST_QUERY_CONTEXT, null);
+        int cnt = 0;
+        while (reader.hasNext()) {
+            cnt++;
+            TimeValuePair timeValuePair = reader.next();
+            if (cnt == 2) {
+                Assert.assertEquals(2, timeValuePair.getTimestamp());
+                Assert.assertEquals(100, timeValuePair.getValue().getInt());
+            } else {
+                Assert.assertEquals(cnt, timeValuePair.getTimestamp());
+                Assert.assertEquals(cnt, timeValuePair.getValue().getInt());
+            }
+        }
+        Assert.assertEquals(10, cnt);
+    }
+
+    // Note that createUnSeqByTimestampReader is of private use.
+}