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/03/10 08:29:06 UTC
[incubator-iotdb] branch aggregate created (now cfa2b65)
This is an automated email from the ASF dual-hosted git repository.
suyue pushed a change to branch aggregate
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git.
at cfa2b65 realize aggregate function interface
This branch includes the following new commits:
new 5979aff realize reader for aggregation
new cfa2b65 realize aggregate function interface
The 2 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/02: realize reader for aggregation
Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
suyue pushed a commit to branch aggregate
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git
commit 5979aff5f3252af7ef4679a17ab7d8a41c446bf8
Author: suyue <23...@qq.com>
AuthorDate: Sat Mar 9 20:35:38 2019 +0800
realize reader for aggregation
---
.../dataset/EngineDataSetWithoutTimeGenerator.java | 12 +-
.../executor/EngineExecutorWithTimeGenerator.java | 13 +-
.../EngineExecutorWithoutTimeGenerator.java | 33 ++-
.../db/query/factory/SeriesReaderFactory.java | 36 ++-
.../iotdb/db/query/reader/AllDataReader.java | 125 +++++++++
.../reader/{IReader.java => IAggregateReader.java} | 28 +-
.../reader/{IReader.java => IBatchReader.java} | 18 +-
.../reader/{IReader.java => IPointReader.java} | 16 +-
.../org/apache/iotdb/db/query/reader/IReader.java | 9 +-
...nkReaderWithFilter.java => MemChunkReader.java} | 58 ++++-
.../reader/mem/MemChunkReaderByTimestamp.java | 22 +-
.../reader/mem/MemChunkReaderWithoutFilter.java | 70 -----
.../db/query/reader/merge/PriorityMergeReader.java | 56 ++--
.../merge/PriorityMergeReaderByTimestamp.java | 1 +
.../query/reader/sequence/SealedTsFilesReader.java | 108 +++-----
.../query/reader/sequence/SequenceDataReader.java | 48 ++--
.../reader/sequence/UnSealedTsFileReader.java | 44 +---
.../query/reader/unsequence/EngineChunkReader.java | 39 +--
.../db/query/timegenerator/EngineLeafNode.java | 19 +-
.../query/timegenerator/EngineNodeConstructor.java | 14 +-
iotdb/src/test/java/PerformanceTest.java | 282 +++++++++++++++++++++
.../iotdb/db/query/reader/AllDataReaderTest.java | 77 ++++++
.../iotdb/db/query/reader/FakedIBatchPoint.java | 108 ++++++++
.../iotdb/db/query/reader/FakedIPointReader.java | 75 ++++++
.../query/reader/FakedSeriesReaderByTimestamp.java | 93 +++++++
.../merge/PriorityMergeReaderByTimestampTest.java | 27 +-
.../reader/merge/PriorityMergeReaderTest.java | 23 +-
.../reader/merge/SeriesMergeSortReaderTest.java | 22 +-
.../reader/sequence/SealedTsFilesReaderTest.java} | 32 ++-
.../tsfile/read/reader/chunk/ChunkReader.java | 54 ++--
.../read/reader/series/FileSeriesReader.java | 45 ++--
31 files changed, 1081 insertions(+), 526 deletions(-)
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/query/dataset/EngineDataSetWithoutTimeGenerator.java b/iotdb/src/main/java/org/apache/iotdb/db/query/dataset/EngineDataSetWithoutTimeGenerator.java
index 4c0ccb7..6d78f74 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/query/dataset/EngineDataSetWithoutTimeGenerator.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/query/dataset/EngineDataSetWithoutTimeGenerator.java
@@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
+
package org.apache.iotdb.db.query.dataset;
import java.io.IOException;
@@ -23,6 +24,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Set;
+import org.apache.iotdb.db.query.reader.IPointReader;
import org.apache.iotdb.db.query.reader.IReader;
import org.apache.iotdb.db.utils.TimeValuePair;
import org.apache.iotdb.db.utils.TsPrimitiveType;
@@ -34,11 +36,11 @@ import org.apache.iotdb.tsfile.read.common.RowRecord;
import org.apache.iotdb.tsfile.read.query.dataset.QueryDataSet;
/**
- * TODO implement this class as TsFile DataSetWithoutTimeGenerator
+ * TODO implement this class as TsFile DataSetWithoutTimeGenerator.
*/
public class EngineDataSetWithoutTimeGenerator extends QueryDataSet {
- private List<IReader> readers;
+ private List<IPointReader> readers;
private TimeValuePair[] cacheTimeValueList;
@@ -55,7 +57,7 @@ public class EngineDataSetWithoutTimeGenerator extends QueryDataSet {
* @throws IOException IOException
*/
public EngineDataSetWithoutTimeGenerator(List<Path> paths, List<TSDataType> dataTypes,
- List<IReader> readers)
+ List<IPointReader> readers)
throws IOException {
super(paths, dataTypes);
this.readers = readers;
@@ -68,7 +70,7 @@ public class EngineDataSetWithoutTimeGenerator extends QueryDataSet {
cacheTimeValueList = new TimeValuePair[readers.size()];
for (int i = 0; i < readers.size(); i++) {
- IReader reader = readers.get(i);
+ IPointReader reader = readers.get(i);
if (reader.hasNext()) {
TimeValuePair timeValuePair = reader.next();
cacheTimeValueList[i] = timeValuePair;
@@ -89,7 +91,7 @@ public class EngineDataSetWithoutTimeGenerator extends QueryDataSet {
RowRecord record = new RowRecord(minTime);
for (int i = 0; i < readers.size(); i++) {
- IReader reader = readers.get(i);
+ IPointReader reader = readers.get(i);
if (cacheTimeValueList[i] == null) {
record.addField(new Field(null));
} else {
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/query/executor/EngineExecutorWithTimeGenerator.java b/iotdb/src/main/java/org/apache/iotdb/db/query/executor/EngineExecutorWithTimeGenerator.java
index 13f0053..d5b1740 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/query/executor/EngineExecutorWithTimeGenerator.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/query/executor/EngineExecutorWithTimeGenerator.java
@@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
+
package org.apache.iotdb.db.query.executor;
import java.io.IOException;
@@ -30,6 +31,7 @@ import org.apache.iotdb.db.query.control.QueryDataSourceManager;
import org.apache.iotdb.db.query.control.QueryTokenManager;
import org.apache.iotdb.db.query.dataset.EngineDataSetWithTimeGenerator;
import org.apache.iotdb.db.query.factory.SeriesReaderFactory;
+import org.apache.iotdb.db.query.reader.AllDataReader;
import org.apache.iotdb.db.query.reader.merge.EngineReaderByTimeStamp;
import org.apache.iotdb.db.query.reader.merge.PriorityMergeReader;
import org.apache.iotdb.db.query.reader.merge.PriorityMergeReaderByTimestamp;
@@ -108,12 +110,19 @@ public class EngineExecutorWithTimeGenerator {
// reader for sequence data
SequenceDataReader tsFilesReader = new SequenceDataReader(queryDataSource.getSeqDataSource(),
null, context);
- mergeReaderByTimestamp.addReaderWithPriority(tsFilesReader, 1);
// reader for unSequence data
PriorityMergeReader unSeqMergeReader = SeriesReaderFactory.getInstance()
.createUnSeqMergeReader(queryDataSource.getOverflowSeriesDataSource(), null);
- mergeReaderByTimestamp.addReaderWithPriority(unSeqMergeReader, 2);
+
+ if (tsFilesReader == null || !tsFilesReader.hasNext()) {
+ mergeReaderByTimestamp
+ .addReaderWithPriority(unSeqMergeReader, PriorityMergeReader.HIGH_PRIORITY);
+ } else {
+ mergeReaderByTimestamp
+ .addReaderWithPriority(new AllDataReader(tsFilesReader, unSeqMergeReader),
+ PriorityMergeReader.HIGH_PRIORITY);
+ }
readersOfSelectedSeries.add(mergeReaderByTimestamp);
}
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/query/executor/EngineExecutorWithoutTimeGenerator.java b/iotdb/src/main/java/org/apache/iotdb/db/query/executor/EngineExecutorWithoutTimeGenerator.java
index 11c94bc..6eb300e 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/query/executor/EngineExecutorWithoutTimeGenerator.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/query/executor/EngineExecutorWithoutTimeGenerator.java
@@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
+
package org.apache.iotdb.db.query.executor;
import java.io.IOException;
@@ -30,7 +31,8 @@ import org.apache.iotdb.db.query.control.QueryDataSourceManager;
import org.apache.iotdb.db.query.control.QueryTokenManager;
import org.apache.iotdb.db.query.dataset.EngineDataSetWithoutTimeGenerator;
import org.apache.iotdb.db.query.factory.SeriesReaderFactory;
-import org.apache.iotdb.db.query.reader.IReader;
+import org.apache.iotdb.db.query.reader.AllDataReader;
+import org.apache.iotdb.db.query.reader.IPointReader;
import org.apache.iotdb.db.query.reader.merge.PriorityMergeReader;
import org.apache.iotdb.db.query.reader.sequence.SequenceDataReader;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
@@ -61,7 +63,7 @@ public class EngineExecutorWithoutTimeGenerator {
Filter timeFilter = ((GlobalTimeExpression) queryExpression.getExpression()).getFilter();
- List<IReader> readersOfSelectedSeries = new ArrayList<>();
+ List<IPointReader> readersOfSelectedSeries = new ArrayList<>();
List<TSDataType> dataTypes = new ArrayList<>();
QueryTokenManager.getInstance()
@@ -79,14 +81,11 @@ public class EngineExecutorWithoutTimeGenerator {
throw new FileNodeManagerException(e);
}
- PriorityMergeReader priorityReader = new PriorityMergeReader();
-
// sequence reader for one sealed tsfile
SequenceDataReader tsFilesReader;
try {
tsFilesReader = new SequenceDataReader(queryDataSource.getSeqDataSource(),
timeFilter, context);
- priorityReader.addReaderWithPriority(tsFilesReader, PriorityMergeReader.LOW_PRIORITY);
} catch (IOException e) {
throw new FileNodeManagerException(e);
}
@@ -96,12 +95,18 @@ public class EngineExecutorWithoutTimeGenerator {
try {
unSeqMergeReader = SeriesReaderFactory.getInstance()
.createUnSeqMergeReader(queryDataSource.getOverflowSeriesDataSource(), timeFilter);
- priorityReader.addReaderWithPriority(unSeqMergeReader, PriorityMergeReader.HIGH_PRIORITY);
} catch (IOException e) {
throw new FileNodeManagerException(e);
}
- readersOfSelectedSeries.add(priorityReader);
+ if (tsFilesReader == null) {
+ //only have unsequence data.
+ readersOfSelectedSeries.add(unSeqMergeReader);
+ } else {
+ //merge sequence data with unsequence data.
+ readersOfSelectedSeries.add(new AllDataReader(tsFilesReader, unSeqMergeReader));
+ }
+
}
try {
@@ -118,7 +123,7 @@ public class EngineExecutorWithoutTimeGenerator {
public QueryDataSet executeWithoutFilter(QueryContext context)
throws FileNodeManagerException {
- List<IReader> readersOfSelectedSeries = new ArrayList<>();
+ List<IPointReader> readersOfSelectedSeries = new ArrayList<>();
List<TSDataType> dataTypes = new ArrayList<>();
QueryTokenManager.getInstance()
@@ -136,14 +141,11 @@ public class EngineExecutorWithoutTimeGenerator {
throw new FileNodeManagerException(e);
}
- PriorityMergeReader priorityReader = new PriorityMergeReader();
-
// sequence insert data
SequenceDataReader tsFilesReader;
try {
tsFilesReader = new SequenceDataReader(queryDataSource.getSeqDataSource(),
null, context);
- priorityReader.addReaderWithPriority(tsFilesReader, 1);
} catch (IOException e) {
throw new FileNodeManagerException(e);
}
@@ -153,12 +155,17 @@ public class EngineExecutorWithoutTimeGenerator {
try {
unSeqMergeReader = SeriesReaderFactory.getInstance()
.createUnSeqMergeReader(queryDataSource.getOverflowSeriesDataSource(), null);
- priorityReader.addReaderWithPriority(unSeqMergeReader, 2);
} catch (IOException e) {
throw new FileNodeManagerException(e);
}
- readersOfSelectedSeries.add(priorityReader);
+ if (tsFilesReader == null) {
+ //only have unsequence data.
+ readersOfSelectedSeries.add(unSeqMergeReader);
+ } else {
+ //merge sequence data with unsequence data.
+ readersOfSelectedSeries.add(new AllDataReader(tsFilesReader, unSeqMergeReader));
+ }
}
try {
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/query/factory/SeriesReaderFactory.java b/iotdb/src/main/java/org/apache/iotdb/db/query/factory/SeriesReaderFactory.java
index 51ce94b..e20c009 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/query/factory/SeriesReaderFactory.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/query/factory/SeriesReaderFactory.java
@@ -27,9 +27,11 @@ import org.apache.iotdb.db.engine.querycontext.OverflowInsertFile;
import org.apache.iotdb.db.engine.querycontext.OverflowSeriesDataSource;
import org.apache.iotdb.db.query.context.QueryContext;
import org.apache.iotdb.db.query.control.FileReaderManager;
+import org.apache.iotdb.db.query.reader.AllDataReader;
+import org.apache.iotdb.db.query.reader.IBatchReader;
+import org.apache.iotdb.db.query.reader.IPointReader;
import org.apache.iotdb.db.query.reader.IReader;
-import org.apache.iotdb.db.query.reader.mem.MemChunkReaderWithFilter;
-import org.apache.iotdb.db.query.reader.mem.MemChunkReaderWithoutFilter;
+import org.apache.iotdb.db.query.reader.mem.MemChunkReader;
import org.apache.iotdb.db.query.reader.merge.PriorityMergeReader;
import org.apache.iotdb.db.query.reader.sequence.SealedTsFilesReader;
import org.apache.iotdb.db.query.reader.unsequence.EngineChunkReader;
@@ -110,15 +112,9 @@ public class SeriesReaderFactory {
// add reader for MemTable
if (overflowSeriesDataSource.hasRawChunk()) {
- if (filter != null) {
- unSeqMergeReader.addReaderWithPriority(
- new MemChunkReaderWithFilter(overflowSeriesDataSource.getReadableMemChunk(), filter),
- priorityValue);
- } else {
- unSeqMergeReader.addReaderWithPriority(
- new MemChunkReaderWithoutFilter(overflowSeriesDataSource.getReadableMemChunk()),
- priorityValue);
- }
+ unSeqMergeReader.addReaderWithPriority(
+ new MemChunkReader(overflowSeriesDataSource.getReadableMemChunk(), filter),
+ priorityValue);
}
// TODO add external sort when needed
@@ -141,22 +137,24 @@ public class SeriesReaderFactory {
singleSeriesExpression,
intervalFileNode.getFilePath());
- PriorityMergeReader priorityMergeReader = new PriorityMergeReader();
-
// Sequence reader
- IReader seriesInTsFileReader = createSealedTsFileReaderForMerge(intervalFileNode,
+ IBatchReader seriesInTsFileReader = createSealedTsFileReaderForMerge(intervalFileNode,
singleSeriesExpression, context);
- priorityMergeReader.addReaderWithPriority(seriesInTsFileReader, 1);
// UnSequence merge reader
- IReader unSeqMergeReader = createUnSeqMergeReader(overflowSeriesDataSource,
+ IPointReader unSeqMergeReader = createUnSeqMergeReader(overflowSeriesDataSource,
singleSeriesExpression.getFilter());
- priorityMergeReader.addReaderWithPriority(unSeqMergeReader, 2);
+ if (seriesInTsFileReader == null || !seriesInTsFileReader.hasNext()) {
+ //only have unsequence data.
+ return unSeqMergeReader;
+ } else {
+ //merge sequence data with unsequence data.
+ return new AllDataReader(seriesInTsFileReader, unSeqMergeReader);
+ }
- return priorityMergeReader;
}
- private IReader createSealedTsFileReaderForMerge(IntervalFileNode fileNode,
+ private IBatchReader createSealedTsFileReaderForMerge(IntervalFileNode fileNode,
SingleSeriesExpression singleSeriesExpression,
QueryContext context)
throws IOException {
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/query/reader/AllDataReader.java b/iotdb/src/main/java/org/apache/iotdb/db/query/reader/AllDataReader.java
new file mode 100644
index 0000000..d277c45
--- /dev/null
+++ b/iotdb/src/main/java/org/apache/iotdb/db/query/reader/AllDataReader.java
@@ -0,0 +1,125 @@
+/**
+ * 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 org.apache.iotdb.db.utils.TimeValuePair;
+import org.apache.iotdb.db.utils.TimeValuePairUtils;
+import org.apache.iotdb.tsfile.read.common.BatchData;
+
+public class AllDataReader implements IPointReader {
+
+ private IBatchReader batchReader;
+ private IPointReader pointReader;
+
+ private boolean hasCachedBatchData;
+ private BatchData batchData;
+
+ /**
+ * merge sequence reader, unsequence reader.
+ */
+ public AllDataReader(IBatchReader batchReader, IPointReader pointReader) {
+ this.batchReader = batchReader;
+ this.pointReader = pointReader;
+
+ this.hasCachedBatchData = false;
+ }
+
+ @Override
+ public boolean hasNext() throws IOException {
+ //has value in batchData
+ if (hasCachedBatchData && batchData.hasNext()) {
+ return true;
+ } else {
+ hasCachedBatchData = false;
+ }
+
+ //has value in batchReader
+ while (batchReader.hasNext()) {
+ batchData = batchReader.nextBatch();
+ if (batchData.hasNext()) {
+ hasCachedBatchData = true;
+ return true;
+ }
+ }
+
+ //has value in pointData
+ if (pointReader != null && pointReader.hasNext()) {
+ return true;
+ }
+
+ return false;
+ }
+
+ @Override
+ public TimeValuePair next() throws IOException {
+ //construct batchData, and compare with value in pointReader
+ while (hasCachedBatchData || batchReader.hasNext()) {
+ //if batchData isn't initialization, then initialize it
+ if (!hasCachedBatchData) {
+ if (batchReader.hasNext()) {
+ batchData = batchReader.nextBatch();
+ hasCachedBatchData = true;
+ } else {
+ hasCachedBatchData = false;
+ break;
+ }
+ }
+
+ //if batchData is end, then jump to the entry of the while loop.
+ if (!batchData.hasNext()) {
+ hasCachedBatchData = false;
+ continue;
+ }
+
+ //pointReader has next, compare value in pointReader with value in batchData.
+ if (pointReader != null && pointReader.hasNext()) {
+ long timeInPointReader = pointReader.current().getTimestamp();
+ long timeInBatchData = batchData.currentTime();
+ if (timeInPointReader > timeInBatchData) {
+ TimeValuePair timeValuePair = TimeValuePairUtils.getCurrentTimeValuePair(batchData);
+ batchData.next();
+ return timeValuePair;
+ }
+ if (timeInPointReader == timeInBatchData) {
+ batchData.next();
+ }
+ return pointReader.next();
+ } else {
+ // pointReader doesn't have next time-value pair, return pair in batchData.
+ TimeValuePair timeValuePair = TimeValuePairUtils.getCurrentTimeValuePair(batchData);
+ batchData.next();
+ return timeValuePair;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public TimeValuePair current() throws IOException {
+ throw new IOException("current() in AllDataReader is an empty method.");
+ }
+
+ @Override
+ public void close() throws IOException {
+ batchReader.close();
+ pointReader.close();
+ }
+}
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/query/reader/IReader.java b/iotdb/src/main/java/org/apache/iotdb/db/query/reader/IAggregateReader.java
similarity index 62%
copy from iotdb/src/main/java/org/apache/iotdb/db/query/reader/IReader.java
copy to iotdb/src/main/java/org/apache/iotdb/db/query/reader/IAggregateReader.java
index 6a574d6..edc985f 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/query/reader/IReader.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/query/reader/IAggregateReader.java
@@ -16,29 +16,19 @@
* specific language governing permissions and limitations
* under the License.
*/
+
package org.apache.iotdb.db.query.reader;
import java.io.IOException;
-import org.apache.iotdb.db.utils.TimeValuePair;
-import org.apache.iotdb.tsfile.read.common.BatchData;
-
-/**
- * Vital read interface. Batch method is used to increase query speed. Getting a batch of data
- * a time is faster than getting one point a time.
- */
-public interface IReader {
-
- boolean hasNext() throws IOException;
-
- TimeValuePair next() throws IOException;
-
- void skipCurrentTimeValuePair() throws IOException;
-
- void close() throws IOException;
+import org.apache.iotdb.tsfile.file.header.PageHeader;
- boolean hasNextBatch();
+public interface IAggregateReader extends IBatchReader {
- BatchData nextBatch();
+ /**
+ * Returns meta-information of batch data. If batch data comes from memory, return null. If batch
+ * data comes from page data, return pageHeader.
+ */
+ PageHeader nextPageHeader() throws IOException;
- BatchData currentBatch();
+ void skipPageData() throws IOException;
}
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/query/reader/IReader.java b/iotdb/src/main/java/org/apache/iotdb/db/query/reader/IBatchReader.java
similarity index 71%
copy from iotdb/src/main/java/org/apache/iotdb/db/query/reader/IReader.java
copy to iotdb/src/main/java/org/apache/iotdb/db/query/reader/IBatchReader.java
index 6a574d6..6ca07c2 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/query/reader/IReader.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/query/reader/IBatchReader.java
@@ -16,29 +16,17 @@
* specific language governing permissions and limitations
* under the License.
*/
+
package org.apache.iotdb.db.query.reader;
import java.io.IOException;
-import org.apache.iotdb.db.utils.TimeValuePair;
import org.apache.iotdb.tsfile.read.common.BatchData;
-/**
- * Vital read interface. Batch method is used to increase query speed. Getting a batch of data
- * a time is faster than getting one point a time.
- */
-public interface IReader {
+public interface IBatchReader {
boolean hasNext() throws IOException;
- TimeValuePair next() throws IOException;
-
- void skipCurrentTimeValuePair() throws IOException;
+ BatchData nextBatch() throws IOException;
void close() throws IOException;
-
- boolean hasNextBatch();
-
- BatchData nextBatch();
-
- BatchData currentBatch();
}
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/query/reader/IReader.java b/iotdb/src/main/java/org/apache/iotdb/db/query/reader/IPointReader.java
similarity index 74%
copy from iotdb/src/main/java/org/apache/iotdb/db/query/reader/IReader.java
copy to iotdb/src/main/java/org/apache/iotdb/db/query/reader/IPointReader.java
index 6a574d6..cbd7e3c 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/query/reader/IReader.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/query/reader/IPointReader.java
@@ -16,29 +16,19 @@
* specific language governing permissions and limitations
* under the License.
*/
+
package org.apache.iotdb.db.query.reader;
import java.io.IOException;
import org.apache.iotdb.db.utils.TimeValuePair;
-import org.apache.iotdb.tsfile.read.common.BatchData;
-/**
- * Vital read interface. Batch method is used to increase query speed. Getting a batch of data
- * a time is faster than getting one point a time.
- */
-public interface IReader {
+public interface IPointReader extends IReader {
boolean hasNext() throws IOException;
TimeValuePair next() throws IOException;
- void skipCurrentTimeValuePair() throws IOException;
+ TimeValuePair current() throws IOException;
void close() throws IOException;
-
- boolean hasNextBatch();
-
- BatchData nextBatch();
-
- BatchData currentBatch();
}
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/query/reader/IReader.java b/iotdb/src/main/java/org/apache/iotdb/db/query/reader/IReader.java
index 6a574d6..bdb8d32 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/query/reader/IReader.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/query/reader/IReader.java
@@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
+
package org.apache.iotdb.db.query.reader;
import java.io.IOException;
@@ -32,13 +33,5 @@ public interface IReader {
TimeValuePair next() throws IOException;
- void skipCurrentTimeValuePair() throws IOException;
-
void close() throws IOException;
-
- boolean hasNextBatch();
-
- BatchData nextBatch();
-
- BatchData currentBatch();
}
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/query/reader/mem/MemChunkReaderWithFilter.java b/iotdb/src/main/java/org/apache/iotdb/db/query/reader/mem/MemChunkReader.java
similarity index 54%
rename from iotdb/src/main/java/org/apache/iotdb/db/query/reader/mem/MemChunkReaderWithFilter.java
rename to iotdb/src/main/java/org/apache/iotdb/db/query/reader/mem/MemChunkReader.java
index 1f21a84..fc2bbe8 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/query/reader/mem/MemChunkReaderWithFilter.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/query/reader/mem/MemChunkReader.java
@@ -16,26 +16,37 @@
* specific language governing permissions and limitations
* under the License.
*/
+
package org.apache.iotdb.db.query.reader.mem;
+import java.io.IOException;
import java.util.Iterator;
-import org.apache.iotdb.db.engine.memtable.TimeValuePairSorter;
import org.apache.iotdb.db.engine.querycontext.ReadOnlyMemChunk;
-import org.apache.iotdb.db.query.reader.IReader;
+import org.apache.iotdb.db.query.reader.IAggregateReader;
+import org.apache.iotdb.db.query.reader.IBatchReader;
+import org.apache.iotdb.db.query.reader.IPointReader;
import org.apache.iotdb.db.utils.TimeValuePair;
+import org.apache.iotdb.tsfile.file.header.PageHeader;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
import org.apache.iotdb.tsfile.read.common.BatchData;
import org.apache.iotdb.tsfile.read.filter.basic.Filter;
-public class MemChunkReaderWithFilter implements IReader {
+public class MemChunkReader implements IPointReader, IBatchReader, IAggregateReader {
private Iterator<TimeValuePair> timeValuePairIterator;
private Filter filter;
private boolean hasCachedTimeValuePair;
private TimeValuePair cachedTimeValuePair;
- public MemChunkReaderWithFilter(ReadOnlyMemChunk readableChunk, Filter filter) {
+ private TSDataType dataType;
+
+ /**
+ * memory data reader.
+ */
+ public MemChunkReader(ReadOnlyMemChunk readableChunk, Filter filter) {
timeValuePairIterator = readableChunk.getIterator();
this.filter = filter;
+ this.dataType = readableChunk.getDataType();
}
@Override
@@ -45,7 +56,8 @@ public class MemChunkReaderWithFilter implements IReader {
}
while (timeValuePairIterator.hasNext()) {
TimeValuePair timeValuePair = timeValuePairIterator.next();
- if (filter.satisfy(timeValuePair.getTimestamp(), timeValuePair.getValue().getValue())) {
+ if (filter == null || filter
+ .satisfy(timeValuePair.getTimestamp(), timeValuePair.getValue().getValue())) {
hasCachedTimeValuePair = true;
cachedTimeValuePair = timeValuePair;
break;
@@ -65,27 +77,45 @@ public class MemChunkReaderWithFilter implements IReader {
}
@Override
- public void skipCurrentTimeValuePair() {
- next();
+ public TimeValuePair current() throws IOException {
+ if (!hasCachedTimeValuePair) {
+ cachedTimeValuePair = timeValuePairIterator.next();
+ hasCachedTimeValuePair = true;
+ }
+ return cachedTimeValuePair;
}
@Override
- public void close() {
- // Do nothing because mem chunk reader will not open files
+ public BatchData nextBatch() throws IOException {
+ BatchData batchData = new BatchData(dataType, true);
+ if (hasCachedTimeValuePair) {
+ hasCachedTimeValuePair = false;
+ batchData.putTime(cachedTimeValuePair.getTimestamp());
+ batchData.putAnObject(cachedTimeValuePair.getValue().getValue());
+ }
+ while (timeValuePairIterator.hasNext()) {
+ TimeValuePair timeValuePair = timeValuePairIterator.next();
+ if (filter == null || filter
+ .satisfy(timeValuePair.getTimestamp(), timeValuePair.getValue().getValue())) {
+ batchData.putTime(timeValuePair.getTimestamp());
+ batchData.putAnObject(timeValuePair.getValue().getValue());
+ }
+ }
+ return batchData;
}
@Override
- public boolean hasNextBatch() {
- return false;
+ public void close() {
+ // Do nothing because mem chunk reader will not open files
}
@Override
- public BatchData nextBatch() {
+ public PageHeader nextPageHeader() throws IOException {
return null;
}
@Override
- public BatchData currentBatch() {
- return null;
+ public void skipPageData() throws IOException {
+ nextBatch();
}
}
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/query/reader/mem/MemChunkReaderByTimestamp.java b/iotdb/src/main/java/org/apache/iotdb/db/query/reader/mem/MemChunkReaderByTimestamp.java
index dbd6beb..2db7e0b 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/query/reader/mem/MemChunkReaderByTimestamp.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/query/reader/mem/MemChunkReaderByTimestamp.java
@@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
+
package org.apache.iotdb.db.query.reader.mem;
import java.io.IOException;
@@ -24,7 +25,6 @@ import org.apache.iotdb.db.engine.memtable.TimeValuePairSorter;
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.read.common.BatchData;
public class MemChunkReaderByTimestamp implements EngineReaderByTimeStamp {
@@ -55,11 +55,6 @@ public class MemChunkReaderByTimestamp implements EngineReaderByTimeStamp {
}
@Override
- public void skipCurrentTimeValuePair() throws IOException {
- next();
- }
-
- @Override
public void close() {
// Do nothing because mem chunk reader will not open files
}
@@ -82,19 +77,4 @@ public class MemChunkReaderByTimestamp implements EngineReaderByTimeStamp {
return null;
}
- @Override
- public boolean hasNextBatch() {
- return false;
- }
-
- @Override
- public BatchData nextBatch() {
- return null;
- }
-
- @Override
- public BatchData currentBatch() {
- return null;
- }
-
}
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/query/reader/mem/MemChunkReaderWithoutFilter.java b/iotdb/src/main/java/org/apache/iotdb/db/query/reader/mem/MemChunkReaderWithoutFilter.java
deleted file mode 100644
index bae7496..0000000
--- a/iotdb/src/main/java/org/apache/iotdb/db/query/reader/mem/MemChunkReaderWithoutFilter.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/**
- * 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.mem;
-
-import java.util.Iterator;
-import org.apache.iotdb.db.engine.memtable.TimeValuePairSorter;
-import org.apache.iotdb.db.query.reader.IReader;
-import org.apache.iotdb.db.utils.TimeValuePair;
-import org.apache.iotdb.tsfile.read.common.BatchData;
-
-// TODO merge MemChunkReaderWithoutFilter and MemChunkReaderWithFilter to one class
-public class MemChunkReaderWithoutFilter implements IReader {
-
- private Iterator<TimeValuePair> timeValuePairIterator;
-
- public MemChunkReaderWithoutFilter(TimeValuePairSorter readableChunk) {
- timeValuePairIterator = readableChunk.getIterator();
- }
-
- @Override
- public boolean hasNext() {
- return timeValuePairIterator.hasNext();
- }
-
- @Override
- public TimeValuePair next() {
- return timeValuePairIterator.next();
- }
-
- @Override
- public void skipCurrentTimeValuePair() {
- next();
- }
-
- @Override
- public void close() {
- // Do nothing because mem chunk reader will not open files
- }
-
- @Override
- public boolean hasNextBatch() {
- return false;
- }
-
- @Override
- public BatchData nextBatch() {
- return null;
- }
-
- @Override
- public BatchData currentBatch() {
- return null;
- }
-}
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/query/reader/merge/PriorityMergeReader.java b/iotdb/src/main/java/org/apache/iotdb/db/query/reader/merge/PriorityMergeReader.java
index e100e50..7a3c665 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/query/reader/merge/PriorityMergeReader.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/query/reader/merge/PriorityMergeReader.java
@@ -16,36 +16,34 @@
* specific language governing permissions and limitations
* under the License.
*/
+
package org.apache.iotdb.db.query.reader.merge;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.PriorityQueue;
-import org.apache.iotdb.db.query.reader.IReader;
+import org.apache.iotdb.db.query.reader.IPointReader;
import org.apache.iotdb.db.utils.TimeValuePair;
-import org.apache.iotdb.tsfile.read.common.BatchData;
/**
* <p>
- * Usage:
- * (1) merge multiple chunk group readers in the unsequence file
- * (2)merge sequence reader, unsequence reader and mem reader
+ * Usage: (1) merge multiple chunk group readers in the unsequence file.
* </p>
*/
-public class PriorityMergeReader implements IReader {
+public class PriorityMergeReader implements IPointReader {
public static final int LOW_PRIORITY = 1;
public static final int HIGH_PRIORITY = 2;
- private List<IReader> readerList = new ArrayList<>();
+ private List<IPointReader> readerList = new ArrayList<>();
private List<Integer> priorityList = new ArrayList<>();
private PriorityQueue<Element> heap = new PriorityQueue<>();
/**
- * The bigger the priority value is, the higher the priority of this reader is
+ * The bigger the priority value is, the higher the priority of this reader is.
*/
- public void addReaderWithPriority(IReader reader, int priority) throws IOException {
+ public void addReaderWithPriority(IPointReader reader, int priority) throws IOException {
if (reader.hasNext()) {
heap.add(new Element(readerList.size(), reader.next(), priority));
}
@@ -65,11 +63,16 @@ public class PriorityMergeReader implements IReader {
return top.timeValuePair;
}
+ @Override
+ public TimeValuePair current() throws IOException {
+ return heap.peek().timeValuePair;
+ }
+
private void updateHeap(Element top) throws IOException {
while (!heap.isEmpty() && heap.peek().timeValuePair.getTimestamp() == top.timeValuePair
.getTimestamp()) {
Element e = heap.poll();
- IReader reader = readerList.get(e.index);
+ IPointReader reader = readerList.get(e.index);
if (reader.hasNext()) {
heap.add(new Element(e.index, reader.next(), priorityList.get(e.index)));
}
@@ -77,35 +80,12 @@ public class PriorityMergeReader implements IReader {
}
@Override
- public void skipCurrentTimeValuePair() throws IOException {
- if (hasNext()) {
- next();
- }
- }
-
- @Override
public void close() throws IOException {
- for (IReader reader : readerList) {
+ for (IPointReader reader : readerList) {
reader.close();
}
}
- @Override
- public boolean hasNextBatch() {
- // TODO
- return false;
- }
-
- @Override
- public BatchData nextBatch() {
- return null;
- }
-
- @Override
- public BatchData currentBatch() {
- return null;
- }
-
protected class Element implements Comparable<Element> {
int index;
@@ -133,11 +113,11 @@ public class PriorityMergeReader implements IReader {
}
@Override
- public boolean equals(Object o){
- if (o instanceof Element){
+ public boolean equals(Object o) {
+ if (o instanceof Element) {
Element element = (Element) o;
if (this.timeValuePair.getTimestamp() == element.timeValuePair.getTimestamp()
- && this.priority.equals(element.priority)){
+ && this.priority.equals(element.priority)) {
return true;
}
}
@@ -145,7 +125,7 @@ public class PriorityMergeReader implements IReader {
}
@Override
- public int hashCode(){
+ public int hashCode() {
return (int) (timeValuePair.getTimestamp() * 31 + priority.hashCode());
}
}
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/query/reader/merge/PriorityMergeReaderByTimestamp.java b/iotdb/src/main/java/org/apache/iotdb/db/query/reader/merge/PriorityMergeReaderByTimestamp.java
index 244291a..b606665 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/query/reader/merge/PriorityMergeReaderByTimestamp.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/query/reader/merge/PriorityMergeReaderByTimestamp.java
@@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
+
package org.apache.iotdb.db.query.reader.merge;
import java.io.IOException;
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/query/reader/sequence/SealedTsFilesReader.java b/iotdb/src/main/java/org/apache/iotdb/db/query/reader/sequence/SealedTsFilesReader.java
index a8465bf..b2a0994 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/query/reader/sequence/SealedTsFilesReader.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/query/reader/sequence/SealedTsFilesReader.java
@@ -26,10 +26,10 @@ import org.apache.iotdb.db.engine.filenode.IntervalFileNode;
import org.apache.iotdb.db.engine.modification.Modification;
import org.apache.iotdb.db.query.context.QueryContext;
import org.apache.iotdb.db.query.control.FileReaderManager;
-import org.apache.iotdb.db.query.reader.IReader;
+import org.apache.iotdb.db.query.reader.IAggregateReader;
+import org.apache.iotdb.db.query.reader.IBatchReader;
import org.apache.iotdb.db.utils.QueryUtils;
-import org.apache.iotdb.db.utils.TimeValuePair;
-import org.apache.iotdb.db.utils.TimeValuePairUtils;
+import org.apache.iotdb.tsfile.file.header.PageHeader;
import org.apache.iotdb.tsfile.file.metadata.ChunkMetaData;
import org.apache.iotdb.tsfile.read.TsFileSequenceReader;
import org.apache.iotdb.tsfile.read.common.BatchData;
@@ -42,17 +42,18 @@ import org.apache.iotdb.tsfile.read.reader.series.FileSeriesReader;
import org.apache.iotdb.tsfile.read.reader.series.FileSeriesReaderWithFilter;
import org.apache.iotdb.tsfile.read.reader.series.FileSeriesReaderWithoutFilter;
-public class SealedTsFilesReader implements IReader {
+public class SealedTsFilesReader implements IBatchReader, IAggregateReader {
private Path seriesPath;
private List<IntervalFileNode> sealedTsFiles;
private int usedIntervalFileIndex;
private FileSeriesReader seriesReader;
private Filter filter;
- private BatchData data;
- private boolean hasCachedData;
private QueryContext context;
+ /**
+ * init with seriesPath, sealedTsFiles, filter, context.
+ */
public SealedTsFilesReader(Path seriesPath, List<IntervalFileNode> sealedTsFiles, Filter filter,
QueryContext context) {
this(seriesPath, sealedTsFiles, context);
@@ -69,10 +70,12 @@ public class SealedTsFilesReader implements IReader {
this.sealedTsFiles = sealedTsFiles;
this.usedIntervalFileIndex = 0;
this.seriesReader = null;
- this.hasCachedData = false;
this.context = context;
}
+ /**
+ * init with seriesReader and queryContext.
+ */
public SealedTsFilesReader(FileSeriesReader seriesReader, QueryContext context) {
this.seriesReader = seriesReader;
sealedTsFiles = new ArrayList<>();
@@ -81,80 +84,30 @@ public class SealedTsFilesReader implements IReader {
@Override
public boolean hasNext() throws IOException {
- if (hasCachedData) {
+
+ // try to get next batch data from current reader
+ if (seriesReader != null && seriesReader.hasNextBatch()) {
return true;
}
- while (!hasCachedData) {
- boolean flag = false;
-
- // try to get next time value pair from current batch data
- if (data != null && data.hasNext()) {
- hasCachedData = true;
- return true;
- }
-
- // try to get next batch data from current reader
- if (seriesReader != null && seriesReader.hasNextBatch()) {
- data = seriesReader.nextBatch();
- if (data.hasNext()) {
- hasCachedData = true;
- return true;
- } else {
- flag = true;
- }
- }
-
+ // init until reach a satisfied reader
+ while (usedIntervalFileIndex < sealedTsFiles.size()) {
// try to get next batch data from next reader
- while (!flag && usedIntervalFileIndex < sealedTsFiles.size()) {
- // init until reach a satisfied reader
- if (seriesReader == null || !seriesReader.hasNextBatch()) {
- IntervalFileNode fileNode = sealedTsFiles.get(usedIntervalFileIndex++);
- if (singleTsFileSatisfied(fileNode)) {
- initSingleTsFileReader(fileNode, context);
- } else {
- flag = true;
- }
- }
- if (!flag && seriesReader.hasNextBatch()) {
- data = seriesReader.nextBatch();
-
- // notice that, data maybe an empty batch data, so an examination must exist
- if (data.hasNext()) {
- hasCachedData = true;
- return true;
- }
- }
+ IntervalFileNode fileNode = sealedTsFiles.get(usedIntervalFileIndex++);
+ if (singleTsFileSatisfied(fileNode)) {
+ initSingleTsFileReader(fileNode, context);
+ } else {
+ continue;
}
- if (!flag || data == null || !data.hasNext()) {
- break;
+ if (seriesReader.hasNextBatch()) {
+ return true;
}
}
return false;
}
- @Override
- public TimeValuePair next() {
- TimeValuePair timeValuePair = TimeValuePairUtils.getCurrentTimeValuePair(data);
- data.next();
- hasCachedData = false;
- return timeValuePair;
- }
-
- @Override
- public void skipCurrentTimeValuePair() {
- next();
- }
-
- @Override
- public void close() throws IOException {
- if (seriesReader != null) {
- seriesReader.close();
- }
- }
-
private boolean singleTsFileSatisfied(IntervalFileNode fileNode) {
if (filter == null) {
@@ -192,17 +145,24 @@ public class SealedTsFilesReader implements IReader {
}
@Override
- public boolean hasNextBatch() {
- return false;
+ public BatchData nextBatch() throws IOException {
+ return seriesReader.nextBatch();
}
@Override
- public BatchData nextBatch() {
- return null;
+ public void close() throws IOException {
+ if (seriesReader != null) {
+ seriesReader.close();
+ }
}
@Override
- public BatchData currentBatch() {
+ public PageHeader nextPageHeader() throws IOException {
return null;
}
+
+ @Override
+ public void skipPageData() throws IOException {
+ seriesReader.skipPageData();
+ }
}
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/query/reader/sequence/SequenceDataReader.java b/iotdb/src/main/java/org/apache/iotdb/db/query/reader/sequence/SequenceDataReader.java
index e4ca98f..b664c93 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/query/reader/sequence/SequenceDataReader.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/query/reader/sequence/SequenceDataReader.java
@@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
+
package org.apache.iotdb.db.query.reader.sequence;
import java.io.IOException;
@@ -23,10 +24,10 @@ import java.util.ArrayList;
import java.util.List;
import org.apache.iotdb.db.engine.querycontext.GlobalSortedSeriesDataSource;
import org.apache.iotdb.db.query.context.QueryContext;
-import org.apache.iotdb.db.query.reader.IReader;
-import org.apache.iotdb.db.query.reader.mem.MemChunkReaderWithFilter;
-import org.apache.iotdb.db.query.reader.mem.MemChunkReaderWithoutFilter;
-import org.apache.iotdb.db.utils.TimeValuePair;
+import org.apache.iotdb.db.query.reader.IAggregateReader;
+import org.apache.iotdb.db.query.reader.IBatchReader;
+import org.apache.iotdb.db.query.reader.mem.MemChunkReader;
+import org.apache.iotdb.tsfile.file.header.PageHeader;
import org.apache.iotdb.tsfile.read.common.BatchData;
import org.apache.iotdb.tsfile.read.filter.basic.Filter;
@@ -36,12 +37,12 @@ import org.apache.iotdb.tsfile.read.filter.basic.Filter;
* in MemTable.
* </p>
*/
-public class SequenceDataReader implements IReader {
+public class SequenceDataReader implements IBatchReader, IAggregateReader {
- private List<IReader> seriesReaders;
+ private List<IAggregateReader> seriesReaders;
private boolean curReaderInitialized;
private int nextSeriesReaderIndex;
- private IReader currentSeriesReader;
+ private IAggregateReader currentSeriesReader;
/**
* init with globalSortedSeriesDataSource and filter.
@@ -68,17 +69,13 @@ public class SequenceDataReader implements IReader {
// add data in memTable
if (sources.hasRawSeriesChunk()) {
- if (filter == null) {
- seriesReaders.add(new MemChunkReaderWithoutFilter(sources.getReadableChunk()));
- } else {
- seriesReaders.add(new MemChunkReaderWithFilter(sources.getReadableChunk(), filter));
- }
+ seriesReaders.add(new MemChunkReader(sources.getReadableChunk(), filter));
}
-
}
@Override
public boolean hasNext() throws IOException {
+
if (curReaderInitialized && currentSeriesReader.hasNext()) {
return true;
} else {
@@ -96,35 +93,24 @@ public class SequenceDataReader implements IReader {
}
@Override
- public TimeValuePair next() throws IOException {
- return currentSeriesReader.next();
- }
-
- @Override
- public void skipCurrentTimeValuePair() throws IOException {
- next();
- }
-
- @Override
public void close() throws IOException {
- for (IReader seriesReader : seriesReaders) {
+ for (IBatchReader seriesReader : seriesReaders) {
seriesReader.close();
}
}
@Override
- public boolean hasNextBatch() {
- return false;
+ public BatchData nextBatch() throws IOException {
+ return currentSeriesReader.nextBatch();
}
@Override
- public BatchData nextBatch() {
- return null;
+ public PageHeader nextPageHeader() throws IOException {
+ return currentSeriesReader.nextPageHeader();
}
@Override
- public BatchData currentBatch() {
- return null;
+ public void skipPageData() throws IOException {
+ currentSeriesReader.skipPageData();
}
-
}
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/query/reader/sequence/UnSealedTsFileReader.java b/iotdb/src/main/java/org/apache/iotdb/db/query/reader/sequence/UnSealedTsFileReader.java
index 3c02930..c11ddc2 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/query/reader/sequence/UnSealedTsFileReader.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/query/reader/sequence/UnSealedTsFileReader.java
@@ -16,14 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
+
package org.apache.iotdb.db.query.reader.sequence;
import java.io.IOException;
import org.apache.iotdb.db.engine.querycontext.UnsealedTsFile;
import org.apache.iotdb.db.query.control.FileReaderManager;
-import org.apache.iotdb.db.query.reader.IReader;
-import org.apache.iotdb.db.utils.TimeValuePair;
-import org.apache.iotdb.db.utils.TimeValuePairUtils;
+import org.apache.iotdb.db.query.reader.IAggregateReader;
+import org.apache.iotdb.db.query.reader.IBatchReader;
+import org.apache.iotdb.tsfile.file.header.PageHeader;
import org.apache.iotdb.tsfile.read.TsFileSequenceReader;
import org.apache.iotdb.tsfile.read.common.BatchData;
import org.apache.iotdb.tsfile.read.common.Path;
@@ -34,11 +35,10 @@ import org.apache.iotdb.tsfile.read.reader.series.FileSeriesReader;
import org.apache.iotdb.tsfile.read.reader.series.FileSeriesReaderWithFilter;
import org.apache.iotdb.tsfile.read.reader.series.FileSeriesReaderWithoutFilter;
-public class UnSealedTsFileReader implements IReader {
+public class UnSealedTsFileReader implements IBatchReader, IAggregateReader {
protected Path seriesPath;
private FileSeriesReader unSealedReader;
- private BatchData data;
/**
* Construct funtion for UnSealedTsFileReader.
@@ -61,31 +61,11 @@ public class UnSealedTsFileReader implements IReader {
unsealedTsFile.getChunkMetaDataList(),
filter);
}
-
}
@Override
public boolean hasNext() throws IOException {
- if (data == null || !data.hasNext()) {
- if (!unSealedReader.hasNextBatch()) {
- return false;
- }
- data = unSealedReader.nextBatch();
- }
-
- return data.hasNext();
- }
-
- @Override
- public TimeValuePair next() {
- TimeValuePair timeValuePair = TimeValuePairUtils.getCurrentTimeValuePair(data);
- data.next();
- return timeValuePair;
- }
-
- @Override
- public void skipCurrentTimeValuePair() {
- data.next();
+ return unSealedReader.hasNextBatch();
}
@Override
@@ -96,17 +76,17 @@ public class UnSealedTsFileReader implements IReader {
}
@Override
- public boolean hasNextBatch() {
- return false;
+ public BatchData nextBatch() throws IOException {
+ return unSealedReader.nextBatch();
}
@Override
- public BatchData nextBatch() {
- return null;
+ public PageHeader nextPageHeader() throws IOException {
+ return unSealedReader.nextPageHeader();
}
@Override
- public BatchData currentBatch() {
- return null;
+ public void skipPageData() throws IOException {
+ unSealedReader.skipPageData();
}
}
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/query/reader/unsequence/EngineChunkReader.java b/iotdb/src/main/java/org/apache/iotdb/db/query/reader/unsequence/EngineChunkReader.java
index e49e968..66f03d2 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/query/reader/unsequence/EngineChunkReader.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/query/reader/unsequence/EngineChunkReader.java
@@ -16,17 +16,18 @@
* specific language governing permissions and limitations
* under the License.
*/
+
package org.apache.iotdb.db.query.reader.unsequence;
import java.io.IOException;
-import org.apache.iotdb.db.query.reader.IReader;
+import org.apache.iotdb.db.query.reader.IPointReader;
import org.apache.iotdb.db.utils.TimeValuePair;
import org.apache.iotdb.db.utils.TimeValuePairUtils;
import org.apache.iotdb.tsfile.read.TsFileSequenceReader;
import org.apache.iotdb.tsfile.read.common.BatchData;
import org.apache.iotdb.tsfile.read.reader.chunk.ChunkReader;
-public class EngineChunkReader implements IReader {
+public class EngineChunkReader implements IPointReader {
private ChunkReader chunkReader;
private BatchData data;
@@ -44,15 +45,16 @@ public class EngineChunkReader implements IReader {
@Override
public boolean hasNext() throws IOException {
- if (data == null || !data.hasNext()) {
- if (chunkReader.hasNextBatch()) {
- data = chunkReader.nextBatch();
- } else {
- return false;
+ if (data != null && data.hasNext()) {
+ return true;
+ }
+ while (chunkReader.hasNextBatch()) {
+ data = chunkReader.nextBatch();
+ if (data.hasNext()) {
+ return true;
}
}
-
- return data.hasNext();
+ return false;
}
@Override
@@ -63,8 +65,8 @@ public class EngineChunkReader implements IReader {
}
@Override
- public void skipCurrentTimeValuePair() {
- next();
+ public TimeValuePair current() throws IOException {
+ return TimeValuePairUtils.getCurrentTimeValuePair(data);
}
@Override
@@ -72,19 +74,4 @@ public class EngineChunkReader implements IReader {
this.chunkReader.close();
this.unClosedTsFileReader.close();
}
-
- @Override
- public boolean hasNextBatch() {
- return false;
- }
-
- @Override
- public BatchData nextBatch() {
- return null;
- }
-
- @Override
- public BatchData currentBatch() {
- return null;
- }
}
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/query/timegenerator/EngineLeafNode.java b/iotdb/src/main/java/org/apache/iotdb/db/query/timegenerator/EngineLeafNode.java
index 292ca0e..688e296 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/query/timegenerator/EngineLeafNode.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/query/timegenerator/EngineLeafNode.java
@@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
+
package org.apache.iotdb.db.query.timegenerator;
import java.io.IOException;
@@ -44,15 +45,15 @@ public class EngineLeafNode implements Node {
return reader.next().getTimestamp();
}
- /**
- * check if current time of current batch is equals to input time.
- */
- public boolean currentTimeIs(long time) {
- if (!reader.currentBatch().hasNext()) {
- return false;
- }
- return reader.currentBatch().currentTime() == time;
- }
+// /**
+// * check if current time of current batch is equals to input time.
+// */
+// public boolean currentTimeIs(long time) {
+// if (!reader.currentBatch().hasNext()) {
+// return false;
+// }
+// return reader.currentBatch().currentTime() == time;
+// }
/**
* check if current value is equals to input value.
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/query/timegenerator/EngineNodeConstructor.java b/iotdb/src/main/java/org/apache/iotdb/db/query/timegenerator/EngineNodeConstructor.java
index 0cb02c8..3d5b3e4 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/query/timegenerator/EngineNodeConstructor.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/query/timegenerator/EngineNodeConstructor.java
@@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
+
package org.apache.iotdb.db.query.timegenerator;
import static org.apache.iotdb.tsfile.read.expression.ExpressionType.AND;
@@ -28,6 +29,7 @@ import org.apache.iotdb.db.exception.FileNodeManagerException;
import org.apache.iotdb.db.query.context.QueryContext;
import org.apache.iotdb.db.query.control.QueryDataSourceManager;
import org.apache.iotdb.db.query.factory.SeriesReaderFactory;
+import org.apache.iotdb.db.query.reader.AllDataReader;
import org.apache.iotdb.db.query.reader.IReader;
import org.apache.iotdb.db.query.reader.merge.PriorityMergeReader;
import org.apache.iotdb.db.query.reader.sequence.SequenceDataReader;
@@ -92,19 +94,21 @@ public class EngineNodeConstructor {
Filter filter = singleSeriesExpression.getFilter();
- PriorityMergeReader priorityReader = new PriorityMergeReader();
-
// reader for all sequence data
SequenceDataReader tsFilesReader = new SequenceDataReader(queryDataSource.getSeqDataSource(),
filter, context);
- priorityReader.addReaderWithPriority(tsFilesReader, 1);
// reader for all unSequence data
PriorityMergeReader unSeqMergeReader = SeriesReaderFactory.getInstance()
.createUnSeqMergeReader(queryDataSource.getOverflowSeriesDataSource(), filter);
- priorityReader.addReaderWithPriority(unSeqMergeReader, 2);
- return priorityReader;
+ if (tsFilesReader == null || !tsFilesReader.hasNext()) {
+ //only have unsequence data.
+ return unSeqMergeReader;
+ } else {
+ //merge sequence data with unsequence data.
+ return new AllDataReader(tsFilesReader, unSeqMergeReader);
+ }
}
}
diff --git a/iotdb/src/test/java/PerformanceTest.java b/iotdb/src/test/java/PerformanceTest.java
new file mode 100644
index 0000000..8bcb228
--- /dev/null
+++ b/iotdb/src/test/java/PerformanceTest.java
@@ -0,0 +1,282 @@
+/**
+ * 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.
+ */
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.iotdb.db.exception.FileNodeManagerException;
+import org.apache.iotdb.db.query.executor.EngineQueryRouter;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.read.common.Path;
+import org.apache.iotdb.tsfile.read.common.RowRecord;
+import org.apache.iotdb.tsfile.read.expression.IExpression;
+import org.apache.iotdb.tsfile.read.expression.QueryExpression;
+import org.apache.iotdb.tsfile.read.expression.impl.SingleSeriesExpression;
+import org.apache.iotdb.tsfile.read.filter.TimeFilter;
+import org.apache.iotdb.tsfile.read.filter.ValueFilter;
+import org.apache.iotdb.tsfile.read.filter.basic.Filter;
+import org.apache.iotdb.tsfile.read.filter.factory.FilterFactory;
+import org.apache.iotdb.tsfile.read.query.dataset.QueryDataSet;
+
+/**
+ * Delete this class when submitting pr.
+ */
+public class PerformanceTest {
+
+ // private static int deviceStart = 5, deviceEnd = 9;
+ private static int deviceStart = 9, deviceEnd = 9;
+ private static int sensorStart = 8, sensorEnd = 8;
+ private static String insertTemplate = "INSERT INTO root.perform.group_0.d_%s(timestamp,s_%s"
+ + ") VALUES(%d,%d)";
+
+ public static void main(String[] args) throws IOException, FileNodeManagerException, SQLException {
+ try {
+ Class.forName("org.apache.iotdb.jdbc.IoTDBDriver");
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ }
+ //insert();
+
+ //singleWithoutFilterTest();
+
+ // queryMultiSeriesWithoutFilterTest();
+
+ queryMultiSeriesWithFilterTest();
+ }
+
+ private static void singleWithoutFilterTest() throws IOException, FileNodeManagerException {
+
+ List<Path> selectedPathList = new ArrayList<>();
+ selectedPathList.add(getPath(1, 1));
+
+ QueryExpression queryExpression = QueryExpression.create(selectedPathList, null);
+
+ EngineQueryRouter queryRouter = new EngineQueryRouter();
+
+ long startTime = System.currentTimeMillis();
+
+ QueryDataSet queryDataSet = queryRouter.query(queryExpression);
+
+ int count = 0;
+ while (queryDataSet.hasNext()) {
+ RowRecord rowRecord = queryDataSet.next();
+ count++;
+ // output(count, rowRecord, true);
+ }
+
+ long endTime = System.currentTimeMillis();
+ System.out
+ .println(String.format("Time consume : %s, count number : %s", endTime - startTime, count));
+
+ }
+
+ public static void queryMultiSeriesWithoutFilterTest()
+ throws IOException, FileNodeManagerException {
+
+ List<Path> selectedPathList = new ArrayList<>();
+ for (int i = deviceStart; i <= deviceEnd; i++) {
+ for (int j = sensorStart; j <= sensorEnd; j++) {
+ selectedPathList.add(getPath(i, j));
+ }
+ }
+
+ QueryExpression queryExpression = QueryExpression.create(selectedPathList, null);
+
+ EngineQueryRouter queryRouter = new EngineQueryRouter();
+
+ long startTime = System.currentTimeMillis();
+
+ QueryDataSet queryDataSet = queryRouter.query(queryExpression);
+
+ int count = 0;
+ while (queryDataSet.hasNext()) {
+ RowRecord rowRecord = queryDataSet.next();
+ count++;
+ }
+
+ long endTime = System.currentTimeMillis();
+ System.out
+ .println(String.format("Time consume : %s, count number : %s", endTime - startTime, count));
+
+ }
+
+ public static void queryMultiSeriesWithFilterTest() throws IOException, FileNodeManagerException {
+
+ List<Path> selectedPathList = new ArrayList<>();
+ for (int i = deviceStart; i <= deviceEnd; i++) {
+ for (int j = sensorStart; j <= sensorEnd; j++) {
+ selectedPathList.add(getPath(i, j));
+ }
+ }
+
+ Filter valueFilter = ValueFilter.gtEq(34300);
+ Filter timeFilter = FilterFactory
+ .and(TimeFilter.gtEq(50000L), TimeFilter.ltEq(100000L));
+ Filter filter = FilterFactory.and(timeFilter, valueFilter);
+
+ IExpression expression = new SingleSeriesExpression(getPath(9, 9), filter);
+ EngineQueryRouter queryRouter = new EngineQueryRouter();
+
+ QueryExpression queryExpression = QueryExpression.create(selectedPathList, expression);
+ long startTime = System.currentTimeMillis();
+
+ QueryDataSet queryDataSet = queryRouter.query(queryExpression);
+
+ int count = 0;
+ while (queryDataSet.hasNext()) {
+ RowRecord rowRecord = queryDataSet.next();
+ count++;
+ // if (count % 10000 == 0)
+ // System.out.println(rowRecord);
+ }
+
+ long endTime = System.currentTimeMillis();
+ System.out
+ .println(String.format("Time consume : %s ms, count number : %s", endTime - startTime, count));
+
+ }
+
+ public static void output(int cnt, RowRecord rowRecord, boolean flag) {
+ if (!flag) {
+ return;
+ }
+
+ if (cnt % 10000 == 0) {
+ System.out.println(cnt + " : " + rowRecord);
+ }
+
+ if (cnt > 97600) {
+ System.out.println("----" + cnt + " : " + rowRecord);
+ }
+ }
+
+ public static Path getPath(int d, int s) {
+ return new Path(String.format("root.perform.group_0.d_%s.s_%s", d, s));
+ }
+
+ private static void insert() throws SQLException {
+ int d_start = 0, d_end = 10;
+ int s_start = 0, s_end = 10;
+ int num = 100000;
+ prepareSeries(d_start,d_end,s_start,s_end);
+ prepareData(d_start,d_end,s_start,s_end, num);
+ }
+
+ private static void prepareData(int d_start, int d_end, int s_start, int s_end, int num) throws SQLException {
+ System.out.println("prepareData start!");
+ Connection connection = null;
+ try {
+ connection = DriverManager
+ .getConnection(Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root",
+ "root");
+ Statement statement = connection.createStatement();
+ // prepare BufferWrite file
+ for (int i = 20000; i <= 30000; i++) {
+ insertInTimestamp(statement, d_start,d_end,s_start,s_end, i);
+ }
+ statement.execute("merge");
+ System.out.println("prepareData 20000-30000 end ");
+
+ // prepare Unseq-File
+ for (int i = 1; i <= 10000; i++) {
+ insertInTimestamp(statement, d_start,d_end,s_start,s_end, i);
+ }
+ statement.execute("merge");
+ System.out.println("prepareData 1-10000 end ");
+
+ // prepare muilty BufferWrite file
+ for (int i = 40000; i <= 65000; i++) {
+ insertInTimestamp(statement, d_start,d_end,s_start,s_end, i);
+ }
+ statement.execute("merge");
+ System.out.println("prepareData 40000-65000 end ");
+
+ // prepare muilty BufferWrite file
+ for (int i = 80000; i <= 87000; i++) {
+ insertInTimestamp(statement, d_start,d_end,s_start,s_end, i);
+ }
+ statement.execute("merge");
+ System.out.println("prepareData 80000-87000 end ");
+
+ // prepare BufferWrite cache
+ for (int i = 90001; i <= 100000; i++) {
+ insertInTimestamp(statement, d_start,d_end,s_start,s_end, i);
+ }
+ System.out.println("prepareData 90001-100000 end ");
+
+ // prepare Overflow cache
+ for (int i = 10001; i <= 20000; i++) {
+ insertInTimestamp(statement, d_start,d_end,s_start,s_end, i);
+ }
+ System.out.println("prepareData 10001-20000 end ");
+ statement.close();
+ } finally {
+ if (connection != null) {
+ connection.close();
+ }
+ }
+ }
+
+ private static void insertInTimestamp(Statement statement,int d_start, int d_end, int s_start, int s_end, int time)
+ throws SQLException {
+ for(int m = d_start; m <= d_end; m++ ){
+ for(int n = s_start; n<= s_end; n++){
+ statement.execute(String.format(insertTemplate, m, n, time, time));
+ }
+ }
+ }
+
+ private static void prepareSeries(int d_start, int d_end, int s_start, int s_end) throws SQLException {
+ System.out.println("prepareSeries start!");
+ Connection connection = null;
+ try {
+ connection = DriverManager
+ .getConnection(Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root",
+ "root");
+ Statement statement = connection.createStatement();
+ for(int i = d_start; i <= d_end; i++ ){
+ statement.execute(createStorageGroupSql(i));
+ }
+ statement.close();
+
+ statement = connection.createStatement();
+ for(int i = d_start; i <= d_end; i++ ){
+ for(int j = s_start; j<= s_end; j++){
+ statement.execute(String.format("CREATE TIMESERIES root.perform.group_0.d_%s.s_%s WITH DATATYPE=INT32, ENCODING=RLE", i, j));//
+ }
+ }
+ statement.close();
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ if (connection != null) {
+ connection.close();
+ }
+ }
+ }
+
+ public static String createStorageGroupSql(int d){
+ return String.format("SET STORAGE GROUP TO root.perform.group_0.d_%s", d);
+ }
+
+}
diff --git a/iotdb/src/test/java/org/apache/iotdb/db/query/reader/AllDataReaderTest.java b/iotdb/src/test/java/org/apache/iotdb/db/query/reader/AllDataReaderTest.java
new file mode 100644
index 0000000..4b16fb4
--- /dev/null
+++ b/iotdb/src/test/java/org/apache/iotdb/db/query/reader/AllDataReaderTest.java
@@ -0,0 +1,77 @@
+/**
+ * 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 static org.junit.Assert.*;
+
+import java.io.IOException;
+import org.apache.iotdb.db.utils.TimeValuePair;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class AllDataReaderTest {
+
+ private AllDataReader reader1;
+ private AllDataReader reader2;
+
+ private void init(){
+ IBatchReader batchReader1 = new FakedIBatchPoint(100, 1000, 7, 11);
+ IBatchReader batchReader2 = new FakedIBatchPoint(100, 1000, 7, 11);
+ IPointReader pointReader = new FakedIPointReader(20, 500, 11, 19);
+
+ reader1 = new AllDataReader(batchReader1, pointReader);
+ reader2 = new AllDataReader(batchReader2, null);
+ }
+
+ @Test
+ public void test() throws IOException {
+ init();
+ testWithOutNullReader();
+ testWithNullPointReader();
+ }
+
+ private void testWithOutNullReader() throws IOException {
+ int cnt = 0;
+ while (reader1.hasNext()){
+ TimeValuePair timeValuePair = reader1.next();
+ cnt++;
+ if((timeValuePair.getTimestamp()-20) % 11 == 0 && timeValuePair.getTimestamp() < 20+500*11){
+ Assert.assertEquals(timeValuePair.getTimestamp() % 19, timeValuePair.getValue().getLong());
+ continue;
+ }
+ if((timeValuePair.getTimestamp()-100) % 7 == 0){
+ Assert.assertEquals(timeValuePair.getTimestamp() % 11, timeValuePair.getValue().getLong());
+ }
+ }
+ Assert.assertEquals(1430, cnt);
+ System.out.println("testWithOutNullReader-cnt:"+cnt);
+ }
+
+ private void testWithNullPointReader() throws IOException {
+ int cnt = 0;
+ while (reader2.hasNext()){
+ TimeValuePair timeValuePair = reader2.next();
+ Assert.assertEquals(timeValuePair.getTimestamp() % 11, timeValuePair.getValue().getLong());
+ cnt++;
+ }
+ Assert.assertEquals(1000, cnt);
+ System.out.println("testWithNullPointReader-cnt:"+cnt);
+ }
+}
\ No newline at end of file
diff --git a/iotdb/src/test/java/org/apache/iotdb/db/query/reader/FakedIBatchPoint.java b/iotdb/src/test/java/org/apache/iotdb/db/query/reader/FakedIBatchPoint.java
new file mode 100644
index 0000000..7bf8590
--- /dev/null
+++ b/iotdb/src/test/java/org/apache/iotdb/db/query/reader/FakedIBatchPoint.java
@@ -0,0 +1,108 @@
+/**
+ * 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 java.util.Random;
+import org.apache.iotdb.db.utils.TimeValuePair;
+import org.apache.iotdb.db.utils.TsPrimitiveType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.read.common.BatchData;
+import org.junit.Assert;
+
+public class FakedIBatchPoint implements IBatchReader {
+
+ private Iterator<TimeValuePair> iterator;
+ private BatchData batchData;
+ private boolean hasCachedBatchData;
+ private boolean hasEmptyBatch;
+ private Random random;
+
+ private TimeValuePair timeValuePair;
+
+ public FakedIBatchPoint(long startTime, int size, int interval, int modValue, boolean hasEmptyBatch) {
+ 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();
+ this.hasEmptyBatch = hasEmptyBatch;
+ this.random = new Random();
+ this.hasCachedBatchData = false;
+ }
+
+ public FakedIBatchPoint(long startTime, int size, int interval, int modValue) {
+ this(startTime, size, interval, modValue, false);
+ }
+
+ @Override
+ public boolean hasNext() throws IOException {
+ if(hasCachedBatchData){
+ return true;
+ }
+ if(iterator.hasNext()){
+ constructBatchData();
+ hasCachedBatchData = true;
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public BatchData nextBatch() throws IOException {
+ if(hasCachedBatchData){
+ hasCachedBatchData = false;
+ return batchData;
+ }
+ else {
+ constructBatchData();
+ return batchData;
+ }
+
+ }
+
+ @Override
+ public void close() throws IOException {
+
+ }
+
+ private void constructBatchData(){
+ int num = random.nextInt(10);
+ if(!hasEmptyBatch){
+ num+=1;
+ }
+ batchData = new BatchData(TSDataType.INT64,true);
+ while (num > 0 && iterator.hasNext()){
+ timeValuePair = iterator.next();
+ batchData.putTime(timeValuePair.getTimestamp());
+ batchData.putLong(timeValuePair.getValue().getLong());
+ num--;
+ }
+ if(!hasEmptyBatch){
+ Assert.assertTrue(batchData.hasNext());
+ }
+ }
+}
diff --git a/iotdb/src/test/java/org/apache/iotdb/db/query/reader/FakedIPointReader.java b/iotdb/src/test/java/org/apache/iotdb/db/query/reader/FakedIPointReader.java
new file mode 100644
index 0000000..d9dd4ce
--- /dev/null
+++ b/iotdb/src/test/java/org/apache/iotdb/db/query/reader/FakedIPointReader.java
@@ -0,0 +1,75 @@
+/**
+ * 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.utils.TimeValuePair;
+import org.apache.iotdb.db.utils.TsPrimitiveType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+
+public class FakedIPointReader implements IPointReader{
+
+ private Iterator<TimeValuePair> iterator;
+ private boolean hasCachedTimeValuePair = false;
+ private TimeValuePair cachedTimeValuePair;
+
+ public FakedIPointReader(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 boolean hasNext() throws IOException {
+ return hasCachedTimeValuePair || iterator.hasNext();
+ }
+
+ @Override
+ public TimeValuePair next() throws IOException {
+ if (hasCachedTimeValuePair){
+ hasCachedTimeValuePair = false;
+ return cachedTimeValuePair;
+ }
+ return iterator.next();
+ }
+
+ @Override
+ public TimeValuePair current() throws IOException {
+ if(hasCachedTimeValuePair){
+ return cachedTimeValuePair;
+ }
+ cachedTimeValuePair = iterator.next();
+ hasCachedTimeValuePair = true;
+ return cachedTimeValuePair;
+ }
+
+ @Override
+ public void close() throws IOException {
+
+ }
+}
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..821e14e
--- /dev/null
+++ b/iotdb/src/test/java/org/apache/iotdb/db/query/reader/FakedSeriesReaderByTimestamp.java
@@ -0,0 +1,93 @@
+/**
+ * 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 TsPrimitiveType getValueInTimestamp(long timestamp) throws IOException {
+ if(hasCachedTimeValuePair){
+ if(timestamp == cachedTimeValuePair.getTimestamp()){
+ hasCachedTimeValuePair = false;
+ return cachedTimeValuePair.getValue();
+ }
+ else if(timestamp > cachedTimeValuePair.getTimestamp()){
+ hasCachedTimeValuePair = false;
+ }
+ else {
+ return null;
+ }
+ }
+ while(iterator.hasNext()){
+ cachedTimeValuePair = iterator.next();
+ if(timestamp == cachedTimeValuePair.getTimestamp()){
+ return cachedTimeValuePair.getValue();
+ }
+ else if(timestamp < cachedTimeValuePair.getTimestamp()){
+ hasCachedTimeValuePair = true;
+ break;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public boolean hasNext() throws IOException {
+ return hasCachedTimeValuePair || iterator.hasNext();
+ }
+
+ @Override
+ public TimeValuePair next() throws IOException {
+ if (hasCachedTimeValuePair){
+ hasCachedTimeValuePair = false;
+ return cachedTimeValuePair;
+ }
+ return iterator.next();
+ }
+
+ @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 03771e8..595399d 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
@@ -23,6 +23,7 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
+import org.apache.iotdb.db.query.reader.IPointReader;
import org.apache.iotdb.db.utils.TimeValuePair;
import org.apache.iotdb.db.utils.TsPrimitiveType;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
@@ -104,7 +105,8 @@ public class PriorityMergeReaderByTimestampTest {
}
- public static class FakedPrioritySeriesReaderByTimestamp implements EngineReaderByTimeStamp {
+ public static class FakedPrioritySeriesReaderByTimestamp implements EngineReaderByTimeStamp,
+ IPointReader {
private Iterator<TimeValuePair> iterator;
private long currentTimeStamp = Long.MIN_VALUE;
@@ -150,8 +152,12 @@ public class PriorityMergeReaderByTimestampTest {
}
@Override
- public void skipCurrentTimeValuePair() throws IOException {
- next();
+ public TimeValuePair current() throws IOException {
+ if (hasCachedTimeValuePair) {
+ return cachedTimeValuePair;
+ } else {
+ throw new IOException(" to end! " + iterator.next());
+ }
}
@Override
@@ -176,20 +182,5 @@ public class PriorityMergeReaderByTimestampTest {
}
return null;
}
-
- @Override
- public boolean hasNextBatch() {
- return false;
- }
-
- @Override
- public BatchData nextBatch() {
- return null;
- }
-
- @Override
- public BatchData currentBatch() {
- return null;
- }
}
}
diff --git a/iotdb/src/test/java/org/apache/iotdb/db/query/reader/merge/PriorityMergeReaderTest.java b/iotdb/src/test/java/org/apache/iotdb/db/query/reader/merge/PriorityMergeReaderTest.java
index 66ecf06..4f3b071 100644
--- a/iotdb/src/test/java/org/apache/iotdb/db/query/reader/merge/PriorityMergeReaderTest.java
+++ b/iotdb/src/test/java/org/apache/iotdb/db/query/reader/merge/PriorityMergeReaderTest.java
@@ -22,6 +22,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import org.apache.iotdb.db.query.reader.IPointReader;
import org.apache.iotdb.db.query.reader.IReader;
import org.apache.iotdb.db.utils.TimeValuePair;
import org.apache.iotdb.db.utils.TsPrimitiveType;
@@ -65,7 +66,7 @@ public class PriorityMergeReaderTest {
Assert.assertEquals(162, cnt);
}
- public static class FakedPrioritySeriesReader implements IReader {
+ public static class FakedPrioritySeriesReader implements IPointReader {
private Iterator<TimeValuePair> iterator;
@@ -92,27 +93,13 @@ public class PriorityMergeReaderTest {
}
@Override
- public void skipCurrentTimeValuePair() {
- iterator.next();
+ public TimeValuePair current() throws IOException {
+ throw new IOException("current() in FakedPrioritySeriesReader is an empty method.");
}
- @Override
- public void close() {
- }
-
- @Override
- public boolean hasNextBatch() {
- return false;
- }
@Override
- public BatchData nextBatch() {
- return null;
- }
-
- @Override
- public BatchData currentBatch() {
- return null;
+ public void close() {
}
}
}
diff --git a/iotdb/src/test/java/org/apache/iotdb/db/query/reader/merge/SeriesMergeSortReaderTest.java b/iotdb/src/test/java/org/apache/iotdb/db/query/reader/merge/SeriesMergeSortReaderTest.java
index f27948e..fb4d163 100644
--- a/iotdb/src/test/java/org/apache/iotdb/db/query/reader/merge/SeriesMergeSortReaderTest.java
+++ b/iotdb/src/test/java/org/apache/iotdb/db/query/reader/merge/SeriesMergeSortReaderTest.java
@@ -19,6 +19,7 @@
package org.apache.iotdb.db.query.reader.merge;
import java.io.IOException;
+import org.apache.iotdb.db.query.reader.IPointReader;
import org.apache.iotdb.db.query.reader.IReader;
import org.apache.iotdb.db.utils.TimeValuePair;
import org.apache.iotdb.db.utils.TsPrimitiveType;
@@ -66,7 +67,7 @@ public class SeriesMergeSortReaderTest {
}
}
- public static class FakedSeriesReader implements IReader {
+ public static class FakedSeriesReader implements IPointReader {
private long[] timestamps;
private int index;
@@ -89,27 +90,12 @@ public class SeriesMergeSortReaderTest {
}
@Override
- public void skipCurrentTimeValuePair() {
- next();
+ public TimeValuePair current() throws IOException {
+ return new TimeValuePair(timestamps[index], new TsPrimitiveType.TsLong(value));
}
@Override
public void close() {
}
-
- @Override
- public boolean hasNextBatch() {
- return false;
- }
-
- @Override
- public BatchData nextBatch() {
- return null;
- }
-
- @Override
- public BatchData currentBatch() {
- return null;
- }
}
}
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/query/reader/IReader.java b/iotdb/src/test/java/org/apache/iotdb/db/query/reader/sequence/SealedTsFilesReaderTest.java
similarity index 57%
copy from iotdb/src/main/java/org/apache/iotdb/db/query/reader/IReader.java
copy to iotdb/src/test/java/org/apache/iotdb/db/query/reader/sequence/SealedTsFilesReaderTest.java
index 6a574d6..2d6e5eb 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/query/reader/IReader.java
+++ b/iotdb/src/test/java/org/apache/iotdb/db/query/reader/sequence/SealedTsFilesReaderTest.java
@@ -16,29 +16,27 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.iotdb.db.query.reader;
-import java.io.IOException;
-import org.apache.iotdb.db.utils.TimeValuePair;
-import org.apache.iotdb.tsfile.read.common.BatchData;
+package org.apache.iotdb.db.query.reader.sequence;
-/**
- * Vital read interface. Batch method is used to increase query speed. Getting a batch of data
- * a time is faster than getting one point a time.
- */
-public interface IReader {
+import static org.junit.Assert.*;
- boolean hasNext() throws IOException;
+import org.junit.Test;
- TimeValuePair next() throws IOException;
+public class SealedTsFilesReaderTest {
- void skipCurrentTimeValuePair() throws IOException;
+ private SealedTsFilesReader sealedTsFilesReader;
- void close() throws IOException;
+ @Test
+ public void hasNext() {
- boolean hasNextBatch();
+ }
- BatchData nextBatch();
+ @Test
+ public void nextBatch() {
+ }
- BatchData currentBatch();
-}
+ @Test
+ public void currentBatch() {
+ }
+}
\ No newline at end of file
diff --git a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/reader/chunk/ChunkReader.java b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/reader/chunk/ChunkReader.java
index 125e131..f16c047 100644
--- a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/reader/chunk/ChunkReader.java
+++ b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/reader/chunk/ChunkReader.java
@@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
+
package org.apache.iotdb.tsfile.read.reader.chunk;
import java.io.IOException;
@@ -48,6 +49,9 @@ public abstract class ChunkReader {
private BatchData data;
+ private PageHeader pageHeader;
+ private boolean hasCachedPageHeader;
+
/**
* Data whose timestamp <= deletedAt should be considered deleted(not be returned).
*/
@@ -72,38 +76,45 @@ public abstract class ChunkReader {
valueDecoder = Decoder
.getDecoderByType(chunkHeader.getEncodingType(), chunkHeader.getDataType());
data = new BatchData(chunkHeader.getDataType());
- }
-
- public boolean hasNextBatch() {
- return chunkDataBuffer.remaining() > 0;
+ hasCachedPageHeader = false;
}
/**
- * get next data batch.
- *
- * @return next data batch
- * @throws IOException IOException
+ * judge if has nextBatch.
*/
- public BatchData nextBatch() throws IOException {
-
+ public boolean hasNextBatch() throws IOException {
+ if (hasCachedPageHeader) {
+ return true;
+ }
// construct next satisfied page header
while (chunkDataBuffer.remaining() > 0) {
// deserialize a PageHeader from chunkDataBuffer
- PageHeader pageHeader = PageHeader
- .deserializeFrom(chunkDataBuffer, chunkHeader.getDataType());
+ pageHeader = PageHeader.deserializeFrom(chunkDataBuffer, chunkHeader.getDataType());
// if the current page satisfies
if (pageSatisfied(pageHeader)) {
- PageReader pageReader = constructPageReaderForNextPage(pageHeader.getCompressedSize());
- if (pageReader.hasNextBatch()) {
- data = pageReader.nextBatch();
- return data;
- }
+ hasCachedPageHeader = true;
+ return true;
} else {
skipBytesInStreamByLength(pageHeader.getCompressedSize());
}
}
+ return false;
+ }
+ /**
+ * get next data batch.
+ *
+ * @return next data batch
+ * @throws IOException IOException
+ */
+ public BatchData nextBatch() throws IOException {
+ PageReader pageReader = constructPageReaderForNextPage(pageHeader.getCompressedSize());
+ hasCachedPageHeader = false;
+ if (pageReader.hasNextBatch()) {
+ data = pageReader.nextBatch();
+ return data;
+ }
return data;
}
@@ -111,6 +122,15 @@ public abstract class ChunkReader {
return data;
}
+ public PageHeader nextPageHeader() throws IOException {
+ return pageHeader;
+ }
+
+ public void skipPageData() {
+ skipBytesInStreamByLength(pageHeader.getCompressedSize());
+ hasCachedPageHeader = false;
+ }
+
private void skipBytesInStreamByLength(long length) {
chunkDataBuffer.position(chunkDataBuffer.position() + (int) length);
}
diff --git a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/reader/series/FileSeriesReader.java b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/reader/series/FileSeriesReader.java
index f42c8ae..110fec3 100644
--- a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/reader/series/FileSeriesReader.java
+++ b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/reader/series/FileSeriesReader.java
@@ -16,10 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
+
package org.apache.iotdb.tsfile.read.reader.series;
import java.io.IOException;
import java.util.List;
+import org.apache.iotdb.tsfile.file.header.PageHeader;
import org.apache.iotdb.tsfile.file.metadata.ChunkMetaData;
import org.apache.iotdb.tsfile.read.common.BatchData;
import org.apache.iotdb.tsfile.read.controller.ChunkLoader;
@@ -48,30 +50,14 @@ public abstract class FileSeriesReader {
/**
* check if current chunk has next batch data.
+ *
* @return True if current chunk has next batch data
*/
- public boolean hasNextBatch() {
-
- // current chunk has data
- if (chunkReader != null && chunkReader.hasNextBatch()) {
- return true;
-
- // has additional chunk to read
- } else {
- return chunkToRead < chunkMetaDataList.size();
- }
-
- }
-
- /**
- * get next batch data.
- */
- public BatchData nextBatch() throws IOException {
+ public boolean hasNextBatch() throws IOException {
// current chunk has additional batch
if (chunkReader != null && chunkReader.hasNextBatch()) {
- data = chunkReader.nextBatch();
- return data;
+ return true;
}
// current chunk does not have additional batch, init new chunk reader
@@ -83,15 +69,18 @@ public abstract class FileSeriesReader {
initChunkReader(chunkMetaData);
if (chunkReader.hasNextBatch()) {
- data = chunkReader.nextBatch();
- return data;
+ return true;
}
}
}
+ return false;
+ }
- if (data == null) {
- return new BatchData();
- }
+ /**
+ * get next batch data.
+ */
+ public BatchData nextBatch() throws IOException {
+ data = chunkReader.nextBatch();
return data;
}
@@ -99,6 +88,14 @@ public abstract class FileSeriesReader {
return data;
}
+ public PageHeader nextPageHeader() throws IOException {
+ return chunkReader.nextPageHeader();
+ }
+
+ public void skipPageData() {
+ chunkReader.skipPageData();
+ }
+
protected abstract void initChunkReader(ChunkMetaData chunkMetaData) throws IOException;
protected abstract boolean chunkSatisfied(ChunkMetaData chunkMetaData);
[incubator-iotdb] 02/02: realize aggregate function interface
Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
suyue pushed a commit to branch aggregate
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git
commit cfa2b65f7cc9b6946d95aca21655437e14d20ddf
Author: suyue <23...@qq.com>
AuthorDate: Sun Mar 10 16:27:56 2019 +0800
realize aggregate function interface
---
.../db/query/aggregation/AggreFuncFactory.java | 76 ++++++++++
.../db/query/aggregation/AggregateFunction.java | 130 +++++++++++++++++
.../db/query/aggregation/AggregationConstant.java | 40 ++++++
.../db/query/aggregation/impl/CountAggrFunc.java | 112 +++++++++++++++
.../db/query/aggregation/impl/FirstAggrFunc.java | 114 +++++++++++++++
.../db/query/aggregation/impl/LastAggrFunc.java | 135 ++++++++++++++++++
.../db/query/aggregation/impl/MaxTimeAggrFunc.java | 127 +++++++++++++++++
.../query/aggregation/impl/MaxValueAggrFunc.java | 137 ++++++++++++++++++
.../db/query/aggregation/impl/MeanAggrFunc.java | 133 +++++++++++++++++
.../db/query/aggregation/impl/MinTimeAggrFunc.java | 108 ++++++++++++++
.../query/aggregation/impl/MinValueAggrFunc.java | 138 ++++++++++++++++++
.../db/query/aggregation/impl/SumAggrFunc.java | 130 +++++++++++++++++
.../iotdb/db/query/dataset/AggregateDataSet.java | 138 ++++++++++++++++++
.../db/query/executor/AggregateEngineExecutor.java | 158 +++++++++++++++++++++
.../iotdb/db/query/executor/EngineQueryRouter.java | 35 +++++
.../apache/iotdb/tsfile/read/common/BatchData.java | 58 ++++++++
16 files changed, 1769 insertions(+)
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/query/aggregation/AggreFuncFactory.java b/iotdb/src/main/java/org/apache/iotdb/db/query/aggregation/AggreFuncFactory.java
new file mode 100644
index 0000000..882993d
--- /dev/null
+++ b/iotdb/src/main/java/org/apache/iotdb/db/query/aggregation/AggreFuncFactory.java
@@ -0,0 +1,76 @@
+/**
+ * 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.aggregation;
+
+import org.apache.iotdb.db.exception.ProcessorException;
+import org.apache.iotdb.db.query.aggregation.impl.CountAggrFunc;
+import org.apache.iotdb.db.query.aggregation.impl.FirstAggrFunc;
+import org.apache.iotdb.db.query.aggregation.impl.LastAggrFunc;
+import org.apache.iotdb.db.query.aggregation.impl.MaxTimeAggrFunc;
+import org.apache.iotdb.db.query.aggregation.impl.MaxValueAggrFunc;
+import org.apache.iotdb.db.query.aggregation.impl.MeanAggrFunc;
+import org.apache.iotdb.db.query.aggregation.impl.MinTimeAggrFunc;
+import org.apache.iotdb.db.query.aggregation.impl.MinValueAggrFunc;
+import org.apache.iotdb.db.query.aggregation.impl.SumAggrFunc;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+
+/**
+ * Easy factory pattern to build AggregateFunction.
+ */
+public class AggreFuncFactory {
+
+ /**
+ * construct AggregateFunction using factory pattern.
+ * @param aggrFuncName function name.
+ * @param dataType data type.
+ * @return
+ * @throws ProcessorException
+ */
+ public static AggregateFunction getAggrFuncByName(String aggrFuncName, TSDataType dataType)
+ throws ProcessorException {
+ if (aggrFuncName == null) {
+ throw new ProcessorException("AggregateFunction Name must not be null");
+ }
+
+ switch (aggrFuncName.toLowerCase()) {
+ case AggregationConstant.MIN_TIME:
+ return new MinTimeAggrFunc();
+ case AggregationConstant.MAX_TIME:
+ return new MaxTimeAggrFunc();
+ case AggregationConstant.MIN_VALUE:
+ return new MinValueAggrFunc(dataType);
+ case AggregationConstant.MAX_VALUE:
+ return new MaxValueAggrFunc(dataType);
+ case AggregationConstant.COUNT:
+ return new CountAggrFunc();
+ case AggregationConstant.MEAN:
+ return new MeanAggrFunc();
+ case AggregationConstant.FIRST:
+ return new FirstAggrFunc(dataType);
+ case AggregationConstant.SUM:
+ return new SumAggrFunc();
+ case AggregationConstant.LAST:
+ return new LastAggrFunc(dataType);
+ default:
+ throw new ProcessorException(
+ "aggregate does not support " + aggrFuncName + " function.");
+ }
+ }
+}
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/query/aggregation/AggregateFunction.java b/iotdb/src/main/java/org/apache/iotdb/db/query/aggregation/AggregateFunction.java
new file mode 100644
index 0000000..34d2d75
--- /dev/null
+++ b/iotdb/src/main/java/org/apache/iotdb/db/query/aggregation/AggregateFunction.java
@@ -0,0 +1,130 @@
+/**
+ * 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.aggregation;
+
+import java.io.IOException;
+import org.apache.iotdb.db.exception.ProcessorException;
+import org.apache.iotdb.db.query.reader.IPointReader;
+import org.apache.iotdb.db.query.reader.merge.EngineReaderByTimeStamp;
+import org.apache.iotdb.db.query.timegenerator.EngineTimeGenerator;
+import org.apache.iotdb.tsfile.file.header.PageHeader;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.read.common.BatchData;
+import org.apache.iotdb.tsfile.utils.Binary;
+
+public abstract class AggregateFunction {
+
+ public String name;
+ public BatchData resultData;
+ public TSDataType dataType;
+ public boolean hasSetValue;
+
+ public AggregateFunction(String name, TSDataType dataType) {
+ this.name = name;
+ this.dataType = dataType;
+ this.hasSetValue = false;
+ resultData = new BatchData(dataType, true, true);
+ }
+
+ public abstract void init();
+
+ public abstract BatchData getResult();
+
+ /**
+ * <p>
+ * Calculate the aggregation using <code>PageHeader</code>.
+ * </p>
+ *
+ * @param pageHeader <code>PageHeader</code>
+ */
+ public abstract void calculateValueFromPageHeader(PageHeader pageHeader)
+ throws ProcessorException;
+
+ /**
+ * <p>
+ * Could not calculate using <method>calculateValueFromPageHeader</method> directly. Calculate the
+ * aggregation according to all decompressed data in this page.
+ * </p>
+ *
+ * @param dataInThisPage the data in the DataPage
+ * @param unsequenceReader unsequence data reader
+ * @throws IOException TsFile data read exception
+ * @throws ProcessorException wrong aggregation method parameter
+ */
+ public abstract void calculateValueFromPageData(BatchData dataInThisPage,
+ IPointReader unsequenceReader) throws IOException, ProcessorException;
+
+ public abstract void calculateValueFromUnsequenceReader(IPointReader unsequenceReader)
+ throws IOException, ProcessorException;
+
+
+ /**
+ * <p>
+ * This method is calculate the aggregation using the common timestamps of cross series filter.
+ * </p>
+ *
+ * @throws IOException TsFile data read error
+ * @throws ProcessorException wrong aggregation method parameter
+ */
+ public abstract boolean calcAggregationUsingTimestamps(EngineTimeGenerator timeGenerator,
+ EngineReaderByTimeStamp sequenceReader, EngineReaderByTimeStamp unsequenceReader)
+ throws IOException, ProcessorException;
+
+ /**
+ * <p>
+ * This method is calculate the group by function.
+ * </p>
+ */
+ public abstract void calcGroupByAggregation(long partitionStart, long partitionEnd,
+ long intervalStart, long intervalEnd,
+ BatchData data) throws ProcessorException;
+
+ /**
+ * Convert a value from string to its real data type and put into return data.
+ */
+ public void putValueFromStr(String valueStr) throws ProcessorException {
+ try {
+ switch (dataType) {
+ case INT32:
+ resultData.putInt(Integer.parseInt(valueStr));
+ break;
+ case INT64:
+ resultData.putLong(Long.parseLong(valueStr));
+ break;
+ case BOOLEAN:
+ resultData.putBoolean(Boolean.parseBoolean(valueStr));
+ break;
+ case TEXT:
+ resultData.putBinary(new Binary(valueStr));
+ break;
+ case DOUBLE:
+ resultData.putDouble(Double.parseDouble(valueStr));
+ break;
+ case FLOAT:
+ resultData.putFloat(Float.parseFloat(valueStr));
+ break;
+ default:
+ throw new ProcessorException("Unsupported type " + dataType);
+ }
+ } catch (Exception e) {
+ throw new ProcessorException(e.getMessage());
+ }
+ }
+}
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/query/aggregation/AggregationConstant.java b/iotdb/src/main/java/org/apache/iotdb/db/query/aggregation/AggregationConstant.java
new file mode 100644
index 0000000..848d9c7
--- /dev/null
+++ b/iotdb/src/main/java/org/apache/iotdb/db/query/aggregation/AggregationConstant.java
@@ -0,0 +1,40 @@
+/**
+ * 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.aggregation;
+
+import org.apache.iotdb.tsfile.common.constant.StatisticConstant;
+
+public class AggregationConstant {
+
+ public static final String MIN_TIME = StatisticConstant.MIN_TIME;
+ public static final String MAX_TIME = StatisticConstant.MAX_TIME;
+
+ public static final String MAX_VALUE = StatisticConstant.MAX_VALUE;
+ public static final String MIN_VALUE = StatisticConstant.MIN_VALUE;
+
+ public static final String COUNT = StatisticConstant.COUNT;
+
+ public static final String FIRST = StatisticConstant.FIRST;
+ public static final String LAST = StatisticConstant.LAST;
+
+ public static final String MEAN = StatisticConstant.MEAN;
+ public static final String SUM = StatisticConstant.SUM;
+
+}
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/query/aggregation/impl/CountAggrFunc.java b/iotdb/src/main/java/org/apache/iotdb/db/query/aggregation/impl/CountAggrFunc.java
new file mode 100644
index 0000000..b5cbc27
--- /dev/null
+++ b/iotdb/src/main/java/org/apache/iotdb/db/query/aggregation/impl/CountAggrFunc.java
@@ -0,0 +1,112 @@
+/**
+ * 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.aggregation.impl;
+
+import java.io.IOException;
+import org.apache.iotdb.db.exception.ProcessorException;
+import org.apache.iotdb.db.query.aggregation.AggregateFunction;
+import org.apache.iotdb.db.query.aggregation.AggregationConstant;
+import org.apache.iotdb.db.query.reader.IPointReader;
+import org.apache.iotdb.db.query.reader.merge.EngineReaderByTimeStamp;
+import org.apache.iotdb.db.query.timegenerator.EngineTimeGenerator;
+import org.apache.iotdb.tsfile.file.header.PageHeader;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.read.common.BatchData;
+
+public class CountAggrFunc extends AggregateFunction {
+
+ public CountAggrFunc() {
+ super(AggregationConstant.COUNT, TSDataType.INT64);
+ }
+
+ @Override
+ public void init() {
+ if (resultData.length() == 0) {
+ resultData.putTime(0);
+ resultData.putLong(0);
+ }
+ }
+
+ @Override
+ public BatchData getResult() {
+ return resultData;
+ }
+
+ @Override
+ public void calculateValueFromPageHeader(PageHeader pageHeader) {
+ System.out.println("PageHeader>>>>>>>>>>>>" + pageHeader.getNumOfValues() + " " + pageHeader
+ .getMinTimestamp()
+ + "," + pageHeader.getMaxTimestamp());
+ long preValue = resultData.getLong();
+ preValue += pageHeader.getNumOfValues();
+ resultData.setLong(0, preValue);
+
+ }
+
+ @Override
+ public void calculateValueFromPageData(BatchData dataInThisPage, IPointReader unsequenceReader)
+ throws IOException, ProcessorException {
+ while (dataInThisPage.hasNext() && unsequenceReader.hasNext()) {
+ if (dataInThisPage.currentTime() == unsequenceReader.current().getTimestamp()) {
+ dataInThisPage.next();
+ unsequenceReader.next();
+ } else if (dataInThisPage.currentTime() < unsequenceReader.current().getTimestamp()) {
+ dataInThisPage.next();
+ } else {
+ unsequenceReader.next();
+ }
+ long preValue = resultData.getLong();
+ preValue += 1;
+ resultData.setLong(0, preValue);
+ }
+
+ if (dataInThisPage.hasNext()) {
+ long preValue = resultData.getLong();
+ preValue += (resultData.length() - resultData.getCurIdx());
+ resultData.setLong(0, preValue);
+ }
+ }
+
+ @Override
+ public void calculateValueFromUnsequenceReader(IPointReader unsequenceReader)
+ throws IOException, ProcessorException {
+ int cnt = 0;
+ while (unsequenceReader.hasNext()) {
+ unsequenceReader.next();
+ cnt++;
+ }
+ long preValue = resultData.getLong();
+ preValue += cnt;
+ resultData.setLong(0, preValue);
+ }
+
+ @Override
+ public boolean calcAggregationUsingTimestamps(EngineTimeGenerator timeGenerator,
+ EngineReaderByTimeStamp sequenceReader, EngineReaderByTimeStamp unsequenceReader)
+ throws IOException, ProcessorException {
+ return false;
+ }
+
+ @Override
+ public void calcGroupByAggregation(long partitionStart, long partitionEnd, long intervalStart,
+ long intervalEnd, BatchData data) throws ProcessorException {
+
+ }
+}
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/query/aggregation/impl/FirstAggrFunc.java b/iotdb/src/main/java/org/apache/iotdb/db/query/aggregation/impl/FirstAggrFunc.java
new file mode 100644
index 0000000..96823ff
--- /dev/null
+++ b/iotdb/src/main/java/org/apache/iotdb/db/query/aggregation/impl/FirstAggrFunc.java
@@ -0,0 +1,114 @@
+/**
+ * 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.aggregation.impl;
+
+import java.io.IOException;
+import org.apache.iotdb.db.exception.ProcessorException;
+import org.apache.iotdb.db.query.aggregation.AggregateFunction;
+import org.apache.iotdb.db.query.aggregation.AggregationConstant;
+import org.apache.iotdb.db.query.reader.IPointReader;
+import org.apache.iotdb.db.query.reader.merge.EngineReaderByTimeStamp;
+import org.apache.iotdb.db.query.timegenerator.EngineTimeGenerator;
+import org.apache.iotdb.tsfile.file.header.PageHeader;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.read.common.BatchData;
+
+public class FirstAggrFunc extends AggregateFunction {
+
+ public FirstAggrFunc(TSDataType dataType) {
+ super(AggregationConstant.FIRST, dataType);
+ }
+
+ @Override
+ public void init() {
+
+ }
+
+ @Override
+ public BatchData getResult() {
+ return resultData;
+ }
+
+ @Override
+ public void calculateValueFromPageHeader(PageHeader pageHeader) throws ProcessorException {
+ if (resultData.length() != 0) {
+ return;
+ }
+
+ Object firstVal = pageHeader.getStatistics().getFirst();
+ if (firstVal == null) {
+ throw new ProcessorException("PageHeader contains no FIRST value");
+ }
+ resultData.setTime(0, 0);
+ resultData.putAnObject(firstVal);
+ }
+
+ @Override
+ public void calculateValueFromPageData(BatchData dataInThisPage, IPointReader unsequenceReader)
+ throws IOException, ProcessorException {
+ if (resultData.length() != 0) {
+ return;
+ }
+ if (dataInThisPage.hasNext() && unsequenceReader.hasNext()) {
+ if (dataInThisPage.currentTime() >= unsequenceReader.current().getTimestamp()) {
+ resultData.setTime(0, 0);
+ resultData.putAnObject(unsequenceReader.current().getValue().getValue());
+ unsequenceReader.next();
+ return;
+ } else {
+ resultData.setTime(0, 0);
+ resultData.putAnObject(dataInThisPage.currentValue());
+ return;
+ }
+ }
+
+ if (dataInThisPage.hasNext()) {
+ resultData.setTime(0, 0);
+ resultData.putAnObject(dataInThisPage.currentValue());
+ return;
+ }
+ }
+
+ @Override
+ public void calculateValueFromUnsequenceReader(IPointReader unsequenceReader)
+ throws IOException, ProcessorException {
+ if (resultData.length() != 0) {
+ return;
+ }
+ if (unsequenceReader.hasNext()) {
+ resultData.setTime(0, 0);
+ resultData.putAnObject(unsequenceReader.current().getValue().getValue());
+ return;
+ }
+ }
+
+ @Override
+ public boolean calcAggregationUsingTimestamps(EngineTimeGenerator timeGenerator,
+ EngineReaderByTimeStamp sequenceReader, EngineReaderByTimeStamp unsequenceReader)
+ throws IOException, ProcessorException {
+ return false;
+ }
+
+ @Override
+ public void calcGroupByAggregation(long partitionStart, long partitionEnd, long intervalStart,
+ long intervalEnd, BatchData data) throws ProcessorException {
+
+ }
+}
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/query/aggregation/impl/LastAggrFunc.java b/iotdb/src/main/java/org/apache/iotdb/db/query/aggregation/impl/LastAggrFunc.java
new file mode 100644
index 0000000..def4c6a
--- /dev/null
+++ b/iotdb/src/main/java/org/apache/iotdb/db/query/aggregation/impl/LastAggrFunc.java
@@ -0,0 +1,135 @@
+/**
+ * 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.aggregation.impl;
+
+import java.io.IOException;
+import org.apache.iotdb.db.exception.ProcessorException;
+import org.apache.iotdb.db.query.aggregation.AggregateFunction;
+import org.apache.iotdb.db.query.aggregation.AggregationConstant;
+import org.apache.iotdb.db.query.reader.IPointReader;
+import org.apache.iotdb.db.query.reader.merge.EngineReaderByTimeStamp;
+import org.apache.iotdb.db.query.timegenerator.EngineTimeGenerator;
+import org.apache.iotdb.db.utils.TimeValuePair;
+import org.apache.iotdb.tsfile.file.header.PageHeader;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.read.common.BatchData;
+
+public class LastAggrFunc extends AggregateFunction {
+
+ public LastAggrFunc(TSDataType dataType) {
+ super(AggregationConstant.LAST, dataType);
+ }
+
+ @Override
+ public void init() {
+
+ }
+
+ @Override
+ public BatchData getResult() {
+ if (resultData.length() != 0) {
+ resultData.setTime(0, 0);
+ }
+ return resultData;
+ }
+
+ @Override
+ public void calculateValueFromPageHeader(PageHeader pageHeader) throws ProcessorException {
+ Object lastVal = pageHeader.getStatistics().getLast();
+ if (resultData.length() == 0) {
+ resultData.putTime(pageHeader.getMaxTimestamp());
+ resultData.putAnObject(lastVal);
+ } else {
+ if (resultData.currentTime() < pageHeader.getMaxTimestamp()) {
+ resultData.setAnObject(0, (Comparable<?>) lastVal);
+ }
+ }
+ }
+
+ @Override
+ public void calculateValueFromPageData(BatchData dataInThisPage, IPointReader unsequenceReader)
+ throws IOException, ProcessorException {
+ long time = -1;
+ Object lastVal = null;
+ int maxIndex = dataInThisPage.length() - 1;
+ if (maxIndex < 0) {
+ return;
+ }
+ time = dataInThisPage.getTimeByIndex(maxIndex);
+ lastVal = dataInThisPage.getValueByIndex(maxIndex);
+ while (unsequenceReader.hasNext()) {
+ if (unsequenceReader.current().getTimestamp() < time) {
+ unsequenceReader.next();
+ } else if (unsequenceReader.current().getTimestamp() == time) {
+ lastVal = unsequenceReader.current().getValue().getValue();
+ unsequenceReader.next();
+ } else {
+ break;
+ }
+ }
+
+ if (resultData.length() == 0) {
+ if (time != -1) {
+ resultData.setTime(0, time);
+ resultData.setAnObject(0, (Comparable<?>) lastVal);
+ }
+ } else {
+ //has set value
+ if (time != -1 && time > resultData.currentTime()) {
+ resultData.setTime(0, time);
+ resultData.setAnObject(0, (Comparable<?>) lastVal);
+ }
+ }
+ }
+
+ @Override
+ public void calculateValueFromUnsequenceReader(IPointReader unsequenceReader)
+ throws IOException, ProcessorException {
+ TimeValuePair pair = null;
+ while (unsequenceReader.hasNext()) {
+ pair = unsequenceReader.next();
+ }
+ if (resultData.length() == 0) {
+ if (pair != null) {
+ resultData.setAnObject(0, (Comparable<?>) pair.getValue().getValue());
+ resultData.setTime(0, pair.getTimestamp());
+ }
+ } else {
+ if (pair != null && pair.getTimestamp() >= resultData.currentTime()) {
+ resultData.setAnObject(0, (Comparable<?>) pair.getValue().getValue());
+ resultData.setTime(0, pair.getTimestamp());
+ }
+ }
+
+ }
+
+ @Override
+ public boolean calcAggregationUsingTimestamps(EngineTimeGenerator timeGenerator,
+ EngineReaderByTimeStamp sequenceReader, EngineReaderByTimeStamp unsequenceReader)
+ throws IOException, ProcessorException {
+ return false;
+ }
+
+ @Override
+ public void calcGroupByAggregation(long partitionStart, long partitionEnd, long intervalStart,
+ long intervalEnd, BatchData data) throws ProcessorException {
+
+ }
+}
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/query/aggregation/impl/MaxTimeAggrFunc.java b/iotdb/src/main/java/org/apache/iotdb/db/query/aggregation/impl/MaxTimeAggrFunc.java
new file mode 100644
index 0000000..8b4adaf
--- /dev/null
+++ b/iotdb/src/main/java/org/apache/iotdb/db/query/aggregation/impl/MaxTimeAggrFunc.java
@@ -0,0 +1,127 @@
+/**
+ * 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.aggregation.impl;
+
+import java.io.IOException;
+import org.apache.iotdb.db.exception.ProcessorException;
+import org.apache.iotdb.db.query.aggregation.AggregateFunction;
+import org.apache.iotdb.db.query.aggregation.AggregationConstant;
+import org.apache.iotdb.db.query.reader.IPointReader;
+import org.apache.iotdb.db.query.reader.merge.EngineReaderByTimeStamp;
+import org.apache.iotdb.db.query.timegenerator.EngineTimeGenerator;
+import org.apache.iotdb.db.utils.TimeValuePair;
+import org.apache.iotdb.tsfile.file.header.PageHeader;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.read.common.BatchData;
+
+public class MaxTimeAggrFunc extends AggregateFunction {
+
+ public MaxTimeAggrFunc() {
+ super(AggregationConstant.MAX_TIME, TSDataType.INT64);
+ }
+
+ @Override
+ public void init() {
+
+ }
+
+ @Override
+ public BatchData getResult() {
+ return resultData;
+ }
+
+ @Override
+ public void calculateValueFromPageHeader(PageHeader pageHeader) throws ProcessorException {
+ long maxTimestamp = pageHeader.getMaxTimestamp();
+
+ //has not set value
+ if (resultData.length() == 0) {
+ resultData.putTime(0);
+ resultData.putLong(maxTimestamp);
+ return;
+ }
+
+ if (resultData.getLong() < maxTimestamp) {
+ resultData.setLong(0, maxTimestamp);
+ }
+ }
+
+ @Override
+ public void calculateValueFromPageData(BatchData dataInThisPage, IPointReader unsequenceReader)
+ throws IOException, ProcessorException {
+ long time = -1;
+ int maxIndex = dataInThisPage.length() - 1;
+ if (maxIndex < 0) {
+ return;
+ }
+ time = dataInThisPage.getTimeByIndex(maxIndex);
+ while (unsequenceReader.hasNext()) {
+ if (unsequenceReader.current().getTimestamp() <= time) {
+ unsequenceReader.next();
+ } else {
+ break;
+ }
+ }
+ if (resultData.length() == 0) {
+ if (time != -1) {
+ resultData.setTime(0, 0);
+ resultData.setAnObject(0, time);
+ }
+ } else {
+ //has set value
+ if (time != -1 && time > resultData.currentTime()) {
+ resultData.setAnObject(0, time);
+ }
+ }
+ }
+
+ @Override
+ public void calculateValueFromUnsequenceReader(IPointReader unsequenceReader)
+ throws IOException, ProcessorException {
+ TimeValuePair pair = null;
+ while (unsequenceReader.hasNext()) {
+ pair = unsequenceReader.next();
+ }
+ if (resultData.length() == 0) {
+ if (pair != null) {
+ resultData.setTime(0, 0);
+ resultData.setAnObject(0, pair.getTimestamp());
+ }
+ } else {
+ //has set value
+ if (pair != null && pair.getTimestamp() > resultData.currentTime()) {
+ resultData.setAnObject(0, pair.getTimestamp());
+ }
+ }
+ }
+
+ @Override
+ public boolean calcAggregationUsingTimestamps(EngineTimeGenerator timeGenerator,
+ EngineReaderByTimeStamp sequenceReader, EngineReaderByTimeStamp unsequenceReader)
+ throws IOException, ProcessorException {
+ return false;
+ }
+
+ @Override
+ public void calcGroupByAggregation(long partitionStart, long partitionEnd, long intervalStart,
+ long intervalEnd, BatchData data) throws ProcessorException {
+
+ }
+}
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/query/aggregation/impl/MaxValueAggrFunc.java b/iotdb/src/main/java/org/apache/iotdb/db/query/aggregation/impl/MaxValueAggrFunc.java
new file mode 100644
index 0000000..ac3d901
--- /dev/null
+++ b/iotdb/src/main/java/org/apache/iotdb/db/query/aggregation/impl/MaxValueAggrFunc.java
@@ -0,0 +1,137 @@
+/**
+ * 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.aggregation.impl;
+
+import java.io.IOException;
+import org.apache.iotdb.db.exception.ProcessorException;
+import org.apache.iotdb.db.query.aggregation.AggregateFunction;
+import org.apache.iotdb.db.query.aggregation.AggregationConstant;
+import org.apache.iotdb.db.query.reader.IPointReader;
+import org.apache.iotdb.db.query.reader.merge.EngineReaderByTimeStamp;
+import org.apache.iotdb.db.query.timegenerator.EngineTimeGenerator;
+import org.apache.iotdb.tsfile.file.header.PageHeader;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.read.common.BatchData;
+
+public class MaxValueAggrFunc extends AggregateFunction {
+
+ public MaxValueAggrFunc(TSDataType dataType) {
+ super(AggregationConstant.MAX_VALUE, dataType);
+ }
+
+ @Override
+ public void init() {
+
+ }
+
+ @Override
+ public BatchData getResult() {
+ return resultData;
+ }
+
+ @Override
+ public void calculateValueFromPageHeader(PageHeader pageHeader) throws ProcessorException {
+ Comparable<Object> maxVal = (Comparable<Object>) pageHeader.getStatistics().getMax();
+ if (resultData.length() == 0) {
+ resultData.putTime(0);
+ resultData.setAnObject(0, maxVal);
+ } else {
+ if (maxVal.compareTo(resultData.currentValue()) > 0) {
+ resultData.setAnObject(0, maxVal);
+ }
+ }
+ }
+
+ @Override
+ public void calculateValueFromPageData(BatchData dataInThisPage, IPointReader unsequenceReader)
+ throws IOException, ProcessorException {
+ Comparable<Object> maxVal = null;
+ while (dataInThisPage.hasNext() && unsequenceReader.hasNext()) {
+ if (dataInThisPage.currentTime() < unsequenceReader.current().getTimestamp()) {
+ if (maxVal == null || maxVal.compareTo(dataInThisPage.currentValue()) < 0) {
+ maxVal = (Comparable<Object>) dataInThisPage.currentValue();
+ }
+ dataInThisPage.next();
+ } else if (dataInThisPage.currentTime() == unsequenceReader.current().getTimestamp()) {
+ if (maxVal == null
+ || maxVal.compareTo(unsequenceReader.current().getValue().getValue()) < 0) {
+ maxVal = (Comparable<Object>) unsequenceReader.current().getValue().getValue();
+ }
+ dataInThisPage.next();
+ unsequenceReader.next();
+ } else {
+ if (maxVal == null
+ || maxVal.compareTo(unsequenceReader.current().getValue().getValue()) < 0) {
+ maxVal = (Comparable<Object>) unsequenceReader.current().getValue().getValue();
+ }
+ unsequenceReader.next();
+ }
+ }
+
+ while (dataInThisPage.hasNext()) {
+ if (maxVal == null
+ || maxVal.compareTo(unsequenceReader.current().getValue().getValue()) < 0) {
+ maxVal = (Comparable<Object>) unsequenceReader.current().getValue().getValue();
+ }
+ dataInThisPage.next();
+ }
+ updateResult(maxVal);
+ }
+
+ @Override
+ public void calculateValueFromUnsequenceReader(IPointReader unsequenceReader)
+ throws IOException, ProcessorException {
+ Comparable<Object> maxVal = null;
+ while (unsequenceReader.hasNext()) {
+ if (maxVal == null
+ || maxVal.compareTo(unsequenceReader.current().getValue().getValue()) < 0) {
+ maxVal = (Comparable<Object>) unsequenceReader.current().getValue().getValue();
+ }
+ unsequenceReader.next();
+ }
+ updateResult(maxVal);
+ }
+
+ private void updateResult(Comparable<Object> maxVal) {
+ if (resultData.length() == 0) {
+ if (maxVal != null) {
+ resultData.putTime(0);
+ resultData.setAnObject(0, maxVal);
+ }
+ } else {
+ if (maxVal != null && maxVal.compareTo(resultData.currentValue()) > 0) {
+ resultData.setAnObject(0, maxVal);
+ }
+ }
+ }
+
+ @Override
+ public boolean calcAggregationUsingTimestamps(EngineTimeGenerator timeGenerator,
+ EngineReaderByTimeStamp sequenceReader, EngineReaderByTimeStamp unsequenceReader)
+ throws IOException, ProcessorException {
+ return false;
+ }
+
+ @Override
+ public void calcGroupByAggregation(long partitionStart, long partitionEnd, long intervalStart,
+ long intervalEnd, BatchData data) throws ProcessorException {
+
+ }
+}
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/query/aggregation/impl/MeanAggrFunc.java b/iotdb/src/main/java/org/apache/iotdb/db/query/aggregation/impl/MeanAggrFunc.java
new file mode 100644
index 0000000..9e56fdc
--- /dev/null
+++ b/iotdb/src/main/java/org/apache/iotdb/db/query/aggregation/impl/MeanAggrFunc.java
@@ -0,0 +1,133 @@
+/**
+ * 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.aggregation.impl;
+
+import java.io.IOException;
+import org.apache.iotdb.db.exception.ProcessorException;
+import org.apache.iotdb.db.query.aggregation.AggregateFunction;
+import org.apache.iotdb.db.query.aggregation.AggregationConstant;
+import org.apache.iotdb.db.query.reader.IPointReader;
+import org.apache.iotdb.db.query.reader.merge.EngineReaderByTimeStamp;
+import org.apache.iotdb.db.query.timegenerator.EngineTimeGenerator;
+import org.apache.iotdb.db.utils.TimeValuePair;
+import org.apache.iotdb.tsfile.file.header.PageHeader;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.read.common.BatchData;
+
+public class MeanAggrFunc extends AggregateFunction {
+ private double sum = 0.0;
+ private int cnt = 0;
+
+ public MeanAggrFunc() {
+ super(AggregationConstant.MEAN, TSDataType.DOUBLE);
+ }
+
+ @Override
+ public void init() {
+ }
+
+ @Override
+ public BatchData getResult() {
+ if (cnt > 0) {
+ resultData.putTime(0);
+ resultData.setDouble(0, sum / cnt);
+ }
+ return resultData;
+ }
+
+ @Override
+ public void calculateValueFromPageHeader(PageHeader pageHeader) throws ProcessorException {
+ sum += pageHeader.getStatistics().getSum();
+ cnt += pageHeader.getNumOfValues();
+ }
+
+ @Override
+ public void calculateValueFromPageData(BatchData dataInThisPage, IPointReader unsequenceReader)
+ throws IOException, ProcessorException {
+ TSDataType type = dataInThisPage.getDataType();
+ while (dataInThisPage.hasNext() && unsequenceReader.hasNext()) {
+ Object sumVal = null;
+ if (dataInThisPage.currentTime() < unsequenceReader.current().getTimestamp()) {
+ sumVal = dataInThisPage.currentValue();
+ dataInThisPage.next();
+ } else if (dataInThisPage.currentTime() == unsequenceReader.current().getTimestamp()) {
+ sumVal = unsequenceReader.current().getValue().getValue();
+ dataInThisPage.next();
+ unsequenceReader.next();
+ } else {
+ sumVal = unsequenceReader.current().getValue().getValue();
+ unsequenceReader.next();
+ }
+ updateMean(type, sumVal);
+ }
+
+ while (dataInThisPage.hasNext()) {
+ updateMean(type, dataInThisPage.currentValue());
+ dataInThisPage.next();
+ }
+ }
+
+ private void updateMean(TSDataType type, Object sumVal) throws ProcessorException {
+ switch (type) {
+ case INT32:
+ sum += (int) sumVal;
+ break;
+ case INT64:
+ sum += (long) sumVal;
+ break;
+ case FLOAT:
+ sum += (float) sumVal;
+ break;
+ case DOUBLE:
+ sum += (double) sumVal;
+ break;
+ case TEXT:
+ case BOOLEAN:
+ default:
+ throw new ProcessorException("Unsupported data type in aggregation MEAN : " + type);
+ }
+ cnt++;
+ }
+
+ @Override
+ public void calculateValueFromUnsequenceReader(IPointReader unsequenceReader)
+ throws IOException, ProcessorException {
+ TSDataType type = null;
+ if (unsequenceReader.hasNext()) {
+ type = unsequenceReader.current().getValue().getDataType();
+ }
+ while (unsequenceReader.hasNext()) {
+ TimeValuePair pair = unsequenceReader.next();
+ updateMean(type, pair.getValue().getValue());
+ }
+ }
+
+ @Override
+ public boolean calcAggregationUsingTimestamps(EngineTimeGenerator timeGenerator,
+ EngineReaderByTimeStamp sequenceReader, EngineReaderByTimeStamp unsequenceReader)
+ throws IOException, ProcessorException {
+ return false;
+ }
+
+ @Override
+ public void calcGroupByAggregation(long partitionStart, long partitionEnd, long intervalStart,
+ long intervalEnd, BatchData data) throws ProcessorException {
+
+ }
+}
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/query/aggregation/impl/MinTimeAggrFunc.java b/iotdb/src/main/java/org/apache/iotdb/db/query/aggregation/impl/MinTimeAggrFunc.java
new file mode 100644
index 0000000..4dca740
--- /dev/null
+++ b/iotdb/src/main/java/org/apache/iotdb/db/query/aggregation/impl/MinTimeAggrFunc.java
@@ -0,0 +1,108 @@
+/**
+ * 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.aggregation.impl;
+
+import java.io.IOException;
+import org.apache.iotdb.db.exception.ProcessorException;
+import org.apache.iotdb.db.query.aggregation.AggregateFunction;
+import org.apache.iotdb.db.query.aggregation.AggregationConstant;
+import org.apache.iotdb.db.query.reader.IPointReader;
+import org.apache.iotdb.db.query.reader.merge.EngineReaderByTimeStamp;
+import org.apache.iotdb.db.query.timegenerator.EngineTimeGenerator;
+import org.apache.iotdb.tsfile.file.header.PageHeader;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.read.common.BatchData;
+
+public class MinTimeAggrFunc extends AggregateFunction {
+
+ public MinTimeAggrFunc() {
+ super(AggregationConstant.MIN_TIME, TSDataType.INT64);
+ }
+
+ @Override
+ public void init() {
+
+ }
+
+ @Override
+ public BatchData getResult() {
+ return resultData;
+ }
+
+ @Override
+ public void calculateValueFromPageHeader(PageHeader pageHeader) throws ProcessorException {
+ if (resultData.length() > 0) {
+ return;
+ }
+ long time = pageHeader.getMinTimestamp();
+ resultData.putTime(0);
+ resultData.putLong(time);
+ }
+
+ @Override
+ public void calculateValueFromPageData(BatchData dataInThisPage, IPointReader unsequenceReader)
+ throws IOException, ProcessorException {
+ if (resultData.length() > 0) {
+ return;
+ }
+
+ if (dataInThisPage.hasNext() && unsequenceReader.hasNext()) {
+ if (dataInThisPage.currentTime() < unsequenceReader.current().getTimestamp()) {
+ resultData.putTime(0);
+ resultData.putLong(dataInThisPage.currentTime());
+ } else {
+ resultData.putTime(0);
+ resultData.putLong(unsequenceReader.current().getTimestamp());
+ }
+ return;
+ }
+
+ if (dataInThisPage.hasNext()) {
+ resultData.putTime(0);
+ resultData.putLong(dataInThisPage.currentTime());
+ }
+ }
+
+ @Override
+ public void calculateValueFromUnsequenceReader(IPointReader unsequenceReader)
+ throws IOException, ProcessorException {
+ if (resultData.length() > 0) {
+ return;
+ }
+ if (unsequenceReader.hasNext()) {
+ resultData.putTime(0);
+ resultData.putLong(unsequenceReader.current().getTimestamp());
+ }
+ }
+
+ @Override
+ public boolean calcAggregationUsingTimestamps(EngineTimeGenerator timeGenerator,
+ EngineReaderByTimeStamp sequenceReader, EngineReaderByTimeStamp unsequenceReader)
+ throws IOException, ProcessorException {
+ return false;
+ }
+
+ @Override
+ public void calcGroupByAggregation(long partitionStart, long partitionEnd, long intervalStart,
+ long intervalEnd, BatchData data) throws ProcessorException {
+
+ }
+
+}
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/query/aggregation/impl/MinValueAggrFunc.java b/iotdb/src/main/java/org/apache/iotdb/db/query/aggregation/impl/MinValueAggrFunc.java
new file mode 100644
index 0000000..e60ab45
--- /dev/null
+++ b/iotdb/src/main/java/org/apache/iotdb/db/query/aggregation/impl/MinValueAggrFunc.java
@@ -0,0 +1,138 @@
+/**
+ * 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.aggregation.impl;
+
+import java.io.IOException;
+import org.apache.iotdb.db.exception.ProcessorException;
+import org.apache.iotdb.db.query.aggregation.AggregateFunction;
+import org.apache.iotdb.db.query.aggregation.AggregationConstant;
+import org.apache.iotdb.db.query.reader.IPointReader;
+import org.apache.iotdb.db.query.reader.merge.EngineReaderByTimeStamp;
+import org.apache.iotdb.db.query.timegenerator.EngineTimeGenerator;
+import org.apache.iotdb.tsfile.file.header.PageHeader;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.read.common.BatchData;
+
+public class MinValueAggrFunc extends AggregateFunction {
+
+ public MinValueAggrFunc(TSDataType dataType) {
+ super(AggregationConstant.MIN_VALUE, dataType);
+ }
+
+ @Override
+ public void init() {
+
+ }
+
+ @Override
+ public BatchData getResult() {
+ return resultData;
+ }
+
+ @Override
+ public void calculateValueFromPageHeader(PageHeader pageHeader) throws ProcessorException {
+ Comparable<Object> minVal = (Comparable<Object>) pageHeader.getStatistics().getMin();
+ if (resultData.length() == 0) {
+ resultData.putTime(0);
+ resultData.setAnObject(0, minVal);
+ } else {
+ if (minVal.compareTo(resultData.currentValue()) < 0) {
+ resultData.setAnObject(0, minVal);
+ }
+ }
+ }
+
+ @Override
+ public void calculateValueFromPageData(BatchData dataInThisPage, IPointReader unsequenceReader)
+ throws IOException, ProcessorException {
+ Comparable<Object> minVal = null;
+ while (dataInThisPage.hasNext() && unsequenceReader.hasNext()) {
+ if (dataInThisPage.currentTime() < unsequenceReader.current().getTimestamp()) {
+ if (minVal == null || minVal.compareTo(dataInThisPage.currentValue()) > 0) {
+ minVal = (Comparable<Object>) dataInThisPage.currentValue();
+ }
+ dataInThisPage.next();
+ } else if (dataInThisPage.currentTime() == unsequenceReader.current().getTimestamp()) {
+ if (minVal == null
+ || minVal.compareTo(unsequenceReader.current().getValue().getValue()) > 0) {
+ minVal = (Comparable<Object>) unsequenceReader.current().getValue().getValue();
+ }
+ dataInThisPage.next();
+ unsequenceReader.next();
+ } else {
+ if (minVal == null
+ || minVal.compareTo(unsequenceReader.current().getValue().getValue()) > 0) {
+ minVal = (Comparable<Object>) unsequenceReader.current().getValue().getValue();
+ }
+ unsequenceReader.next();
+ }
+ }
+
+ while (dataInThisPage.hasNext()) {
+ if (minVal == null
+ || minVal.compareTo(unsequenceReader.current().getValue().getValue()) > 0) {
+ minVal = (Comparable<Object>) unsequenceReader.current().getValue().getValue();
+ }
+ dataInThisPage.next();
+ }
+ updateResult(minVal);
+ }
+
+ @Override
+ public void calculateValueFromUnsequenceReader(IPointReader unsequenceReader)
+ throws IOException, ProcessorException {
+ Comparable<Object> minVal = null;
+ while (unsequenceReader.hasNext()) {
+ if (minVal == null
+ || minVal.compareTo(unsequenceReader.current().getValue().getValue()) > 0) {
+ minVal = (Comparable<Object>) unsequenceReader.current().getValue().getValue();
+ }
+ unsequenceReader.next();
+ }
+ updateResult(minVal);
+ }
+
+ private void updateResult(Comparable<Object> minVal) {
+ if (resultData.length() == 0) {
+ if (minVal != null) {
+ resultData.putTime(0);
+ resultData.setAnObject(0, minVal);
+ }
+ } else {
+ if (minVal != null && minVal.compareTo(resultData.currentValue()) < 0) {
+ resultData.setAnObject(0, minVal);
+ }
+ }
+ }
+
+ @Override
+ public boolean calcAggregationUsingTimestamps(EngineTimeGenerator timeGenerator,
+ EngineReaderByTimeStamp sequenceReader, EngineReaderByTimeStamp unsequenceReader)
+ throws IOException, ProcessorException {
+ return false;
+ }
+
+ @Override
+ public void calcGroupByAggregation(long partitionStart, long partitionEnd, long intervalStart,
+ long intervalEnd, BatchData data) throws ProcessorException {
+
+ }
+
+}
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/query/aggregation/impl/SumAggrFunc.java b/iotdb/src/main/java/org/apache/iotdb/db/query/aggregation/impl/SumAggrFunc.java
new file mode 100644
index 0000000..642d2a7
--- /dev/null
+++ b/iotdb/src/main/java/org/apache/iotdb/db/query/aggregation/impl/SumAggrFunc.java
@@ -0,0 +1,130 @@
+/**
+ * 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.aggregation.impl;
+
+import java.io.IOException;
+import org.apache.iotdb.db.exception.ProcessorException;
+import org.apache.iotdb.db.query.aggregation.AggregateFunction;
+import org.apache.iotdb.db.query.aggregation.AggregationConstant;
+import org.apache.iotdb.db.query.reader.IPointReader;
+import org.apache.iotdb.db.query.reader.merge.EngineReaderByTimeStamp;
+import org.apache.iotdb.db.query.timegenerator.EngineTimeGenerator;
+import org.apache.iotdb.db.utils.TimeValuePair;
+import org.apache.iotdb.tsfile.file.header.PageHeader;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.read.common.BatchData;
+
+public class SumAggrFunc extends AggregateFunction {
+
+ private double sum = 0.0;
+
+ public SumAggrFunc() {
+ super(AggregationConstant.SUM, TSDataType.DOUBLE);
+ }
+
+ @Override
+ public void init() {
+
+ }
+
+ @Override
+ public BatchData getResult() {
+ resultData.setDouble(0, sum);
+ return resultData;
+ }
+
+ @Override
+ public void calculateValueFromPageHeader(PageHeader pageHeader) throws ProcessorException {
+ sum += pageHeader.getStatistics().getSum();
+ }
+
+ @Override
+ public void calculateValueFromPageData(BatchData dataInThisPage, IPointReader unsequenceReader)
+ throws IOException, ProcessorException {
+ TSDataType type = dataInThisPage.getDataType();
+ while (dataInThisPage.hasNext() && unsequenceReader.hasNext()) {
+ Object sumVal = null;
+ if (dataInThisPage.currentTime() < unsequenceReader.current().getTimestamp()) {
+ sumVal = dataInThisPage.currentValue();
+ dataInThisPage.next();
+ } else if (dataInThisPage.currentTime() == unsequenceReader.current().getTimestamp()) {
+ sumVal = unsequenceReader.current().getValue().getValue();
+ dataInThisPage.next();
+ unsequenceReader.next();
+ } else {
+ sumVal = unsequenceReader.current().getValue().getValue();
+ unsequenceReader.next();
+ }
+ updateSum(type, sumVal);
+ }
+
+ while (dataInThisPage.hasNext()) {
+ updateSum(type, dataInThisPage.currentValue());
+ dataInThisPage.next();
+ }
+ }
+
+ private void updateSum(TSDataType type, Object sumVal) throws ProcessorException {
+ switch (type) {
+ case INT32:
+ sum += (int) sumVal;
+ break;
+ case INT64:
+ sum += (long) sumVal;
+ break;
+ case FLOAT:
+ sum += (float) sumVal;
+ break;
+ case DOUBLE:
+ sum += (double) sumVal;
+ break;
+ case TEXT:
+ case BOOLEAN:
+ default:
+ throw new ProcessorException("Unsupported data type in aggregation MEAN : " + type);
+ }
+ }
+
+ @Override
+ public void calculateValueFromUnsequenceReader(IPointReader unsequenceReader)
+ throws IOException, ProcessorException {
+ TSDataType type = null;
+ if (unsequenceReader.hasNext()) {
+ type = unsequenceReader.current().getValue().getDataType();
+ }
+ while (unsequenceReader.hasNext()) {
+ TimeValuePair pair = unsequenceReader.next();
+ updateSum(type, pair.getValue().getValue());
+ }
+ }
+
+ @Override
+ public boolean calcAggregationUsingTimestamps(EngineTimeGenerator timeGenerator,
+ EngineReaderByTimeStamp sequenceReader, EngineReaderByTimeStamp unsequenceReader)
+ throws IOException, ProcessorException {
+ return false;
+ }
+
+ @Override
+ public void calcGroupByAggregation(long partitionStart, long partitionEnd, long intervalStart,
+ long intervalEnd, BatchData data) throws ProcessorException {
+
+ }
+}
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/query/dataset/AggregateDataSet.java b/iotdb/src/main/java/org/apache/iotdb/db/query/dataset/AggregateDataSet.java
new file mode 100644
index 0000000..00fe608
--- /dev/null
+++ b/iotdb/src/main/java/org/apache/iotdb/db/query/dataset/AggregateDataSet.java
@@ -0,0 +1,138 @@
+/**
+ * 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.dataset;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.PriorityQueue;
+import org.apache.iotdb.tsfile.exception.write.UnSupportedDataTypeException;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.read.common.BatchData;
+import org.apache.iotdb.tsfile.read.common.Field;
+import org.apache.iotdb.tsfile.read.common.Path;
+import org.apache.iotdb.tsfile.read.common.RowRecord;
+import org.apache.iotdb.tsfile.read.query.dataset.QueryDataSet;
+
+public class AggregateDataSet extends QueryDataSet {
+ private List<BatchData> readers;
+
+ private PriorityQueue<Long> timeHeap;
+
+ private List<String> aggres;
+
+ /**
+ * constructor of EngineDataSetWithoutTimeGenerator.
+ *
+ * @param paths paths in List structure
+ * @param aggres aggregate function name
+ * @param dataTypes time series data type
+ * @param readers readers in List(IReader) structure
+ * @throws IOException IOException
+ */
+ public AggregateDataSet(List<Path> paths, List<String> aggres, List<TSDataType> dataTypes,
+ List<BatchData> readers)
+ throws IOException {
+ super(paths, dataTypes);
+ this.readers = readers;
+ initHeap();
+ }
+
+ private void initHeap(){
+ timeHeap = new PriorityQueue<>();
+
+ for (int i = 0; i < readers.size(); i++) {
+ BatchData reader = readers.get(i);
+ if (reader.hasNext()) {
+ timeHeap.add(reader.currentTime());
+ }
+ }
+ }
+
+ @Override
+ public boolean hasNext() {
+ return !timeHeap.isEmpty();
+ }
+
+ @Override
+ public RowRecord next() throws IOException {
+ long minTime = timeHeapGet();
+
+ RowRecord record = new RowRecord(minTime);
+
+ for (int i = 0; i < readers.size(); i++) {
+ BatchData reader = readers.get(i);
+ if (!reader.hasNext()) {
+ record.addField(new Field(null));
+ } else {
+ if (reader.currentTime() == minTime) {
+ record.addField(getField(reader, dataTypes.get(i)));
+ reader.next();
+ if (reader.hasNext()) {
+ timeHeap.add(reader.currentTime());
+ }
+ } else {
+ record.addField(new Field(null));
+ }
+ }
+ }
+
+ return record;
+ }
+
+ private Field getField(BatchData batchData, TSDataType dataType) {
+ Field field = new Field(dataType);
+ switch (dataType) {
+ case INT32:
+ field.setIntV(batchData.getInt());
+ break;
+ case INT64:
+ field.setLongV(batchData.getLong());
+ break;
+ case FLOAT:
+ field.setFloatV(batchData.getFloat());
+ break;
+ case DOUBLE:
+ field.setDoubleV(batchData.getDouble());
+ break;
+ case BOOLEAN:
+ field.setBoolV(batchData.getBoolean());
+ break;
+ case TEXT:
+ field.setBinaryV(batchData.getBinary());
+ break;
+ default:
+ throw new UnSupportedDataTypeException("UnSupported: " + dataType);
+ }
+ return field;
+ }
+
+ private Long timeHeapGet() {
+ Long t = timeHeap.peek();
+ while (!timeHeap.isEmpty()){
+ if(timeHeap.peek() == t){
+ timeHeap.poll();
+ }
+ else {
+ break;
+ }
+ }
+ return t;
+ }
+}
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/query/executor/AggregateEngineExecutor.java b/iotdb/src/main/java/org/apache/iotdb/db/query/executor/AggregateEngineExecutor.java
new file mode 100644
index 0000000..4cb269f
--- /dev/null
+++ b/iotdb/src/main/java/org/apache/iotdb/db/query/executor/AggregateEngineExecutor.java
@@ -0,0 +1,158 @@
+/**
+ * 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.executor;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.iotdb.db.engine.querycontext.QueryDataSource;
+import org.apache.iotdb.db.exception.FileNodeManagerException;
+import org.apache.iotdb.db.exception.PathErrorException;
+import org.apache.iotdb.db.exception.ProcessorException;
+import org.apache.iotdb.db.metadata.MManager;
+import org.apache.iotdb.db.query.aggregation.AggreFuncFactory;
+import org.apache.iotdb.db.query.aggregation.impl.LastAggrFunc;
+import org.apache.iotdb.db.query.aggregation.impl.MaxTimeAggrFunc;
+import org.apache.iotdb.db.query.context.QueryContext;
+import org.apache.iotdb.db.query.control.QueryDataSourceManager;
+import org.apache.iotdb.db.query.control.QueryTokenManager;
+import org.apache.iotdb.db.query.dataset.AggregateDataSet;
+import org.apache.iotdb.db.query.factory.SeriesReaderFactory;
+import org.apache.iotdb.db.query.reader.IAggregateReader;
+import org.apache.iotdb.db.query.reader.IPointReader;
+import org.apache.iotdb.db.query.reader.merge.PriorityMergeReader;
+import org.apache.iotdb.db.query.reader.sequence.SequenceDataReader;
+import org.apache.iotdb.tsfile.file.header.PageHeader;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.read.common.BatchData;
+import org.apache.iotdb.tsfile.read.common.Path;
+import org.apache.iotdb.tsfile.read.expression.IExpression;
+import org.apache.iotdb.tsfile.read.expression.impl.GlobalTimeExpression;
+import org.apache.iotdb.tsfile.read.filter.basic.Filter;
+
+public class AggregateEngineExecutor {
+ private long jobId;
+ private List<Path> selectedSeries;
+ private List<String> aggres;
+ private IExpression expression;
+
+ public AggregateEngineExecutor(long jobId, List<Path> selectedSeries, List<String> aggres, IExpression expression) {
+ this.jobId = jobId;
+ this.selectedSeries = selectedSeries;
+ this.aggres = aggres;
+ this.expression = expression;
+ }
+
+ public AggregateDataSet executeWithOutTimeGenerator(QueryContext context)
+ throws FileNodeManagerException, IOException, PathErrorException, ProcessorException {
+ Filter timeFilter = null;
+ if(timeFilter!=null){
+ timeFilter = ((GlobalTimeExpression)expression).getFilter();
+ }
+ QueryTokenManager.getInstance().beginQueryOfGivenQueryPaths(jobId, selectedSeries);
+
+ List<IAggregateReader> readersOfSequenceData = new ArrayList<>();
+ List<IPointReader> readersOfUnSequenceData = new ArrayList<>();
+ List<AggregateFunction> aggregateFunctions = new ArrayList<>();
+ for(int i = 0; i < selectedSeries.size(); i++){
+ //construct AggregateFunction
+ TSDataType tsDataType = MManager.getInstance().getSeriesType(selectedSeries.get(i).getFullPath());
+ AggregateFunction function = AggreFuncFactory.getAggrFuncByName(aggres.get(i), tsDataType);
+ function.init();
+ aggregateFunctions.add(function);
+
+ QueryDataSource queryDataSource = QueryDataSourceManager.getQueryDataSource(jobId, selectedSeries.get(i), context);
+ // sequence reader for sealed tsfile, unsealed tsfile, memory
+ SequenceDataReader sequenceReader = new SequenceDataReader(queryDataSource.getSeqDataSource(), timeFilter, context);
+ // unseq reader for all chunk groups in unSeqFile, memory
+ PriorityMergeReader unSeqMergeReader = SeriesReaderFactory.getInstance().createUnSeqMergeReader(queryDataSource.getOverflowSeriesDataSource(), timeFilter);
+ readersOfSequenceData.add(sequenceReader);
+ readersOfUnSequenceData.add(unSeqMergeReader);
+ }
+
+ List<BatchData> batchDatas = new ArrayList<BatchData>();
+ //TODO use multi-thread
+ for(int i = 0; i < selectedSeries.size(); i++){
+ BatchData batchData = aggregateWithOutTimeGenerator(aggregateFunctions.get(i), readersOfSequenceData.get(i), readersOfUnSequenceData.get(i));
+ batchDatas.add(batchData);
+ }
+ return constructDataSet(batchDatas);
+ }
+
+ private BatchData aggregateWithOutTimeGenerator(AggregateFunction function, IAggregateReader sequenceReader, IPointReader unSequenceReader)
+ throws IOException, ProcessorException {
+ if (function instanceof MaxTimeAggrFunc || function instanceof LastAggrFunc){
+ //TODO Optimization
+ return function.getResult();
+ }
+
+ while (sequenceReader.hasNext()){
+ PageHeader pageHeader = sequenceReader.nextPageHeader();
+ //judge if overlap with unsequence data
+ if(canUseHeader(pageHeader, unSequenceReader)){
+ //cal by pageHeader
+ function.calculateValueFromPageHeader(pageHeader);
+ sequenceReader.skipPageData();
+ }
+ else {
+ //cal by pageData
+ function.calculateValueFromPageData(sequenceReader.nextBatch(), unSequenceReader);
+ }
+ }
+
+ //cal with unsequence data
+ if(unSequenceReader.hasNext()){
+ function.calculateValueFromUnsequenceReader(unSequenceReader);
+ }
+ return function.getResult();
+ }
+
+ private boolean canUseHeader(PageHeader pageHeader, IPointReader unSequenceReader)
+ throws IOException {
+ //if page data is memory data.
+ if(pageHeader == null){
+ return false;
+ }
+
+ long minTime = pageHeader.getMinTimestamp();
+ long maxTime = pageHeader.getMaxTimestamp();
+ while(unSequenceReader.hasNext() && unSequenceReader.current().getTimestamp() <= maxTime){
+ if(minTime <= unSequenceReader.current().getTimestamp()){
+ return false;
+ }
+ unSequenceReader.next();
+ }
+ return true;
+ }
+
+ public AggregateDataSet executeWithTimeGenerator(QueryContext context){
+ return null;
+ }
+
+ private AggregateDataSet constructDataSet(List<BatchData> batchDataList) throws IOException {
+ List<TSDataType> dataTypes = new ArrayList<>();
+ for(BatchData batchData : batchDataList){
+ dataTypes.add(batchData.getDataType());
+ }
+ return new AggregateDataSet(selectedSeries,aggres,dataTypes, batchDataList);
+ }
+
+
+}
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/query/executor/EngineQueryRouter.java b/iotdb/src/main/java/org/apache/iotdb/db/query/executor/EngineQueryRouter.java
index c9327f4..b5a996f 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/query/executor/EngineQueryRouter.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/query/executor/EngineQueryRouter.java
@@ -16,18 +16,23 @@
* specific language governing permissions and limitations
* under the License.
*/
+
package org.apache.iotdb.db.query.executor;
import static org.apache.iotdb.tsfile.read.expression.ExpressionType.GLOBAL_TIME;
import java.io.IOException;
+import java.util.List;
import java.util.concurrent.atomic.AtomicLong;
import org.apache.iotdb.db.exception.FileNodeManagerException;
import org.apache.iotdb.db.exception.PathErrorException;
+import org.apache.iotdb.db.exception.ProcessorException;
import org.apache.iotdb.db.query.context.QueryContext;
import org.apache.iotdb.db.query.control.OpenedFilePathsManager;
import org.apache.iotdb.db.query.control.QueryTokenManager;
+import org.apache.iotdb.db.query.dataset.AggregateDataSet;
import org.apache.iotdb.tsfile.exception.filter.QueryFilterOptimizationException;
+import org.apache.iotdb.tsfile.read.common.Path;
import org.apache.iotdb.tsfile.read.expression.IExpression;
import org.apache.iotdb.tsfile.read.expression.QueryExpression;
import org.apache.iotdb.tsfile.read.expression.util.ExpressionOptimizer;
@@ -88,6 +93,36 @@ public class EngineQueryRouter {
}
}
+ /**
+ * execute aggregation query.
+ */
+ public AggregateDataSet aggregate(List<Path> selectedSeries, List<String> aggres,
+ IExpression expression)
+ throws QueryFilterOptimizationException, FileNodeManagerException, IOException, PathErrorException, ProcessorException {
+
+ long nextJobId = getNextJobId();
+ QueryTokenManager.getInstance().setJobIdForCurrentRequestThread(nextJobId);
+ OpenedFilePathsManager.getInstance().setJobIdForCurrentRequestThread(nextJobId);
+
+ QueryContext context = new QueryContext();
+
+ if (expression != null) {
+ IExpression optimizedExpression = ExpressionOptimizer.getInstance()
+ .optimize(expression, selectedSeries);
+ AggregateEngineExecutor engineExecutor = new AggregateEngineExecutor(nextJobId,
+ selectedSeries, aggres, optimizedExpression);
+ if (optimizedExpression.getType() == GLOBAL_TIME) {
+ return engineExecutor.executeWithOutTimeGenerator(context);
+ } else {
+ return engineExecutor.executeWithTimeGenerator(context);
+ }
+ } else {
+ AggregateEngineExecutor engineExecutor = new AggregateEngineExecutor(nextJobId,
+ selectedSeries, aggres, expression);
+ return engineExecutor.executeWithOutTimeGenerator(context);
+ }
+ }
+
private synchronized long getNextJobId() {
return jobIdGenerator.incrementAndGet();
}
diff --git a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/common/BatchData.java b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/common/BatchData.java
index ffb37e2..e853440 100644
--- a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/common/BatchData.java
+++ b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/common/BatchData.java
@@ -527,4 +527,62 @@ public class BatchData {
public int length() {
return this.timeLength;
}
+
+ public int getCurIdx() {
+ return curIdx;
+ }
+
+ public long getTimeByIndex(int idx){
+ rangeCheckForTime(idx);
+ return this.timeRet.get(idx / timeCapacity)[idx % timeCapacity];
+ }
+
+ public long getLongByIndex(int idx){
+ rangeCheck(idx);
+ return this.longRet.get(idx / timeCapacity)[idx % timeCapacity];
+ }
+
+ public double getDoubleByIndex(int idx) {
+ rangeCheck(idx);
+ return this.doubleRet.get(idx / timeCapacity)[idx % timeCapacity];
+ }
+
+ public int getIntByIndex(int idx) {
+ rangeCheck(idx);
+ return this.intRet.get(idx / timeCapacity)[idx % timeCapacity];
+ }
+
+ public float getFloatByIndex(int idx) {
+ rangeCheck(idx);
+ return this.floatRet.get(idx / timeCapacity)[idx % timeCapacity];
+ }
+
+ public Binary getBinaryByIndex(int idx) {
+ rangeCheck(idx);
+ return binaryRet.get(idx / timeCapacity)[idx % timeCapacity];
+ }
+
+ public boolean getBooleanByIndex(int idx) {
+ rangeCheck(idx);
+ return booleanRet.get(idx / timeCapacity)[idx % timeCapacity];
+ }
+
+ public Object getValueByIndex(int idx) {
+ switch (dataType) {
+ case INT32:
+ return getIntByIndex(idx);
+ case INT64:
+ return getLongByIndex(idx);
+ case FLOAT:
+ return getFloatByIndex(idx);
+ case DOUBLE:
+ return getDoubleByIndex(idx);
+ case BOOLEAN:
+ return getBooleanByIndex(idx);
+ case TEXT:
+ return getBinaryByIndex(idx);
+ default:
+ return null;
+ }
+ }
}