You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ja...@apache.org on 2025/09/02 01:33:25 UTC
(iotdb) branch dev/1.3 updated: [to dev/1.3] Supports streaming load mem chunk & Push down filter, limit and offset to MemPointIterator
This is an automated email from the ASF dual-hosted git repository.
jackietien pushed a commit to branch dev/1.3
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/dev/1.3 by this push:
new 2b9fdb9b863 [to dev/1.3] Supports streaming load mem chunk & Push down filter, limit and offset to MemPointIterator
2b9fdb9b863 is described below
commit 2b9fdb9b863be0a8013cd07507964a30f7e6ef91
Author: shuwenwei <55...@users.noreply.github.com>
AuthorDate: Tue Sep 2 09:33:17 2025 +0800
[to dev/1.3] Supports streaming load mem chunk & Push down filter, limit and offset to MemPointIterator
---
.../db/it/aligned/IoTDBAlignedMemQueryIT.java | 97 +++
.../java/org/apache/iotdb/db/conf/IoTDBConfig.java | 11 +
.../execution/operator/source/FileLoaderUtils.java | 6 +-
.../execution/operator/source/SeriesScanUtil.java | 341 +++++++--
.../schemaregion/utils/ResourceByPathUtils.java | 113 ++-
.../memtable/AlignedReadOnlyMemChunk.java | 118 ++-
.../dataregion/memtable/ReadOnlyMemChunk.java | 76 +-
.../read/reader/chunk/MemAlignedChunkLoader.java | 27 +-
.../read/reader/chunk/MemChunkLoader.java | 21 +-
.../dataregion/tsfile/TsFileResource.java | 6 +-
.../apache/iotdb/db/utils/ModificationUtils.java | 32 +-
.../db/utils/datastructure/AlignedTVList.java | 314 +++++---
.../db/utils/datastructure/MemPointIterator.java | 73 +-
.../datastructure/MemPointIteratorFactory.java | 136 +++-
.../MergeSortMultiAlignedTVListIterator.java | 66 +-
.../MergeSortMultiTVListIterator.java | 36 +-
.../datastructure/MultiAlignedTVListIterator.java | 127 +++-
.../utils/datastructure/MultiTVListIterator.java | 196 +++--
.../OrderedMultiAlignedTVListIterator.java | 16 +-
.../datastructure/OrderedMultiTVListIterator.java | 15 +-
.../iotdb/db/utils/datastructure/TVList.java | 248 +++++--
.../memtable/AlignedTVListIteratorTest.java | 807 +++++++++++++++++++++
.../memtable/NonAlignedTVListIteratorTest.java | 630 ++++++++++++++++
.../reader/chunk/MemAlignedChunkLoaderTest.java | 1 +
.../read/reader/chunk/MemChunkLoaderTest.java | 6 +
25 files changed, 3088 insertions(+), 431 deletions(-)
diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBAlignedMemQueryIT.java b/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBAlignedMemQueryIT.java
new file mode 100644
index 00000000000..036698c28c0
--- /dev/null
+++ b/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBAlignedMemQueryIT.java
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.db.it.aligned;
+
+import org.apache.iotdb.it.env.EnvFactory;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Locale;
+
+import static org.junit.Assert.assertEquals;
+
+public class IoTDBAlignedMemQueryIT {
+
+ @Before
+ public void setUp() throws Exception {
+ Locale.setDefault(Locale.ENGLISH);
+ EnvFactory.getEnv()
+ .getConfig()
+ .getCommonConfig()
+ .setPartitionInterval(1000)
+ .setMemtableSizeThreshold(10000);
+ EnvFactory.getEnv().initClusterEnvironment();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ EnvFactory.getEnv().cleanClusterEnvironment();
+ }
+
+ @Test
+ public void test() throws SQLException {
+ try (Connection connection = EnvFactory.getEnv().getConnection();
+ Statement statement = connection.createStatement()) {
+
+ statement.execute("insert into root.vehicle.d0(time,s0) aligned values (10,310)");
+ statement.execute("insert into root.vehicle.d0(time,s3) aligned values (10,'text')");
+ statement.execute("insert into root.vehicle.d0(time,s4) aligned values (10,true)");
+
+ try (ResultSet set = statement.executeQuery("SELECT s0 FROM root.vehicle.d0")) {
+ int cnt = 0;
+ while (set.next()) {
+ cnt++;
+ }
+ assertEquals(1, cnt);
+ }
+
+ statement.execute("insert into root.vehicle.d1(time,s0,s1) aligned values (1,1,1)");
+ statement.execute("insert into root.vehicle.d1(time,s0) aligned values (2,2)");
+ statement.execute("insert into root.vehicle.d1(time,s1) aligned values (3,3)");
+
+ try (ResultSet set = statement.executeQuery("SELECT s0 FROM root.vehicle.d1")) {
+ int cnt = 0;
+ while (set.next()) {
+ cnt++;
+ }
+ assertEquals(2, cnt);
+ }
+ statement.execute("flush");
+
+ statement.execute("insert into root.vehicle.d1(time,s0,s1) aligned values (1,1,1)");
+ statement.execute("insert into root.vehicle.d1(time,s0) aligned values (2,2)");
+ statement.execute("insert into root.vehicle.d1(time,s1) aligned values (3,3)");
+
+ try (ResultSet set = statement.executeQuery("SELECT s0 FROM root.vehicle.d1")) {
+ int cnt = 0;
+ while (set.next()) {
+ cnt++;
+ }
+ assertEquals(2, cnt);
+ }
+ }
+ }
+}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java
index 024debf4bf9..3d2b6b6fa5e 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java
@@ -439,6 +439,9 @@ public class IoTDBConfig {
*/
private int tvListSortThreshold = 0;
+ /** Enable streaming query mem chunk */
+ private boolean streamingQueryMemChunk = true;
+
/** Enable inner space compaction for sequence files */
private volatile boolean enableSeqSpaceCompaction = true;
@@ -2319,6 +2322,14 @@ public class IoTDBConfig {
this.tvListSortThreshold = tvListSortThreshold;
}
+ public boolean isStreamingQueryMemChunk() {
+ return streamingQueryMemChunk;
+ }
+
+ public void setStreamingQueryMemChunk(boolean streamingQueryMemChunk) {
+ this.streamingQueryMemChunk = streamingQueryMemChunk;
+ }
+
public boolean isRpcThriftCompressionEnable() {
return rpcThriftCompressionEnable;
}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/FileLoaderUtils.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/FileLoaderUtils.java
index c472b9ca607..dfee7204c62 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/FileLoaderUtils.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/FileLoaderUtils.java
@@ -127,7 +127,8 @@ public class FileLoaderUtils {
} else { // if the tsfile is unclosed, we just get it directly from TsFileResource
loadFromMem = true;
- timeSeriesMetadata = (TimeseriesMetadata) resource.getTimeSeriesMetadata(seriesPath);
+ timeSeriesMetadata =
+ (TimeseriesMetadata) resource.getTimeSeriesMetadata(seriesPath, globalTimeFilter);
if (timeSeriesMetadata != null) {
timeSeriesMetadata.setChunkMetadataLoader(
new MemChunkMetadataLoader(resource, seriesPath, context, globalTimeFilter));
@@ -192,7 +193,8 @@ public class FileLoaderUtils {
} else { // if the tsfile is unclosed, we just get it directly from TsFileResource
loadFromMem = true;
alignedTimeSeriesMetadata =
- (AlignedTimeSeriesMetadata) resource.getTimeSeriesMetadata(alignedPath);
+ (AlignedTimeSeriesMetadata)
+ resource.getTimeSeriesMetadata(alignedPath, globalTimeFilter);
if (alignedTimeSeriesMetadata != null) {
alignedTimeSeriesMetadata.setChunkMetadataLoader(
new MemAlignedChunkMetadataLoader(resource, alignedPath, context, globalTimeFilter));
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/SeriesScanUtil.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/SeriesScanUtil.java
index 76a817f18ef..d9e49d63ebf 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/SeriesScanUtil.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/SeriesScanUtil.java
@@ -27,14 +27,19 @@ import org.apache.iotdb.db.queryengine.metric.SeriesScanCostMetricSet;
import org.apache.iotdb.db.queryengine.plan.analyze.cache.schema.DataNodeTTLCache;
import org.apache.iotdb.db.queryengine.plan.planner.plan.parameter.SeriesScanOptions;
import org.apache.iotdb.db.queryengine.plan.statement.component.Ordering;
+import org.apache.iotdb.db.storageengine.dataregion.memtable.AlignedReadOnlyMemChunk;
+import org.apache.iotdb.db.storageengine.dataregion.memtable.ReadOnlyMemChunk;
import org.apache.iotdb.db.storageengine.dataregion.read.QueryDataSource;
import org.apache.iotdb.db.storageengine.dataregion.read.reader.chunk.MemAlignedPageReader;
+import org.apache.iotdb.db.storageengine.dataregion.read.reader.chunk.MemChunkLoader;
import org.apache.iotdb.db.storageengine.dataregion.read.reader.chunk.MemPageReader;
import org.apache.iotdb.db.storageengine.dataregion.read.reader.common.DescPriorityMergeReader;
import org.apache.iotdb.db.storageengine.dataregion.read.reader.common.MergeReaderPriority;
import org.apache.iotdb.db.storageengine.dataregion.read.reader.common.PriorityMergeReader;
import org.apache.iotdb.db.storageengine.dataregion.tsfile.TsFileResource;
+import org.apache.iotdb.db.utils.datastructure.MemPointIterator;
+import org.apache.tsfile.common.conf.TSFileDescriptor;
import org.apache.tsfile.enums.TSDataType;
import org.apache.tsfile.file.metadata.IChunkMetadata;
import org.apache.tsfile.file.metadata.IDeviceID;
@@ -42,9 +47,11 @@ import org.apache.tsfile.file.metadata.IMetadata;
import org.apache.tsfile.file.metadata.ITimeSeriesMetadata;
import org.apache.tsfile.file.metadata.statistics.Statistics;
import org.apache.tsfile.read.TimeValuePair;
+import org.apache.tsfile.read.common.TimeRange;
import org.apache.tsfile.read.common.block.TsBlock;
import org.apache.tsfile.read.common.block.TsBlockBuilder;
import org.apache.tsfile.read.common.block.TsBlockUtil;
+import org.apache.tsfile.read.controller.IChunkLoader;
import org.apache.tsfile.read.filter.basic.Filter;
import org.apache.tsfile.read.reader.IPageReader;
import org.apache.tsfile.read.reader.IPointReader;
@@ -82,7 +89,7 @@ public class SeriesScanUtil implements Accountable {
private final TSDataType dataType;
// inner class of SeriesReader for order purpose
- private final TimeOrderUtils orderUtils;
+ protected final TimeOrderUtils orderUtils;
private QueryDataSource dataSource;
@@ -100,9 +107,9 @@ public class SeriesScanUtil implements Accountable {
private final PriorityQueue<IChunkMetadata> cachedChunkMetadata;
// page cache
- private VersionPageReader firstPageReader;
- private final List<VersionPageReader> seqPageReaders;
- private final PriorityQueue<VersionPageReader> unSeqPageReaders;
+ private IVersionPageReader firstPageReader;
+ private final List<IVersionPageReader> seqPageReaders;
+ private final PriorityQueue<IVersionPageReader> unSeqPageReaders;
// point cache
private final PriorityMergeReader mergeReader;
@@ -116,6 +123,8 @@ public class SeriesScanUtil implements Accountable {
private static final SeriesScanCostMetricSet SERIES_SCAN_COST_METRIC_SET =
SeriesScanCostMetricSet.getInstance();
+ protected final int MAX_NUMBER_OF_POINTS_IN_PAGE =
+ TSFileDescriptor.getInstance().getConfig().getMaxNumberOfPointsInPage();
private static final long INSTANCE_SIZE =
RamUsageEstimator.shallowSizeOfInstance(SeriesScanUtil.class)
@@ -583,9 +592,17 @@ public class SeriesScanUtil implements Accountable {
}
private void unpackOneChunkMetaData(IChunkMetadata chunkMetaData) throws IOException {
+ long timestampInFileName = FileLoaderUtils.getTimestampInFileName(chunkMetaData);
+
+ IChunkLoader chunkLoader = chunkMetaData.getChunkLoader();
+ if ((chunkLoader instanceof MemChunkLoader)
+ && ((MemChunkLoader) chunkLoader).isStreamingQueryMemChunk()) {
+ unpackOneFakeMemChunkMetaData(
+ chunkMetaData, (MemChunkLoader) chunkLoader, timestampInFileName);
+ return;
+ }
List<IPageReader> pageReaderList =
FileLoaderUtils.loadPageReaderList(chunkMetaData, scanOptions.getGlobalTimeFilter());
- long timestampInFileName = FileLoaderUtils.getTimestampInFileName(chunkMetaData);
// init TsBlockBuilder for each page reader
pageReaderList.forEach(p -> p.initTsBlockBuilder(getTsDataTypeList()));
@@ -628,6 +645,39 @@ public class SeriesScanUtil implements Accountable {
}
}
+ private void unpackOneFakeMemChunkMetaData(
+ IChunkMetadata chunkMetaData, MemChunkLoader chunkLoader, long timestampInFileName) {
+ ReadOnlyMemChunk readOnlyMemChunk = chunkLoader.getReadOnlyMemChunk();
+ boolean isAligned = readOnlyMemChunk instanceof AlignedReadOnlyMemChunk;
+ List<Statistics<? extends Serializable>> statisticsList =
+ isAligned
+ ? ((AlignedReadOnlyMemChunk) readOnlyMemChunk).getTimeStatisticsList()
+ : readOnlyMemChunk.getPageStatisticsList();
+
+ // we need to create a new MemPointIterator for SeriesScanUtil because streaming scan method
+ // don't support sharing MemPointIterator
+ MemPointIterator memPointIterator =
+ readOnlyMemChunk.createMemPointIterator(
+ orderUtils.getScanOrder(), scanOptions.getGlobalTimeFilter());
+ for (Statistics<? extends Serializable> statistics : statisticsList) {
+ IVersionPageReader versionPageReader =
+ new LazyMemVersionPageReader(
+ context,
+ timestampInFileName,
+ chunkMetaData.getVersion(),
+ chunkMetaData.getOffsetOfChunkHeader(),
+ isAligned,
+ statistics,
+ memPointIterator,
+ chunkMetaData.isSeq());
+ if (chunkMetaData.isSeq()) {
+ seqPageReaders.add(versionPageReader);
+ } else {
+ unSeqPageReaders.add(versionPageReader);
+ }
+ }
+ }
+
@SuppressWarnings("unchecked")
private boolean currentPageOverlapped() throws IOException {
// This method should be called after calling hasNextPage.
@@ -664,8 +714,8 @@ public class SeriesScanUtil implements Accountable {
if (currentPageOverlapped() || firstPageReader.isModified()) {
return false;
}
- return filterAllSatisfy(scanOptions.getGlobalTimeFilter(), firstPageReader.data)
- && filterAllSatisfy(scanOptions.getPushDownFilter(), firstPageReader.data);
+ return filterAllSatisfy(scanOptions.getGlobalTimeFilter(), firstPageReader.getPageReader())
+ && filterAllSatisfy(scanOptions.getPushDownFilter(), firstPageReader.getPageReader());
}
@SuppressWarnings("squid:S3740")
@@ -707,6 +757,25 @@ public class SeriesScanUtil implements Accountable {
}
firstPageReader.addPushDownFilter(scanOptions.getPushDownFilter());
+
+ if (firstPageReader instanceof LazyMemVersionPageReader) {
+ firstPageReader.setLimitOffset(paginationController);
+ LazyMemVersionPageReader lazyMemVersionPageReader =
+ (LazyMemVersionPageReader) firstPageReader;
+ // We must set the time range before actually reading the required data because
+ // MemPointIterator is shared by multiple Pages
+ lazyMemVersionPageReader.setCurrentPageTimeRangeToMemPointIterator();
+ lazyMemVersionPageReader.setInited();
+ // There is no need to consider scan order here, because the tsBlock returned here has been
+ // processed in MemPointIterator
+ TsBlock tsBlock =
+ lazyMemVersionPageReader.hasNextBatch() ? lazyMemVersionPageReader.nextBatch() : null;
+ if (!lazyMemVersionPageReader.hasNextBatch()) {
+ firstPageReader = null;
+ }
+ return tsBlock;
+ }
+
TsBlock tsBlock;
if (orderUtils.getAscending()) {
firstPageReader.setLimitOffset(paginationController);
@@ -733,14 +802,11 @@ public class SeriesScanUtil implements Accountable {
}
private void filterFirstPageReader() {
- if (firstPageReader == null) {
+ if (firstPageReader == null || firstPageReader.isModified()) {
return;
}
- IPageReader pageReader = firstPageReader.data;
- if (pageReader.isModified()) {
- return;
- }
+ IPageReader pageReader = firstPageReader.getPageReader();
// globalTimeFilter.canSkip() must be FALSE
Filter pushDownFilter = scanOptions.getPushDownFilter();
@@ -834,15 +900,7 @@ public class SeriesScanUtil implements Accountable {
timeValuePair.getTimestamp(), firstPageReader.getStatistics())) {
// current timeValuePair is overlapped with firstPageReader, add it to merged reader
// and update endTime to the max end time
- mergeReader.addReader(
- getPointReader(
- firstPageReader.getAllSatisfiedPageData(orderUtils.getAscending())),
- firstPageReader.version,
- orderUtils.getOverlapCheckTime(firstPageReader.getStatistics()));
- context
- .getQueryStatistics()
- .getPageReaderMaxUsedMemorySize()
- .updateAndGet(v -> Math.max(v, mergeReader.getUsedMemorySize()));
+ putPageReaderToMergeReader(firstPageReader);
currentPageEndPointTime =
updateEndPointTime(currentPageEndPointTime, firstPageReader);
firstPageReader = null;
@@ -862,15 +920,8 @@ public class SeriesScanUtil implements Accountable {
return hasCachedNextOverlappedPage;
} else if (orderUtils.isOverlapped(
timeValuePair.getTimestamp(), seqPageReaders.get(0).getStatistics())) {
- VersionPageReader pageReader = seqPageReaders.remove(0);
- mergeReader.addReader(
- getPointReader(pageReader.getAllSatisfiedPageData(orderUtils.getAscending())),
- pageReader.version,
- orderUtils.getOverlapCheckTime(pageReader.getStatistics()));
- context
- .getQueryStatistics()
- .getPageReaderMaxUsedMemorySize()
- .updateAndGet(v -> Math.max(v, mergeReader.getUsedMemorySize()));
+ IVersionPageReader pageReader = seqPageReaders.remove(0);
+ putPageReaderToMergeReader(pageReader);
currentPageEndPointTime = updateEndPointTime(currentPageEndPointTime, pageReader);
}
}
@@ -878,6 +929,10 @@ public class SeriesScanUtil implements Accountable {
// get the latest first point in mergeReader
timeValuePair = mergeReader.nextTimeValuePair();
addTimeValuePairToResult(timeValuePair, builder);
+ // A PageReader from MemChunk may have a lot of data, so it needs to be checked here
+ if (builder.getPositionCount() >= MAX_NUMBER_OF_POINTS_IN_PAGE) {
+ break;
+ }
}
hasCachedNextOverlappedPage = !builder.isEmpty();
cachedTsBlock = builder.build();
@@ -903,7 +958,7 @@ public class SeriesScanUtil implements Accountable {
}
}
- private long updateEndPointTime(long currentPageEndPointTime, VersionPageReader pageReader) {
+ private long updateEndPointTime(long currentPageEndPointTime, IVersionPageReader pageReader) {
if (orderUtils.getAscending()) {
return Math.min(currentPageEndPointTime, pageReader.getStatistics().getEndTime());
} else {
@@ -983,7 +1038,7 @@ public class SeriesScanUtil implements Accountable {
private void initFirstPageReader() throws IOException {
while (this.firstPageReader == null) {
- VersionPageReader firstPageReader = getFirstPageReaderFromCachedReaders();
+ IVersionPageReader firstPageReader = getFirstPageReaderFromCachedReaders();
// unpack overlapped page using current page reader
if (firstPageReader != null) {
@@ -1011,8 +1066,8 @@ public class SeriesScanUtil implements Accountable {
}
// We use get() and peek() here in case it's not the first page reader before unpacking
- private VersionPageReader getFirstPageReaderFromCachedReaders() {
- VersionPageReader firstPageReader = null;
+ private IVersionPageReader getFirstPageReaderFromCachedReaders() {
+ IVersionPageReader firstPageReader = null;
if (!seqPageReaders.isEmpty() && !unSeqPageReaders.isEmpty()) {
if (orderUtils.isTakeSeqAsFirst(
seqPageReaders.get(0).getStatistics(), unSeqPageReaders.peek().getStatistics())) {
@@ -1031,7 +1086,7 @@ public class SeriesScanUtil implements Accountable {
private void unpackAllOverlappedUnseqPageReadersToMergeReader(long endpointTime)
throws IOException {
while (!unSeqPageReaders.isEmpty()
- && orderUtils.isOverlapped(endpointTime, unSeqPageReaders.peek().data.getStatistics())) {
+ && orderUtils.isOverlapped(endpointTime, unSeqPageReaders.peek().getStatistics())) {
putPageReaderToMergeReader(unSeqPageReaders.poll());
}
if (firstPageReader != null
@@ -1042,10 +1097,26 @@ public class SeriesScanUtil implements Accountable {
}
}
- private void putPageReaderToMergeReader(VersionPageReader pageReader) throws IOException {
+ private void putPageReaderToMergeReader(IVersionPageReader pageReader) throws IOException {
+ IPointReader pointReader;
+ if (pageReader instanceof LazyMemVersionPageReader) {
+ // There may be many VersionPageReaders belonging to the same MemChunk sharing a
+ // MemPointIterator, but the time ranges of these pages sharing it must not overlap, so there
+ // will be no problem of reading data from the MemPointIterator at the same time
+ LazyMemVersionPageReader lazyMemPageReader = (LazyMemVersionPageReader) pageReader;
+ // We must set the time range before actually reading the required data because
+ // MemPointIterator is shared by multiple Pages
+ lazyMemPageReader.setCurrentPageTimeRangeToMemPointIterator();
+ lazyMemPageReader.setInited();
+ // There is no need to consider scanOrder here, because MemPointIterator has already returned
+ // according to the current scan order
+ pointReader = lazyMemPageReader.getPointReader();
+ } else {
+ pointReader = getPointReader(pageReader.getAllSatisfiedPageData(orderUtils.getAscending()));
+ }
mergeReader.addReader(
- getPointReader(pageReader.getAllSatisfiedPageData(orderUtils.getAscending())),
- pageReader.version,
+ pointReader,
+ pageReader.getVersion(),
orderUtils.getOverlapCheckTime(pageReader.getStatistics()));
context
.getQueryStatistics()
@@ -1236,14 +1307,36 @@ public class SeriesScanUtil implements Accountable {
return filter == null || filter.allSatisfy(metadata);
}
- protected static class VersionPageReader {
- private final QueryContext context;
- private final MergeReaderPriority version;
- private final IPageReader data;
+ protected interface IVersionPageReader {
+ Statistics getStatistics();
+
+ Statistics getMeasurementStatistics(int index);
+
+ Statistics getTimeStatistics();
+
+ TsBlock getAllSatisfiedPageData(boolean ascending) throws IOException;
+
+ MergeReaderPriority getVersion();
+
+ IPageReader getPageReader();
+
+ void addPushDownFilter(Filter pushDownFilter);
+
+ boolean isModified();
+
+ boolean isSeq();
+
+ void setLimitOffset(PaginationController paginationController);
+ }
+
+ protected static class VersionPageReader implements IVersionPageReader {
+ protected final QueryContext context;
+ protected final MergeReaderPriority version;
+ protected final IPageReader data;
- private final boolean isSeq;
- private final boolean isAligned;
- private final boolean isMem;
+ protected final boolean isSeq;
+ protected final boolean isAligned;
+ protected final boolean isMem;
VersionPageReader(
QueryContext context,
@@ -1261,21 +1354,30 @@ public class SeriesScanUtil implements Accountable {
}
@SuppressWarnings("squid:S3740")
- Statistics getStatistics() {
+ public Statistics getStatistics() {
return data.getStatistics();
}
@SuppressWarnings("squid:S3740")
- Statistics getMeasurementStatistics(int index) {
+ public Statistics getMeasurementStatistics(int index) {
return data.getMeasurementStatistics(index).orElse(null);
}
@SuppressWarnings("squid:S3740")
- Statistics getTimeStatistics() {
+ public Statistics getTimeStatistics() {
return data.getTimeStatistics();
}
- TsBlock getAllSatisfiedPageData(boolean ascending) throws IOException {
+ @Override
+ public MergeReaderPriority getVersion() {
+ return version;
+ }
+
+ public IPageReader getPageReader() {
+ return data;
+ }
+
+ public TsBlock getAllSatisfiedPageData(boolean ascending) throws IOException {
long startTime = System.nanoTime();
try {
TsBlock tsBlock = data.getAllSatisfiedData();
@@ -1305,11 +1407,11 @@ public class SeriesScanUtil implements Accountable {
}
}
- void addPushDownFilter(Filter pushDownFilter) {
+ public void addPushDownFilter(Filter pushDownFilter) {
data.addRecordFilter(pushDownFilter);
}
- boolean isModified() {
+ public boolean isModified() {
return data.isModified();
}
@@ -1322,6 +1424,131 @@ public class SeriesScanUtil implements Accountable {
}
}
+ protected static class LazyMemVersionPageReader implements IVersionPageReader {
+
+ private final Statistics<? extends Serializable> statistics;
+ private final MemPointIterator memPointIterator;
+ protected final QueryContext context;
+ protected final MergeReaderPriority version;
+
+ protected final boolean isSeq;
+ protected final boolean isAligned;
+ private boolean inited = false;
+
+ LazyMemVersionPageReader(
+ QueryContext context,
+ long fileTimestamp,
+ long version,
+ long offset,
+ boolean isAligned,
+ Statistics<? extends Serializable> statistics,
+ MemPointIterator memPointIterator,
+ boolean isSeq) {
+ this.statistics = statistics;
+ this.memPointIterator = memPointIterator;
+ this.context = context;
+ this.version = new MergeReaderPriority(fileTimestamp, version, offset, isSeq);
+ this.isSeq = isSeq;
+ this.isAligned = isAligned;
+ }
+
+ public IPointReader getPointReader() {
+ return memPointIterator;
+ }
+
+ public boolean hasNextBatch() {
+ return memPointIterator.hasNextBatch();
+ }
+
+ public void setCurrentPageTimeRangeToMemPointIterator() {
+ if (inited) {
+ return;
+ }
+ if (statistics.getStartTime() > statistics.getEndTime()) {
+ // empty
+ return;
+ }
+ this.memPointIterator.setCurrentPageTimeRange(
+ new TimeRange(statistics.getStartTime(), statistics.getEndTime()));
+ }
+
+ public TsBlock nextBatch() {
+ long startTime = System.nanoTime();
+ try {
+ return memPointIterator.nextBatch();
+ } finally {
+ long time = System.nanoTime() - startTime;
+ if (isAligned) {
+ context.getQueryStatistics().getPageReadersDecodeAlignedMemCount().getAndAdd(1);
+ context.getQueryStatistics().getPageReadersDecodeAlignedMemTime().getAndAdd(time);
+ } else {
+ context.getQueryStatistics().getPageReadersDecodeAlignedMemCount().getAndAdd(1);
+ context.getQueryStatistics().getPageReadersDecodeNonAlignedMemTime().getAndAdd(time);
+ }
+ }
+ }
+
+ @Override
+ public Statistics getStatistics() {
+ return statistics;
+ }
+
+ @Override
+ public Statistics getMeasurementStatistics(int index) {
+ return statistics;
+ }
+
+ @Override
+ public Statistics getTimeStatistics() {
+ return statistics;
+ }
+
+ @Override
+ public TsBlock getAllSatisfiedPageData(boolean ascending) {
+ throw new UnsupportedOperationException("getAllSatisfiedPageData() shouldn't be called here");
+ }
+
+ @Override
+ public MergeReaderPriority getVersion() {
+ return version;
+ }
+
+ @Override
+ public IPageReader getPageReader() {
+ throw new UnsupportedOperationException("getPageReader() shouldn't be called here");
+ }
+
+ @Override
+ public void addPushDownFilter(Filter pushDownFilter) {
+ if (inited) {
+ return;
+ }
+ memPointIterator.setPushDownFilter(pushDownFilter);
+ }
+
+ @Override
+ public void setLimitOffset(PaginationController paginationController) {
+ if (inited) {
+ return;
+ }
+ memPointIterator.setLimitAndOffset(paginationController);
+ }
+
+ @Override
+ public boolean isModified() {
+ return true;
+ }
+
+ @Override
+ public boolean isSeq() {
+ return isSeq;
+ }
+
+ public void setInited() {
+ inited = true;
+ }
+ }
+
public interface TimeOrderUtils {
long getOrderTime(Statistics<? extends Object> statistics);
@@ -1351,6 +1578,8 @@ public class SeriesScanUtil implements Accountable {
boolean getAscending();
+ Ordering getScanOrder();
+
boolean hasNextSeqResource();
boolean hasNextUnseqResource();
@@ -1435,6 +1664,11 @@ public class SeriesScanUtil implements Accountable {
return false;
}
+ @Override
+ public Ordering getScanOrder() {
+ return Ordering.DESC;
+ }
+
@Override
public boolean hasNextSeqResource() {
while (dataSource.hasNextSeqResource(curSeqFileIndex, false, deviceID)) {
@@ -1559,6 +1793,11 @@ public class SeriesScanUtil implements Accountable {
return true;
}
+ @Override
+ public Ordering getScanOrder() {
+ return Ordering.ASC;
+ }
+
@Override
public boolean hasNextSeqResource() {
while (dataSource.hasNextSeqResource(curSeqFileIndex, true, deviceID)) {
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/utils/ResourceByPathUtils.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/utils/ResourceByPathUtils.java
index 78dce2cff39..a66f19108ea 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/utils/ResourceByPathUtils.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/utils/ResourceByPathUtils.java
@@ -21,6 +21,7 @@ package org.apache.iotdb.db.schemaengine.schemaregion.utils;
import org.apache.iotdb.commons.path.AlignedPath;
import org.apache.iotdb.commons.path.MeasurementPath;
import org.apache.iotdb.commons.path.PartialPath;
+import org.apache.iotdb.db.conf.IoTDBDescriptor;
import org.apache.iotdb.db.exception.query.QueryProcessException;
import org.apache.iotdb.db.queryengine.execution.fragment.FragmentInstanceContext;
import org.apache.iotdb.db.queryengine.execution.fragment.QueryContext;
@@ -84,7 +85,9 @@ public abstract class ResourceByPathUtils {
}
public abstract ITimeSeriesMetadata generateTimeSeriesMetadata(
- List<ReadOnlyMemChunk> readOnlyMemChunk, List<IChunkMetadata> chunkMetadataList)
+ List<ReadOnlyMemChunk> readOnlyMemChunk,
+ List<IChunkMetadata> chunkMetadataList,
+ Filter globalTimeFilter)
throws IOException;
public abstract ReadOnlyMemChunk getReadOnlyMemChunkFromMemTable(
@@ -219,12 +222,19 @@ class AlignedResourceByPathUtils extends ResourceByPathUtils {
*/
@Override
public AlignedTimeSeriesMetadata generateTimeSeriesMetadata(
- List<ReadOnlyMemChunk> readOnlyMemChunk, List<IChunkMetadata> chunkMetadataList) {
+ List<ReadOnlyMemChunk> readOnlyMemChunk,
+ List<IChunkMetadata> chunkMetadataList,
+ Filter globalTimeFilter) {
TimeseriesMetadata timeTimeSeriesMetadata = new TimeseriesMetadata();
timeTimeSeriesMetadata.setDataSizeOfChunkMetaDataList(-1);
timeTimeSeriesMetadata.setMeasurementId("");
timeTimeSeriesMetadata.setTsDataType(TSDataType.VECTOR);
+ boolean useFakeStatistics =
+ !readOnlyMemChunk.isEmpty()
+ && IoTDBDescriptor.getInstance().getConfig().isStreamingQueryMemChunk();
+ long startTime = Long.MAX_VALUE;
+ long endTime = Long.MIN_VALUE;
Statistics<? extends Serializable> timeStatistics =
Statistics.getStatsByType(timeTimeSeriesMetadata.getTsDataType());
@@ -244,25 +254,7 @@ class AlignedResourceByPathUtils extends ResourceByPathUtils {
for (IChunkMetadata chunkMetadata : chunkMetadataList) {
AlignedChunkMetadata alignedChunkMetadata = (AlignedChunkMetadata) chunkMetadata;
modified = (modified || alignedChunkMetadata.isModified());
- timeStatistics.mergeStatistics(alignedChunkMetadata.getTimeChunkMetadata().getStatistics());
- for (int i = 0; i < valueTimeSeriesMetadataList.size(); i++) {
- if (alignedChunkMetadata.getValueChunkMetadataList().get(i) != null) {
- exist[i] = true;
- valueTimeSeriesMetadataList
- .get(i)
- .getStatistics()
- .mergeStatistics(
- alignedChunkMetadata.getValueChunkMetadataList().get(i).getStatistics());
- }
- }
- }
-
- for (ReadOnlyMemChunk memChunk : readOnlyMemChunk) {
- if (!memChunk.isEmpty()) {
- memChunk.sortTvLists();
- memChunk.initChunkMetaFromTvLists();
- AlignedChunkMetadata alignedChunkMetadata =
- (AlignedChunkMetadata) memChunk.getChunkMetaData();
+ if (!useFakeStatistics) {
timeStatistics.mergeStatistics(alignedChunkMetadata.getTimeChunkMetadata().getStatistics());
for (int i = 0; i < valueTimeSeriesMetadataList.size(); i++) {
if (alignedChunkMetadata.getValueChunkMetadataList().get(i) != null) {
@@ -274,14 +266,57 @@ class AlignedResourceByPathUtils extends ResourceByPathUtils {
alignedChunkMetadata.getValueChunkMetadataList().get(i).getStatistics());
}
}
+ continue;
+ }
+ startTime = Math.min(startTime, chunkMetadata.getStartTime());
+ endTime = Math.max(endTime, chunkMetadata.getEndTime());
+ }
+
+ for (ReadOnlyMemChunk memChunk : readOnlyMemChunk) {
+ if (!memChunk.isEmpty()) {
+ memChunk.sortTvLists();
+ if (useFakeStatistics) {
+ memChunk.initChunkMetaFromTVListsWithFakeStatistics();
+ startTime = Math.min(startTime, memChunk.getChunkMetaData().getStartTime());
+ endTime = Math.max(endTime, memChunk.getChunkMetaData().getEndTime());
+ } else {
+ memChunk.initChunkMetaFromTvLists(globalTimeFilter);
+ }
+ AlignedChunkMetadata alignedChunkMetadata =
+ (AlignedChunkMetadata) memChunk.getChunkMetaData();
+ if (!useFakeStatistics) {
+ timeStatistics.mergeStatistics(
+ alignedChunkMetadata.getTimeChunkMetadata().getStatistics());
+ for (int i = 0; i < valueTimeSeriesMetadataList.size(); i++) {
+ if (alignedChunkMetadata.getValueChunkMetadataList().get(i) != null) {
+ exist[i] = true;
+ valueTimeSeriesMetadataList
+ .get(i)
+ .getStatistics()
+ .mergeStatistics(
+ alignedChunkMetadata.getValueChunkMetadataList().get(i).getStatistics());
+ }
+ }
+ }
}
}
timeTimeSeriesMetadata.setStatistics(timeStatistics);
- timeTimeSeriesMetadata.setModified(modified);
+ if (useFakeStatistics) {
+ timeStatistics.setStartTime(startTime);
+ timeStatistics.setEndTime(endTime);
+ timeStatistics.setCount(1);
+ }
+ timeTimeSeriesMetadata.setModified(useFakeStatistics || modified);
for (int i = 0; i < valueTimeSeriesMetadataList.size(); i++) {
- if (!exist[i]) {
+ if (useFakeStatistics) {
+ TimeseriesMetadata valueTimeseriesMetadata = valueTimeSeriesMetadataList.get(i);
+ valueTimeseriesMetadata.getStatistics().setStartTime(startTime);
+ valueTimeseriesMetadata.getStatistics().setEndTime(endTime);
+ valueTimeseriesMetadata.getStatistics().setCount(1);
+ valueTimeseriesMetadata.setModified(useFakeStatistics || modified);
+ } else if (!exist[i]) {
valueTimeSeriesMetadataList.set(i, null);
}
}
@@ -420,30 +455,52 @@ class MeasurementResourceByPathUtils extends ResourceByPathUtils {
*/
@Override
public ITimeSeriesMetadata generateTimeSeriesMetadata(
- List<ReadOnlyMemChunk> readOnlyMemChunk, List<IChunkMetadata> chunkMetadataList) {
+ List<ReadOnlyMemChunk> readOnlyMemChunk,
+ List<IChunkMetadata> chunkMetadataList,
+ Filter globalTimeFilter) {
+ boolean useFakeStatistics =
+ !readOnlyMemChunk.isEmpty()
+ && IoTDBDescriptor.getInstance().getConfig().isStreamingQueryMemChunk();
TimeseriesMetadata timeSeriesMetadata = new TimeseriesMetadata();
timeSeriesMetadata.setMeasurementId(partialPath.getMeasurementSchema().getMeasurementId());
timeSeriesMetadata.setTsDataType(partialPath.getMeasurementSchema().getType());
timeSeriesMetadata.setDataSizeOfChunkMetaDataList(-1);
+ long startTime = Long.MAX_VALUE;
+ long endTime = Long.MIN_VALUE;
Statistics<? extends Serializable> seriesStatistics =
Statistics.getStatsByType(timeSeriesMetadata.getTsDataType());
// flush chunkMetadataList one by one
boolean isModified = false;
for (IChunkMetadata chunkMetadata : chunkMetadataList) {
isModified = (isModified || chunkMetadata.isModified());
- seriesStatistics.mergeStatistics(chunkMetadata.getStatistics());
+ if (!useFakeStatistics) {
+ seriesStatistics.mergeStatistics(chunkMetadata.getStatistics());
+ continue;
+ }
+ startTime = Math.min(startTime, chunkMetadata.getStartTime());
+ endTime = Math.max(endTime, chunkMetadata.getEndTime());
}
for (ReadOnlyMemChunk memChunk : readOnlyMemChunk) {
if (!memChunk.isEmpty()) {
memChunk.sortTvLists();
- memChunk.initChunkMetaFromTvLists();
- seriesStatistics.mergeStatistics(memChunk.getChunkMetaData().getStatistics());
+ if (useFakeStatistics) {
+ memChunk.initChunkMetaFromTVListsWithFakeStatistics();
+ startTime = Math.min(startTime, memChunk.getChunkMetaData().getStartTime());
+ endTime = Math.max(endTime, memChunk.getChunkMetaData().getEndTime());
+ } else {
+ memChunk.initChunkMetaFromTvLists(globalTimeFilter);
+ seriesStatistics.mergeStatistics(memChunk.getChunkMetaData().getStatistics());
+ }
}
}
+ if (useFakeStatistics) {
+ seriesStatistics.setStartTime(startTime);
+ seriesStatistics.setEndTime(endTime);
+ }
timeSeriesMetadata.setStatistics(seriesStatistics);
- timeSeriesMetadata.setModified(isModified);
+ timeSeriesMetadata.setModified(useFakeStatistics || isModified);
return timeSeriesMetadata;
}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/memtable/AlignedReadOnlyMemChunk.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/memtable/AlignedReadOnlyMemChunk.java
index bfe78f0336d..db19d099f18 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/memtable/AlignedReadOnlyMemChunk.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/memtable/AlignedReadOnlyMemChunk.java
@@ -20,6 +20,7 @@
package org.apache.iotdb.db.storageengine.dataregion.memtable;
import org.apache.iotdb.db.queryengine.execution.fragment.QueryContext;
+import org.apache.iotdb.db.queryengine.plan.statement.component.Ordering;
import org.apache.iotdb.db.storageengine.dataregion.read.reader.chunk.MemAlignedChunkLoader;
import org.apache.iotdb.db.utils.datastructure.AlignedTVList;
import org.apache.iotdb.db.utils.datastructure.MemPointIterator;
@@ -38,6 +39,7 @@ import org.apache.tsfile.read.TimeValuePair;
import org.apache.tsfile.read.common.TimeRange;
import org.apache.tsfile.read.common.block.TsBlock;
import org.apache.tsfile.read.common.block.TsBlockBuilder;
+import org.apache.tsfile.read.filter.basic.Filter;
import org.apache.tsfile.read.reader.IPointReader;
import org.apache.tsfile.utils.TsPrimitiveType;
import org.apache.tsfile.write.UnSupportedDataTypeException;
@@ -73,7 +75,8 @@ public class AlignedReadOnlyMemChunk extends ReadOnlyMemChunk {
// When we select two of time series [s1, s3], the column index list should be [0, 2]
private final List<Integer> columnIndexList;
- private MemPointIterator timeValuePairIterator;
+ // Only used when StreamingQueryMemChunk is configured as false
+ private MemPointIterator nonStreamingTimeValuePairIterator;
/**
* The constructor for Aligned type.
@@ -116,7 +119,7 @@ public class AlignedReadOnlyMemChunk extends ReadOnlyMemChunk {
}
@Override
- public void initChunkMetaFromTvLists() {
+ public void initChunkMetaFromTvLists(Filter globalTimeFilter) {
// init chunk meta
Statistics<? extends Serializable> chunkTimeStatistics =
Statistics.getStatsByType(TSDataType.VECTOR);
@@ -127,23 +130,10 @@ public class AlignedReadOnlyMemChunk extends ReadOnlyMemChunk {
chunkValueStatistics[column] = Statistics.getStatsByType(dataTypes.get(column));
}
- // create MergeSortAlignedTVListIterator
- List<AlignedTVList> alignedTvLists =
- alignedTvListQueryMap.keySet().stream()
- .map(x -> (AlignedTVList) x)
- .collect(Collectors.toList());
-
- timeValuePairIterator =
- MemPointIteratorFactory.create(
- dataTypes,
- columnIndexList,
- alignedTvLists,
- valueColumnsDeletionList,
- floatPrecision,
- encodingList,
- MAX_NUMBER_OF_POINTS_IN_PAGE);
+ nonStreamingTimeValuePairIterator = createMemPointIterator(Ordering.ASC, globalTimeFilter);
+ nonStreamingTimeValuePairIterator.setStreamingQueryMemChunk(false);
- while (timeValuePairIterator.hasNextBatch()) {
+ while (nonStreamingTimeValuePairIterator.hasNextBatch()) {
// create pageTimeStatistics and pageValueStatistics for new page
Statistics<? extends Serializable> pageTimeStatistics =
Statistics.getStatsByType(TSDataType.VECTOR);
@@ -156,7 +146,7 @@ public class AlignedReadOnlyMemChunk extends ReadOnlyMemChunk {
}
valueStatisticsList.add(pageValueStatistics);
- TsBlock tsBlock = timeValuePairIterator.nextBatch();
+ TsBlock tsBlock = nonStreamingTimeValuePairIterator.nextBatch();
// time column
for (int i = 0; i < tsBlock.getPositionCount(); i++) {
pageTimeStatistics.update(tsBlock.getTimeByIndex(i));
@@ -267,6 +257,73 @@ public class AlignedReadOnlyMemChunk extends ReadOnlyMemChunk {
cachedMetaData = alignedChunkMetadata;
}
+ // To avoid loading too much data from disk when the time range is too large during query, we
+ // segment the data according to the time range and construct false statistics.
+ @Override
+ public void initChunkMetaFromTVListsWithFakeStatistics() {
+
+ long chunkStartTime = Long.MAX_VALUE;
+ long chunkEndTime = Long.MIN_VALUE;
+ long rowNum = 0;
+ for (Map.Entry<TVList, Integer> entry : alignedTvListQueryMap.entrySet()) {
+ TVList tvList = entry.getKey();
+ chunkStartTime = Math.min(chunkStartTime, tvList.getMinTime());
+ chunkEndTime = Math.max(chunkEndTime, tvList.getMaxTime());
+ rowNum += entry.getValue();
+ }
+
+ int pageNum =
+ (int)
+ Math.min(
+ MAX_NUMBER_OF_FAKE_PAGE, Math.max(1, rowNum / MAX_NUMBER_OF_POINTS_IN_FAKE_PAGE));
+ long timeInterval = (chunkEndTime - chunkStartTime + 1) / pageNum;
+ for (int i = 0; i < pageNum; i++) {
+ long pageStartTime = chunkStartTime + i * timeInterval;
+ long pageEndTime = (i == pageNum - 1) ? chunkEndTime : (pageStartTime + timeInterval - 1);
+
+ Statistics<? extends Serializable>[] pageValueStatistics = new Statistics[dataTypes.size()];
+ for (int column = 0; column < dataTypes.size(); column++) {
+ pageValueStatistics[column] =
+ generateFakeStatistics(dataTypes.get(column), pageStartTime, pageEndTime);
+ }
+ valueStatisticsList.add(pageValueStatistics);
+ Statistics<? extends Serializable> pageTimeStatistics =
+ generateFakeStatistics(TSDataType.VECTOR, pageStartTime, pageEndTime);
+ timeStatisticsList.add(pageTimeStatistics);
+ }
+
+ Statistics<? extends Serializable>[] chunkValueStatistics = new Statistics[dataTypes.size()];
+ for (int column = 0; column < dataTypes.size(); column++) {
+ chunkValueStatistics[column] =
+ generateFakeStatistics(dataTypes.get(column), chunkStartTime, chunkEndTime);
+ }
+
+ // init chunk meta
+ Statistics<? extends Serializable> chunkTimeStatistics =
+ generateFakeStatistics(TSDataType.VECTOR, chunkStartTime, chunkEndTime);
+ IChunkMetadata timeChunkMetadata =
+ new ChunkMetadata(timeChunkName, TSDataType.VECTOR, 0, chunkTimeStatistics);
+ timeChunkMetadata.setModified(true);
+
+ // value columns
+ List<IChunkMetadata> valueChunkMetadataList = new ArrayList<>();
+ for (int column = 0; column < dataTypes.size(); column++) {
+ IChunkMetadata valueChunkMetadata =
+ new ChunkMetadata(
+ valueChunkNames.get(column), dataTypes.get(column), 0, chunkValueStatistics[column]);
+ valueChunkMetadata.setModified(true);
+ valueChunkMetadataList.add(valueChunkMetadata);
+ }
+
+ IChunkMetadata alignedChunkMetadata =
+ new AlignedChunkMetadata(timeChunkMetadata, valueChunkMetadataList);
+ alignedChunkMetadata.setChunkLoader(new MemAlignedChunkLoader(context, this, true));
+ alignedChunkMetadata.setVersion(Long.MAX_VALUE);
+ // By setting Modified to true, we can prevent these fake statistics from being used.
+ alignedChunkMetadata.setModified(true);
+ cachedMetaData = alignedChunkMetadata;
+ }
+
private int count() {
int count = 0;
for (TVList list : alignedTvListQueryMap.keySet()) {
@@ -313,6 +370,8 @@ public class AlignedReadOnlyMemChunk extends ReadOnlyMemChunk {
dataTypes,
columnIndexList,
alignedTvLists,
+ Ordering.ASC,
+ null,
valueColumnsDeletionList,
floatPrecision,
encodingList,
@@ -387,7 +446,26 @@ public class AlignedReadOnlyMemChunk extends ReadOnlyMemChunk {
return valueStatisticsList;
}
+ @Override
public MemPointIterator getMemPointIterator() {
- return timeValuePairIterator;
+ return nonStreamingTimeValuePairIterator;
+ }
+
+ @Override
+ public MemPointIterator createMemPointIterator(Ordering scanOrder, Filter globalTimeFilter) {
+ List<AlignedTVList> alignedTvLists =
+ alignedTvListQueryMap.keySet().stream()
+ .map(x -> (AlignedTVList) x)
+ .collect(Collectors.toList());
+ return MemPointIteratorFactory.create(
+ dataTypes,
+ columnIndexList,
+ alignedTvLists,
+ scanOrder,
+ globalTimeFilter,
+ valueColumnsDeletionList,
+ floatPrecision,
+ encodingList,
+ MAX_NUMBER_OF_POINTS_IN_PAGE);
}
}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/memtable/ReadOnlyMemChunk.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/memtable/ReadOnlyMemChunk.java
index ed2fee4294f..5ba6f1d5ce9 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/memtable/ReadOnlyMemChunk.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/memtable/ReadOnlyMemChunk.java
@@ -22,6 +22,7 @@ package org.apache.iotdb.db.storageengine.dataregion.memtable;
import org.apache.iotdb.commons.utils.TestOnly;
import org.apache.iotdb.db.exception.query.QueryProcessException;
import org.apache.iotdb.db.queryengine.execution.fragment.QueryContext;
+import org.apache.iotdb.db.queryengine.plan.statement.component.Ordering;
import org.apache.iotdb.db.storageengine.dataregion.read.reader.chunk.MemChunkLoader;
import org.apache.iotdb.db.utils.datastructure.MemPointIterator;
import org.apache.iotdb.db.utils.datastructure.MemPointIteratorFactory;
@@ -38,6 +39,7 @@ import org.apache.tsfile.read.TimeValuePair;
import org.apache.tsfile.read.common.TimeRange;
import org.apache.tsfile.read.common.block.TsBlock;
import org.apache.tsfile.read.common.block.TsBlockBuilder;
+import org.apache.tsfile.read.filter.basic.Filter;
import org.apache.tsfile.read.reader.IPointReader;
import org.apache.tsfile.write.UnSupportedDataTypeException;
import org.slf4j.Logger;
@@ -82,6 +84,10 @@ public class ReadOnlyMemChunk {
protected final int MAX_NUMBER_OF_POINTS_IN_PAGE =
TSFileDescriptor.getInstance().getConfig().getMaxNumberOfPointsInPage();
+ protected final int MAX_NUMBER_OF_POINTS_IN_FAKE_PAGE = 10 * MAX_NUMBER_OF_POINTS_IN_PAGE;
+
+ protected final int MAX_NUMBER_OF_FAKE_PAGE = 100;
+
protected ReadOnlyMemChunk(QueryContext context) {
this.context = context;
}
@@ -133,18 +139,11 @@ public class ReadOnlyMemChunk {
}
}
- public void initChunkMetaFromTvLists() {
+ public void initChunkMetaFromTvLists(Filter globalTimeFilter) {
// create chunk statistics
Statistics<? extends Serializable> chunkStatistics = Statistics.getStatsByType(dataType);
- List<TVList> tvLists = new ArrayList<>(tvListQueryMap.keySet());
- timeValuePairIterator =
- MemPointIteratorFactory.create(
- dataType,
- tvLists,
- deletionList,
- floatPrecision,
- encoding,
- MAX_NUMBER_OF_POINTS_IN_PAGE);
+ timeValuePairIterator = createMemPointIterator(Ordering.ASC, globalTimeFilter);
+ timeValuePairIterator.setStreamingQueryMemChunk(false);
while (timeValuePairIterator.hasNextBatch()) {
// statistics for current batch
Statistics<? extends Serializable> pageStatistics = Statistics.getStatsByType(dataType);
@@ -213,6 +212,48 @@ public class ReadOnlyMemChunk {
cachedMetaData = metaData;
}
+ // To avoid loading too much data from disk when the time range is too large during query, we
+ // segment the data according to the time range and construct false statistics.
+ public void initChunkMetaFromTVListsWithFakeStatistics() {
+ long chunkStartTime = Long.MAX_VALUE;
+ long chunkEndTime = Long.MIN_VALUE;
+ long rowNum = 0;
+ for (Map.Entry<TVList, Integer> entry : tvListQueryMap.entrySet()) {
+ TVList tvList = entry.getKey();
+ chunkStartTime = Math.min(chunkStartTime, tvList.getMinTime());
+ chunkEndTime = Math.max(chunkEndTime, tvList.getMaxTime());
+ rowNum += entry.getValue();
+ }
+ Statistics<? extends Serializable> chunkStatistics =
+ generateFakeStatistics(dataType, chunkStartTime, chunkEndTime);
+ cachedMetaData = new ChunkMetadata(measurementUid, dataType, 0, chunkStatistics);
+
+ int pageNum =
+ (int)
+ Math.min(
+ MAX_NUMBER_OF_FAKE_PAGE, Math.max(1, rowNum / MAX_NUMBER_OF_POINTS_IN_FAKE_PAGE));
+ long timeInterval = (chunkEndTime - chunkStartTime + 1) / pageNum;
+ for (int i = 0; i < pageNum; i++) {
+ long pageStartTime = chunkStartTime + i * timeInterval;
+ long pageEndTime = (i == pageNum - 1) ? chunkEndTime : (pageStartTime + timeInterval - 1);
+ pageStatisticsList.add(generateFakeStatistics(dataType, pageStartTime, pageEndTime));
+ }
+
+ cachedMetaData.setChunkLoader(new MemChunkLoader(context, this, true));
+ cachedMetaData.setVersion(Long.MAX_VALUE);
+ // By setting Modified to true, we can prevent these fake statistics from being used.
+ cachedMetaData.setModified(true);
+ }
+
+ protected Statistics<? extends Serializable> generateFakeStatistics(
+ TSDataType dataType, long startTime, long endTime) {
+ Statistics<? extends Serializable> stats = Statistics.getStatsByType(dataType);
+ stats.setStartTime(startTime);
+ stats.setEndTime(endTime);
+ stats.setCount(1);
+ return stats;
+ }
+
public TSDataType getDataType() {
return dataType;
}
@@ -255,6 +296,8 @@ public class ReadOnlyMemChunk {
MemPointIteratorFactory.create(
getDataType(),
tvLists,
+ Ordering.ASC,
+ null,
deletionList,
floatPrecision,
encoding,
@@ -333,4 +376,17 @@ public class ReadOnlyMemChunk {
public MemPointIterator getMemPointIterator() {
return timeValuePairIterator;
}
+
+ public MemPointIterator createMemPointIterator(Ordering scanOrder, Filter globalTimeFilter) {
+ List<TVList> tvLists = new ArrayList<>(tvListQueryMap.keySet());
+ return MemPointIteratorFactory.create(
+ dataType,
+ tvLists,
+ scanOrder,
+ globalTimeFilter,
+ deletionList,
+ floatPrecision,
+ encoding,
+ MAX_NUMBER_OF_POINTS_IN_PAGE);
+ }
}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/read/reader/chunk/MemAlignedChunkLoader.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/read/reader/chunk/MemAlignedChunkLoader.java
index c9c92bc7398..da01964ae39 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/read/reader/chunk/MemAlignedChunkLoader.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/read/reader/chunk/MemAlignedChunkLoader.java
@@ -20,46 +20,31 @@
package org.apache.iotdb.db.storageengine.dataregion.read.reader.chunk;
import org.apache.iotdb.db.queryengine.execution.fragment.QueryContext;
-import org.apache.iotdb.db.queryengine.metric.SeriesScanCostMetricSet;
import org.apache.iotdb.db.storageengine.dataregion.memtable.AlignedReadOnlyMemChunk;
-import org.apache.tsfile.file.metadata.ChunkMetadata;
import org.apache.tsfile.file.metadata.IChunkMetadata;
-import org.apache.tsfile.read.common.Chunk;
-import org.apache.tsfile.read.controller.IChunkLoader;
import org.apache.tsfile.read.filter.basic.Filter;
import org.apache.tsfile.read.reader.IChunkReader;
import static org.apache.iotdb.db.queryengine.metric.SeriesScanCostMetricSet.INIT_CHUNK_READER_ALIGNED_MEM;
/** To read one aligned chunk from memory, and only used in iotdb server module. */
-public class MemAlignedChunkLoader implements IChunkLoader {
- private final QueryContext context;
- private final AlignedReadOnlyMemChunk chunk;
-
- private static final SeriesScanCostMetricSet SERIES_SCAN_COST_METRIC_SET =
- SeriesScanCostMetricSet.getInstance();
+public class MemAlignedChunkLoader extends MemChunkLoader {
public MemAlignedChunkLoader(QueryContext context, AlignedReadOnlyMemChunk chunk) {
- this.context = context;
- this.chunk = chunk;
+ super(context, chunk);
}
- @Override
- public Chunk loadChunk(ChunkMetadata chunkMetaData) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public void close() {
- // no resources need to close
+ public MemAlignedChunkLoader(
+ QueryContext context, AlignedReadOnlyMemChunk chunk, boolean streamingQueryMemChunk) {
+ super(context, chunk, streamingQueryMemChunk);
}
@Override
public IChunkReader getChunkReader(IChunkMetadata chunkMetaData, Filter globalTimeFilter) {
long startTime = System.nanoTime();
try {
- return new MemAlignedChunkReader(chunk, globalTimeFilter);
+ return new MemAlignedChunkReader((AlignedReadOnlyMemChunk) chunk, globalTimeFilter);
} finally {
long duration = System.nanoTime() - startTime;
context.getQueryStatistics().getConstructAlignedChunkReadersMemCount().getAndAdd(1);
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/read/reader/chunk/MemChunkLoader.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/read/reader/chunk/MemChunkLoader.java
index 7683b38a23f..e441e21b179 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/read/reader/chunk/MemChunkLoader.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/read/reader/chunk/MemChunkLoader.java
@@ -34,15 +34,22 @@ import static org.apache.iotdb.db.queryengine.metric.SeriesScanCostMetricSet.INI
/** To read one chunk from memory, and only used in iotdb server module. */
public class MemChunkLoader implements IChunkLoader {
- private final QueryContext context;
- private final ReadOnlyMemChunk chunk;
+ protected final QueryContext context;
+ protected final ReadOnlyMemChunk chunk;
+ protected final boolean streamingQueryMemChunk;
- private static final SeriesScanCostMetricSet SERIES_SCAN_COST_METRIC_SET =
+ protected static final SeriesScanCostMetricSet SERIES_SCAN_COST_METRIC_SET =
SeriesScanCostMetricSet.getInstance();
public MemChunkLoader(QueryContext context, ReadOnlyMemChunk chunk) {
+ this(context, chunk, false);
+ }
+
+ public MemChunkLoader(
+ QueryContext context, ReadOnlyMemChunk chunk, boolean streamingQueryMemChunk) {
this.context = context;
this.chunk = chunk;
+ this.streamingQueryMemChunk = streamingQueryMemChunk;
}
@Override
@@ -67,4 +74,12 @@ public class MemChunkLoader implements IChunkLoader {
SERIES_SCAN_COST_METRIC_SET.recordSeriesScanCost(INIT_CHUNK_READER_NONALIGNED_MEM, duration);
}
}
+
+ public ReadOnlyMemChunk getReadOnlyMemChunk() {
+ return chunk;
+ }
+
+ public boolean isStreamingQueryMemChunk() {
+ return streamingQueryMemChunk;
+ }
}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/tsfile/TsFileResource.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/tsfile/TsFileResource.java
index c8d3f69aa4d..c43b2265b17 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/tsfile/TsFileResource.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/tsfile/TsFileResource.java
@@ -873,7 +873,8 @@ public class TsFileResource {
*
* @return TimeseriesMetadata or the first ValueTimeseriesMetadata in VectorTimeseriesMetadata
*/
- public ITimeSeriesMetadata getTimeSeriesMetadata(PartialPath seriesPath) throws IOException {
+ public ITimeSeriesMetadata getTimeSeriesMetadata(PartialPath seriesPath, Filter globalTimeFilter)
+ throws IOException {
try {
return pathToTimeSeriesMetadataMap.computeIfAbsent(
seriesPath,
@@ -883,7 +884,8 @@ public class TsFileResource {
return ResourceByPathUtils.getResourceInstance(seriesPath)
.generateTimeSeriesMetadata(
pathToReadOnlyMemChunkMap.get(seriesPath),
- pathToChunkMetadataListMap.get(seriesPath));
+ pathToChunkMetadataListMap.get(seriesPath),
+ globalTimeFilter);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/ModificationUtils.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/ModificationUtils.java
index 8b70bdd6c6a..a9f28e24e0a 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/ModificationUtils.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/ModificationUtils.java
@@ -24,6 +24,7 @@ import org.apache.iotdb.commons.path.AlignedPath;
import org.apache.iotdb.commons.path.MeasurementPath;
import org.apache.iotdb.commons.path.PartialPath;
import org.apache.iotdb.commons.path.PatternTreeMap;
+import org.apache.iotdb.db.queryengine.plan.statement.component.Ordering;
import org.apache.iotdb.db.storageengine.dataregion.compaction.execute.utils.CompactionPathUtils;
import org.apache.iotdb.db.storageengine.dataregion.compaction.selector.impl.SettleSelectorImpl;
import org.apache.iotdb.db.storageengine.dataregion.memtable.IMemTable;
@@ -159,16 +160,33 @@ public class ModificationUtils {
// for the index of the deletionList
public static boolean isPointDeleted(
long timestamp, List<TimeRange> deletionList, int[] deleteCursor) {
+ return isPointDeleted(timestamp, deletionList, deleteCursor, Ordering.ASC);
+ }
+
+ public static boolean isPointDeleted(
+ long timestamp, List<TimeRange> deletionList, int[] deleteCursor, Ordering ordering) {
if (deleteCursor.length != 1) {
throw new IllegalArgumentException("deleteCursor should be an array whose size is 1");
}
- while (deletionList != null && deleteCursor[0] < deletionList.size()) {
- if (deletionList.get(deleteCursor[0]).contains(timestamp)) {
- return true;
- } else if (deletionList.get(deleteCursor[0]).getMax() < timestamp) {
- deleteCursor[0]++;
- } else {
- return false;
+ if (ordering.isAscending()) {
+ while (deletionList != null && deleteCursor[0] < deletionList.size()) {
+ if (deletionList.get(deleteCursor[0]).contains(timestamp)) {
+ return true;
+ } else if (deletionList.get(deleteCursor[0]).getMax() < timestamp) {
+ deleteCursor[0]++;
+ } else {
+ return false;
+ }
+ }
+ } else {
+ while (deletionList != null && !deletionList.isEmpty() && deleteCursor[0] >= 0) {
+ if (deletionList.get(deleteCursor[0]).contains(timestamp)) {
+ return true;
+ } else if (deletionList.get(deleteCursor[0]).getMin() >= timestamp) {
+ deleteCursor[0]--;
+ } else {
+ return false;
+ }
}
}
return false;
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/AlignedTVList.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/AlignedTVList.java
index 4b616967621..2b643a52128 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/AlignedTVList.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/AlignedTVList.java
@@ -19,11 +19,13 @@
package org.apache.iotdb.db.utils.datastructure;
+import org.apache.iotdb.db.queryengine.plan.statement.component.Ordering;
import org.apache.iotdb.db.storageengine.dataregion.wal.buffer.IWALByteBufferView;
import org.apache.iotdb.db.storageengine.dataregion.wal.utils.WALWriteUtils;
import org.apache.iotdb.db.storageengine.rescon.memory.PrimitiveArrayManager;
import org.apache.iotdb.db.utils.MathUtils;
+import org.apache.tsfile.block.column.Column;
import org.apache.tsfile.block.column.ColumnBuilder;
import org.apache.tsfile.enums.TSDataType;
import org.apache.tsfile.file.metadata.enums.TSEncoding;
@@ -31,7 +33,9 @@ import org.apache.tsfile.read.TimeValuePair;
import org.apache.tsfile.read.common.TimeRange;
import org.apache.tsfile.read.common.block.TsBlock;
import org.apache.tsfile.read.common.block.TsBlockBuilder;
+import org.apache.tsfile.read.common.block.TsBlockUtil;
import org.apache.tsfile.read.common.block.column.TimeColumnBuilder;
+import org.apache.tsfile.read.filter.basic.Filter;
import org.apache.tsfile.utils.Binary;
import org.apache.tsfile.utils.BitMap;
import org.apache.tsfile.utils.Pair;
@@ -1329,6 +1333,8 @@ public abstract class AlignedTVList extends TVList {
}
public AlignedTVListIterator iterator(
+ Ordering scanOrder,
+ Filter globalTimeFilter,
List<TSDataType> dataTypeList,
List<Integer> columnIndexList,
List<List<TimeRange>> valueColumnsDeletionList,
@@ -1336,6 +1342,8 @@ public abstract class AlignedTVList extends TVList {
List<TSEncoding> encodingList,
int maxNumberOfPointsInPage) {
return new AlignedTVListIterator(
+ scanOrder,
+ globalTimeFilter,
dataTypeList,
columnIndexList,
valueColumnsDeletionList,
@@ -1345,7 +1353,7 @@ public abstract class AlignedTVList extends TVList {
}
/* AlignedTVList Iterator */
- public class AlignedTVListIterator extends TVListIterator implements MemPointIterator {
+ public class AlignedTVListIterator extends TVListIterator {
private final BitMap allValueColDeletedMap;
private final List<TSDataType> dataTypeList;
private final List<Integer> columnIndexList;
@@ -1360,13 +1368,15 @@ public abstract class AlignedTVList extends TVList {
private final List<int[]> valueColumnDeleteCursor = new ArrayList<>();
public AlignedTVListIterator(
+ Ordering scanOrder,
+ Filter globalTimeFilter,
List<TSDataType> dataTypeList,
List<Integer> columnIndexList,
List<List<TimeRange>> valueColumnsDeletionList,
Integer floatPrecision,
List<TSEncoding> encodingList,
int maxNumberOfPointsInPage) {
- super(null, null, null, maxNumberOfPointsInPage);
+ super(scanOrder, globalTimeFilter, null, null, null, maxNumberOfPointsInPage);
this.dataTypeList = dataTypeList;
this.columnIndexList =
(columnIndexList == null)
@@ -1378,7 +1388,13 @@ public abstract class AlignedTVList extends TVList {
this.encodingList = encodingList;
this.selectedIndices = new int[dataTypeList.size()];
for (int i = 0; i < dataTypeList.size(); i++) {
- valueColumnDeleteCursor.add(new int[] {0});
+ List<TimeRange> valueColumnDeletions =
+ valueColumnsDeletionList == null ? null : valueColumnsDeletionList.get(i);
+ int cursor =
+ (valueColumnDeletions == null || scanOrder.isAscending())
+ ? 0
+ : (valueColumnDeletions.size() - 1);
+ valueColumnDeleteCursor.add(new int[] {cursor});
}
}
@@ -1388,8 +1404,14 @@ public abstract class AlignedTVList extends TVList {
findValidRow = false;
while (index < rows && !findValidRow) {
// all columns values are deleted
+ int convertedScanOrderValueIndex = getValueIndex(getScanOrderIndex(index));
if ((allValueColDeletedMap != null
- && allValueColDeletedMap.isMarked(getValueIndex(index)))) {
+ && allValueColDeletedMap.isMarked(convertedScanOrderValueIndex))) {
+ index++;
+ continue;
+ }
+ long time = getTime(getScanOrderIndex(index));
+ if (!isTimeSatisfied(time)) {
index++;
continue;
}
@@ -1399,16 +1421,32 @@ public abstract class AlignedTVList extends TVList {
probeNext = true;
return;
}
- Arrays.fill(selectedIndices, index);
+
+ // When traversing in ASC order, we only need to overwrite the previous non-null value
+ // with the non-null value encountered later.
+ // When traversing in DESC order, we need to keep the non-null value encountered first,
+ // and only overwrite it if the previous value is null and current value is non-null.
+ for (int i = 0; i < selectedIndices.length; i++) {
+ // In order to identify the previous null, we use index -1 here to represent.
+ // The -1 here is also used for checking all null rows
+ selectedIndices[i] = isNullValue(index, i) ? -1 : index;
+ }
findValidRow = true;
// handle duplicated timestamp
- while (index + 1 < rows && getTime(index + 1) == getTime(index)) {
+ // We can use the selectedIndices structure to handle the value coverage of ASC or DESC
+ // traversal
+ while (index + 1 < rows
+ && getTime(getScanOrderIndex(index + 1)) == getTime(getScanOrderIndex(index))) {
index++;
// skip all-Null rows if allValueColDeletedMap exists
if (allValueColDeletedMap == null
- || !allValueColDeletedMap.isMarked(getValueIndex(index))) {
+ || !allValueColDeletedMap.isMarked(getValueIndex(getScanOrderIndex(index)))) {
for (int columnIndex = 0; columnIndex < dataTypeList.size(); columnIndex++) {
+ if (!scanOrder.isAscending() && selectedIndices[columnIndex] != -1) {
+ // non -1 value means it already set the latest point index
+ continue;
+ }
// update selected index if the column is not null
if (!isNullValue(index, columnIndex)) {
selectedIndices[columnIndex] = index;
@@ -1418,29 +1456,40 @@ public abstract class AlignedTVList extends TVList {
}
// valueColumnsDeletionList is set when AlignedTVList iterator is created by
- // MemPointIterator.single method. Otherwise, all-null rows is checked by
+ // MemPointIterator.single method. Otherwise, it is checked by
// MergeSortMultiAlignedTVListIterator or OrderedMultiAlignedTVListIterator.
- if (valueColumnsDeletionList != null) {
- BitMap bitMap = new BitMap(dataTypeList.size());
- long time = getTime(index);
- for (int columnIndex = 0; columnIndex < dataTypeList.size(); columnIndex++) {
- if (isNullValue(index, columnIndex)
- || isPointDeleted(
- time,
- valueColumnsDeletionList.get(columnIndex),
- valueColumnDeleteCursor.get(columnIndex))) {
- bitMap.mark(columnIndex);
- }
+ BitMap bitMap = null;
+ time = getTime(getScanOrderIndex(index));
+ for (int columnIndex = 0; columnIndex < dataTypeList.size(); columnIndex++) {
+ if (selectedIndices[columnIndex] == -1
+ || (valueColumnsDeletionList != null
+ && isPointDeleted(
+ time,
+ valueColumnsDeletionList.get(columnIndex),
+ valueColumnDeleteCursor.get(columnIndex),
+ scanOrder))) {
+ bitMap = bitMap == null ? new BitMap(dataTypeList.size()) : bitMap;
+ bitMap.mark(columnIndex);
}
- if (bitMap.isAllMarked()) {
- findValidRow = false;
- index++;
+ }
+ if (bitMap != null && bitMap.isAllMarked()) {
+ findValidRow = false;
+ index++;
+ continue;
+ }
+ // We previously set some -1. If these values are still -1 in the end,
+ // it means that each index is invalid. At this time, we can use any one at random.
+ for (int i = 0; i < selectedIndices.length; i++) {
+ if (selectedIndices[i] == -1) {
+ selectedIndices[i] = index;
}
}
}
probeNext = true;
}
+ // When used as a point reader, we should not apply a pagination controller or push down filter
+ // because it has not yet been merged with other data.
@Override
public TimeValuePair nextTimeValuePair() {
if (!hasNextTimeValuePair()) {
@@ -1451,7 +1500,9 @@ public abstract class AlignedTVList extends TVList {
vector[columnIndex] = getPrimitiveTypeObject(selectedIndices[columnIndex], columnIndex);
}
TimeValuePair tvPair =
- new TimeValuePair(getTime(index), TsPrimitiveType.getByType(TSDataType.VECTOR, vector));
+ new TimeValuePair(
+ getTime(getScanOrderIndex(index)),
+ TsPrimitiveType.getByType(TSDataType.VECTOR, vector));
next();
return tvPair;
@@ -1467,10 +1518,11 @@ public abstract class AlignedTVList extends TVList {
vector[columnIndex] = getPrimitiveTypeObject(selectedIndices[columnIndex], columnIndex);
}
return new TimeValuePair(
- getTime(index), TsPrimitiveType.getByType(TSDataType.VECTOR, vector));
+ getTime(getScanOrderIndex(index)), TsPrimitiveType.getByType(TSDataType.VECTOR, vector));
}
public TsPrimitiveType getPrimitiveTypeObject(int rowIndex, int columnIndex) {
+ rowIndex = getScanOrderIndex(rowIndex);
int valueIndex = getValueIndex(rowIndex);
if (valueIndex < 0 || valueIndex >= rows) {
return null;
@@ -1521,18 +1573,21 @@ public abstract class AlignedTVList extends TVList {
@Override
public boolean hasNextBatch() {
+ if (!paginationController.hasCurLimit()) {
+ return false;
+ }
if (!probeNext) {
prepareNext();
}
if (findValidRow && selectedIndices.length > 0) {
index = Arrays.stream(selectedIndices).min().getAsInt();
}
- return index < rows;
+ return index < rows && !isCurrentTimeExceedTimeRange(getTime(getScanOrderIndex(index)));
}
@Override
public TsBlock nextBatch() {
- TsBlockBuilder builder = new TsBlockBuilder(dataTypeList);
+ TsBlockBuilder builder = new TsBlockBuilder(maxNumberOfPointsInPage, dataTypeList);
// Time column
TimeColumnBuilder timeBuilder = builder.getTimeColumnBuilder();
@@ -1543,33 +1598,44 @@ public abstract class AlignedTVList extends TVList {
int startIndex = index;
// time column
for (; index < rows; index++) {
- if (validRowCount >= maxNumberOfPointsInPage) {
+ long time = getTime(getScanOrderIndex(index));
+ if (validRowCount >= maxNumberOfPointsInPage || isCurrentTimeExceedTimeRange(time)) {
break;
}
// skip empty row
- if (allValueColDeletedMap != null && allValueColDeletedMap.isMarked(getValueIndex(index))) {
+ if (allValueColDeletedMap != null
+ && allValueColDeletedMap.isMarked(getValueIndex(getScanOrderIndex(index)))) {
+ continue;
+ }
+ if (!isTimeSatisfied(time)) {
continue;
}
int nextRowIndex = index + 1;
while (nextRowIndex < rows
- && allValueColDeletedMap != null
- && allValueColDeletedMap.isMarked(getValueIndex(nextRowIndex))) {
+ && ((allValueColDeletedMap != null
+ && allValueColDeletedMap.isMarked(
+ getValueIndex(getScanOrderIndex(nextRowIndex))))
+ || !isTimeSatisfied(time))) {
nextRowIndex++;
}
- long time = getTime(index);
- if (nextRowIndex == rows || time != getTime(nextRowIndex)) {
+ if ((nextRowIndex == rows || time != getTime(getScanOrderIndex(nextRowIndex)))) {
timeBuilder.writeLong(time);
validRowCount++;
} else {
if (Objects.isNull(timeDuplicateInfo)) {
timeDuplicateInfo = new BitMap(rows);
}
+ // For this timeInvalidInfo, we mark all positions that are not the last one in the
+ // ASC traversal. It has the same behaviour for the DESC traversal, because our ultimate
+ // goal is to process all the data with the same timestamp before writing it into TsBlock.
timeDuplicateInfo.mark(index);
}
index = nextRowIndex - 1;
}
+ boolean[] hasAnyNonNullValue = new boolean[validRowCount];
int columnCount = dataTypeList.size();
+ int currentWriteRowIndex;
// value columns
for (int columnIndex = 0; columnIndex < columnCount; columnIndex++) {
int validColumnIndex = columnIndexList.get(columnIndex);
@@ -1581,18 +1647,35 @@ public abstract class AlignedTVList extends TVList {
lastValidPointIndexForTimeDupCheck = new Pair<>(Long.MIN_VALUE, null);
}
ColumnBuilder valueBuilder = builder.getColumnBuilder(columnIndex);
+ currentWriteRowIndex = 0;
for (int sortedRowIndex = startIndex; sortedRowIndex < index; sortedRowIndex++) {
// skip empty row
- if (allValueColDeletedMap != null
- && allValueColDeletedMap.isMarked(getValueIndex(sortedRowIndex))) {
+ if ((allValueColDeletedMap != null
+ && allValueColDeletedMap.isMarked(
+ getValueIndex(getScanOrderIndex(sortedRowIndex))))
+ || !isTimeSatisfied(getTime(getScanOrderIndex(sortedRowIndex)))) {
continue;
}
// skip time duplicated or totally deleted rows
if (Objects.nonNull(timeDuplicateInfo)) {
- if (!outer.isNullValue(getValueIndex(sortedRowIndex), validColumnIndex)) {
- lastValidPointIndexForTimeDupCheck.left = getTime(sortedRowIndex);
- lastValidPointIndexForTimeDupCheck.right = getValueIndex(sortedRowIndex);
+ if (!outer.isNullValue(
+ getValueIndex(getScanOrderIndex(sortedRowIndex)), validColumnIndex)) {
+ lastValidPointIndexForTimeDupCheck.left = getTime(getScanOrderIndex(sortedRowIndex));
+ if (scanOrder.isAscending()) {
+ lastValidPointIndexForTimeDupCheck.right =
+ getValueIndex(getScanOrderIndex(sortedRowIndex));
+ } else if (lastValidPointIndexForTimeDupCheck.right == null) {
+ // For DESC traversal, we need to keep the first non-null value encountered
+ // We can use lastValidPointIndexForTimeDupCheck.right as a judgment method to see
+ // if it is null
+ lastValidPointIndexForTimeDupCheck.right =
+ getValueIndex(getScanOrderIndex(sortedRowIndex));
+ }
}
+ // timeInvalidInfo was constructed when traversing the time column before. It can be
+ // reused when traversing each value column to skip deleted rows or non-last rows with
+ // duplicated timestamps.
+ // Until the last duplicate timestamp is encountered, it will be skipped here.
if (timeDuplicateInfo.isMarked(sortedRowIndex)) {
continue;
}
@@ -1601,6 +1684,7 @@ public abstract class AlignedTVList extends TVList {
// append null value when query column does not exist in current aligned TVList
if (validColumnIndex < 0 || validColumnIndex >= dataTypes.size()) {
valueBuilder.appendNull();
+ currentWriteRowIndex++;
continue;
}
@@ -1614,69 +1698,137 @@ public abstract class AlignedTVList extends TVList {
// write(T:3,V:null)
int originRowIndex;
if (Objects.nonNull(lastValidPointIndexForTimeDupCheck)
- && (getTime(sortedRowIndex) == lastValidPointIndexForTimeDupCheck.left)) {
+ && (getTime(getScanOrderIndex(sortedRowIndex))
+ == lastValidPointIndexForTimeDupCheck.left)
+ && Objects.nonNull(lastValidPointIndexForTimeDupCheck.right)) {
originRowIndex = lastValidPointIndexForTimeDupCheck.right;
+ // For DESC traversal, the judgment of whether the previous point is null depends on
+ // lastValidPointIndexForTimeDupCheck.right, so we need to remember to clean it up
+ // after writing a point
+ lastValidPointIndexForTimeDupCheck.right = null;
} else {
- originRowIndex = getValueIndex(sortedRowIndex);
+ originRowIndex = getValueIndex(getScanOrderIndex(sortedRowIndex));
}
if (outer.isNullValue(originRowIndex, validColumnIndex)
|| isPointDeleted(
- getTime(sortedRowIndex),
+ getTime(getScanOrderIndex(sortedRowIndex)),
Objects.isNull(valueColumnsDeletionList)
? null
: valueColumnsDeletionList.get(columnIndex),
- deleteCursor)) {
+ deleteCursor,
+ scanOrder)) {
valueBuilder.appendNull();
+ currentWriteRowIndex++;
continue;
}
- switch (dataTypes.get(validColumnIndex)) {
- case BOOLEAN:
- valueBuilder.writeBoolean(getBooleanByValueIndex(originRowIndex, validColumnIndex));
- break;
- case INT32:
- case DATE:
- valueBuilder.writeInt(getIntByValueIndex(originRowIndex, validColumnIndex));
- break;
- case INT64:
- case TIMESTAMP:
- valueBuilder.writeLong(getLongByValueIndex(originRowIndex, validColumnIndex));
- break;
- case FLOAT:
- float valueF = getFloatByValueIndex(originRowIndex, validColumnIndex);
- if (encodingList != null) {
- valueF =
- roundValueWithGivenPrecision(
- valueF, floatPrecision, encodingList.get(columnIndex));
- }
- valueBuilder.writeFloat(valueF);
- break;
- case DOUBLE:
- double valueD = getDoubleByValueIndex(originRowIndex, validColumnIndex);
- if (encodingList != null) {
- valueD =
- roundValueWithGivenPrecision(
- valueD, floatPrecision, encodingList.get(columnIndex));
- }
- valueBuilder.writeDouble(valueD);
- break;
- case TEXT:
- case BLOB:
- case STRING:
- valueBuilder.writeBinary(getBinaryByValueIndex(originRowIndex, validColumnIndex));
- break;
- default:
- break;
- }
+ hasAnyNonNullValue[currentWriteRowIndex++] = true;
+ writeToColumn(validColumnIndex, valueBuilder, originRowIndex, columnIndex);
}
}
builder.declarePositions(validRowCount);
TsBlock tsBlock = builder.build();
- tsBlocks.add(tsBlock);
+ if (needRebuildTsBlock(hasAnyNonNullValue)) {
+ // if exist all null rows, at most have validRowCount - 1 valid rows
+ tsBlock = reBuildTsBlock(hasAnyNonNullValue, validRowCount, dataTypeList, tsBlock);
+ }
+ if (pushDownFilter != null) {
+ tsBlock =
+ TsBlockUtil.applyFilterAndLimitOffsetToTsBlock(
+ tsBlock,
+ new TsBlockBuilder(
+ Math.min(maxNumberOfPointsInPage, tsBlock.getPositionCount()), dataTypeList),
+ pushDownFilter,
+ paginationController);
+ } else {
+ tsBlock = paginationController.applyTsBlock(tsBlock);
+ }
+ addTsBlock(tsBlock);
probeNext = false;
return tsBlock;
}
+ private void writeToColumn(
+ int validColumnIndex, ColumnBuilder valueBuilder, int originRowIndex, int columnIndex) {
+ switch (dataTypes.get(validColumnIndex)) {
+ case BOOLEAN:
+ valueBuilder.writeBoolean(getBooleanByValueIndex(originRowIndex, validColumnIndex));
+ break;
+ case INT32:
+ case DATE:
+ valueBuilder.writeInt(getIntByValueIndex(originRowIndex, validColumnIndex));
+ break;
+ case INT64:
+ case TIMESTAMP:
+ valueBuilder.writeLong(getLongByValueIndex(originRowIndex, validColumnIndex));
+ break;
+ case FLOAT:
+ float valueF = getFloatByValueIndex(originRowIndex, validColumnIndex);
+ if (encodingList != null) {
+ valueF =
+ roundValueWithGivenPrecision(valueF, floatPrecision, encodingList.get(columnIndex));
+ }
+ valueBuilder.writeFloat(valueF);
+ break;
+ case DOUBLE:
+ double valueD = getDoubleByValueIndex(originRowIndex, validColumnIndex);
+ if (encodingList != null) {
+ valueD =
+ roundValueWithGivenPrecision(valueD, floatPrecision, encodingList.get(columnIndex));
+ }
+ valueBuilder.writeDouble(valueD);
+ break;
+ case TEXT:
+ case BLOB:
+ case STRING:
+ valueBuilder.writeBinary(getBinaryByValueIndex(originRowIndex, validColumnIndex));
+ break;
+ default:
+ break;
+ }
+ }
+
+ private TsBlock reBuildTsBlock(
+ boolean[] hasAnyNonNullValue,
+ int previousValidRowCount,
+ List<TSDataType> tsDataTypeList,
+ TsBlock previousTsBlock) {
+ TsBlockBuilder builder = new TsBlockBuilder(previousValidRowCount - 1, tsDataTypeList);
+ TimeColumnBuilder timeColumnBuilder = builder.getTimeColumnBuilder();
+ Column timeColumn = previousTsBlock.getTimeColumn();
+ for (int i = 0; i < previousValidRowCount; i++) {
+ if (hasAnyNonNullValue[i]) {
+ timeColumnBuilder.writeLong(timeColumn.getLong(i));
+ builder.declarePosition();
+ }
+ }
+
+ for (int columnIndex = 0; columnIndex < tsDataTypeList.size(); columnIndex++) {
+ ColumnBuilder columnBuilder = builder.getColumnBuilder(columnIndex);
+ Column column = previousTsBlock.getColumn(columnIndex);
+ for (int i = 0; i < previousValidRowCount; i++) {
+ if (hasAnyNonNullValue[i]) {
+ if (column.isNull(i)) {
+ columnBuilder.appendNull();
+ } else {
+ columnBuilder.write(column, i);
+ }
+ }
+ }
+ }
+ return builder.build();
+ }
+
+ // existing any all null row should rebuild the tsblock
+ private boolean needRebuildTsBlock(boolean[] hasAnyNonNullValue) {
+ for (boolean b : hasAnyNonNullValue) {
+ if (!b) {
+ return true;
+ }
+ }
+ return false;
+ }
+
@Override
public void encodeBatch(IChunkWriter chunkWriter, BatchEncodeInfo encodeInfo, long[] times) {
AlignedChunkWriterImpl alignedChunkWriter = (AlignedChunkWriterImpl) chunkWriter;
@@ -1826,7 +1978,7 @@ public abstract class AlignedTVList extends TVList {
*/
public boolean isNullValue(int rowIndex, int columnIndex) {
// valueIndex is converted index of values
- int valueIndex = getValueIndex(rowIndex);
+ int valueIndex = getValueIndex(getScanOrderIndex(rowIndex));
// validColumnIndex is converted index of columns in the Aligned TVList.
int validColumnIndex = columnIndexList.get(columnIndex);
if (validColumnIndex < 0 || validColumnIndex >= dataTypes.size()) {
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/MemPointIterator.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/MemPointIterator.java
index 66fc547db20..1cce0ff0b4d 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/MemPointIterator.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/MemPointIterator.java
@@ -19,16 +19,79 @@
package org.apache.iotdb.db.utils.datastructure;
+import org.apache.iotdb.db.queryengine.plan.statement.component.Ordering;
+
+import org.apache.tsfile.read.common.TimeRange;
import org.apache.tsfile.read.common.block.TsBlock;
+import org.apache.tsfile.read.filter.basic.Filter;
import org.apache.tsfile.read.reader.IPointReader;
+import org.apache.tsfile.read.reader.series.PaginationController;
import org.apache.tsfile.write.chunk.IChunkWriter;
-public interface MemPointIterator extends IPointReader {
- TsBlock getBatch(int tsBlockIndex);
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+public abstract class MemPointIterator implements IPointReader {
+
+ protected final Ordering scanOrder;
+ // Only used when returning by batch
+ protected Filter pushDownFilter;
+ // Only used when returning by batch
+ protected PaginationController paginationController =
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER;
+ protected TimeRange timeRange;
+ protected List<TsBlock> tsBlocks;
+ protected boolean streamingQueryMemChunk = true;
+
+ public MemPointIterator(Ordering scanOrder) {
+ this.scanOrder = scanOrder;
+ }
+
+ public abstract TsBlock getBatch(int tsBlockIndex);
+
+ // When returned by nextBatch, the pagination controller and push down filter are applied. This
+ // can only be used when there is no overlap with other pages.
+ public abstract boolean hasNextBatch();
+
+ public abstract TsBlock nextBatch();
+
+ public abstract void encodeBatch(
+ IChunkWriter chunkWriter, BatchEncodeInfo encodeInfo, long[] times);
+
+ public void setPushDownFilter(Filter pushDownFilter) {
+ this.pushDownFilter = pushDownFilter;
+ }
+
+ public void setLimitAndOffset(PaginationController paginationController) {
+ this.paginationController = paginationController;
+ }
+
+ public void setCurrentPageTimeRange(TimeRange timeRange) {
+ this.timeRange = timeRange;
+ }
+
+ protected boolean isCurrentTimeExceedTimeRange(long time) {
+ return timeRange != null
+ && (scanOrder.isAscending() ? (time > timeRange.getMax()) : (time < timeRange.getMin()));
+ }
- boolean hasNextBatch();
+ public void setStreamingQueryMemChunk(boolean streamingQueryMemChunk) {
+ this.streamingQueryMemChunk = streamingQueryMemChunk;
+ }
- TsBlock nextBatch();
+ protected void addTsBlock(TsBlock tsBlock) {
+ if (streamingQueryMemChunk) {
+ return;
+ }
+ tsBlocks = tsBlocks == null ? new ArrayList<>() : tsBlocks;
+ tsBlocks.add(tsBlock);
+ }
- void encodeBatch(IChunkWriter chunkWriter, BatchEncodeInfo encodeInfo, long[] times);
+ @Override
+ public void close() throws IOException {
+ if (tsBlocks != null) {
+ tsBlocks.clear();
+ }
+ }
}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/MemPointIteratorFactory.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/MemPointIteratorFactory.java
index b622cc0295e..4d549afb2fd 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/MemPointIteratorFactory.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/MemPointIteratorFactory.java
@@ -19,9 +19,12 @@
package org.apache.iotdb.db.utils.datastructure;
+import org.apache.iotdb.db.queryengine.plan.statement.component.Ordering;
+
import org.apache.tsfile.enums.TSDataType;
import org.apache.tsfile.file.metadata.enums.TSEncoding;
import org.apache.tsfile.read.common.TimeRange;
+import org.apache.tsfile.read.filter.basic.Filter;
import java.util.List;
@@ -32,28 +35,40 @@ public class MemPointIteratorFactory {
// TVListIterator
private static MemPointIterator single(List<TVList> tvLists, int maxNumberOfPointsInPage) {
- return tvLists.get(0).iterator(null, null, null, maxNumberOfPointsInPage);
+ return tvLists.get(0).iterator(Ordering.ASC, null, null, null, null, maxNumberOfPointsInPage);
}
private static MemPointIterator single(
List<TVList> tvLists, List<TimeRange> deletionList, int maxNumberOfPointsInPage) {
- return tvLists.get(0).iterator(deletionList, null, null, maxNumberOfPointsInPage);
+ return tvLists
+ .get(0)
+ .iterator(Ordering.ASC, null, deletionList, null, null, maxNumberOfPointsInPage);
}
private static MemPointIterator single(
List<TVList> tvLists,
+ Ordering scanOrder,
+ Filter globalTimeFilter,
List<TimeRange> deletionList,
Integer floatPrecision,
TSEncoding encoding,
int maxNumberOfPointsInPage) {
- return tvLists.get(0).iterator(deletionList, floatPrecision, encoding, maxNumberOfPointsInPage);
+ return tvLists
+ .get(0)
+ .iterator(
+ scanOrder,
+ globalTimeFilter,
+ deletionList,
+ floatPrecision,
+ encoding,
+ maxNumberOfPointsInPage);
}
// MergeSortMultiTVListIterator
private static MemPointIterator mergeSort(
TSDataType tsDataType, List<TVList> tvLists, int maxNumberOfPointsInPage) {
return new MergeSortMultiTVListIterator(
- tsDataType, tvLists, null, null, null, maxNumberOfPointsInPage);
+ Ordering.ASC, null, tsDataType, tvLists, null, null, null, maxNumberOfPointsInPage);
}
private static MemPointIterator mergeSort(
@@ -62,25 +77,34 @@ public class MemPointIteratorFactory {
List<TimeRange> deletionList,
int maxNumberOfPointsInPage) {
return new MergeSortMultiTVListIterator(
- tsDataType, tvLists, deletionList, null, null, maxNumberOfPointsInPage);
+ Ordering.ASC, null, tsDataType, tvLists, deletionList, null, null, maxNumberOfPointsInPage);
}
private static MemPointIterator mergeSort(
TSDataType tsDataType,
List<TVList> tvLists,
+ Ordering scanOrder,
+ Filter globalTimeFilter,
List<TimeRange> deletionList,
Integer floatPrecision,
TSEncoding encoding,
int maxNumberOfPointsInPage) {
return new MergeSortMultiTVListIterator(
- tsDataType, tvLists, deletionList, floatPrecision, encoding, maxNumberOfPointsInPage);
+ scanOrder,
+ globalTimeFilter,
+ tsDataType,
+ tvLists,
+ deletionList,
+ floatPrecision,
+ encoding,
+ maxNumberOfPointsInPage);
}
// OrderedMultiTVListIterator
private static MemPointIterator ordered(
TSDataType tsDataType, List<TVList> tvLists, int maxNumberOfPointsInPage) {
return new OrderedMultiTVListIterator(
- tsDataType, tvLists, null, null, null, maxNumberOfPointsInPage);
+ Ordering.ASC, null, tsDataType, tvLists, null, null, null, maxNumberOfPointsInPage);
}
private static MemPointIterator ordered(
@@ -89,18 +113,27 @@ public class MemPointIteratorFactory {
List<TimeRange> deletionList,
int maxNumberOfPointsInPage) {
return new OrderedMultiTVListIterator(
- tsDataType, tvLists, deletionList, null, null, maxNumberOfPointsInPage);
+ Ordering.ASC, null, tsDataType, tvLists, deletionList, null, null, maxNumberOfPointsInPage);
}
private static MemPointIterator ordered(
TSDataType tsDataType,
List<TVList> tvLists,
+ Ordering scanOrder,
+ Filter globalTimeFilter,
List<TimeRange> deletionList,
Integer floatPrecision,
TSEncoding encoding,
int maxNumberOfPointsInPage) {
return new OrderedMultiTVListIterator(
- tsDataType, tvLists, deletionList, floatPrecision, encoding, maxNumberOfPointsInPage);
+ scanOrder,
+ globalTimeFilter,
+ tsDataType,
+ tvLists,
+ deletionList,
+ floatPrecision,
+ encoding,
+ maxNumberOfPointsInPage);
}
// AlignedTVListIterator
@@ -111,7 +144,15 @@ public class MemPointIteratorFactory {
int maxNumberOfPointsInPage) {
return alignedTvLists
.get(0)
- .iterator(tsDataTypes, columnIndexList, null, null, null, maxNumberOfPointsInPage);
+ .iterator(
+ Ordering.ASC,
+ null,
+ tsDataTypes,
+ columnIndexList,
+ null,
+ null,
+ null,
+ maxNumberOfPointsInPage);
}
private static MemPointIterator single(
@@ -123,6 +164,8 @@ public class MemPointIteratorFactory {
return alignedTvLists
.get(0)
.iterator(
+ Ordering.ASC,
+ null,
tsDataTypes,
columnIndexList,
valueColumnsDeletionList,
@@ -135,6 +178,8 @@ public class MemPointIteratorFactory {
List<TSDataType> tsDataTypes,
List<Integer> columnIndexList,
List<AlignedTVList> alignedTvLists,
+ Ordering scanOrder,
+ Filter globalTimeFilter,
List<List<TimeRange>> valueColumnsDeletionList,
Integer floatPrecision,
List<TSEncoding> encodingList,
@@ -142,6 +187,8 @@ public class MemPointIteratorFactory {
return alignedTvLists
.get(0)
.iterator(
+ scanOrder,
+ globalTimeFilter,
tsDataTypes,
columnIndexList,
valueColumnsDeletionList,
@@ -157,7 +204,15 @@ public class MemPointIteratorFactory {
List<AlignedTVList> alignedTvLists,
int maxNumberOfPointsInPage) {
return new MergeSortMultiAlignedTVListIterator(
- tsDataTypes, columnIndexList, alignedTvLists, null, null, null, maxNumberOfPointsInPage);
+ tsDataTypes,
+ columnIndexList,
+ alignedTvLists,
+ Ordering.ASC,
+ null,
+ null,
+ null,
+ null,
+ maxNumberOfPointsInPage);
}
private static MemPointIterator mergeSort(
@@ -170,6 +225,8 @@ public class MemPointIteratorFactory {
tsDataTypes,
columnIndexList,
alignedTvLists,
+ Ordering.ASC,
+ null,
valueColumnsDeletionList,
null,
null,
@@ -180,6 +237,8 @@ public class MemPointIteratorFactory {
List<TSDataType> tsDataTypes,
List<Integer> columnIndexList,
List<AlignedTVList> alignedTvLists,
+ Ordering scanOrder,
+ Filter globalTimeFilter,
List<List<TimeRange>> valueColumnsDeletionList,
Integer floatPrecision,
List<TSEncoding> encodingList,
@@ -188,6 +247,8 @@ public class MemPointIteratorFactory {
tsDataTypes,
columnIndexList,
alignedTvLists,
+ scanOrder,
+ globalTimeFilter,
valueColumnsDeletionList,
floatPrecision,
encodingList,
@@ -201,7 +262,15 @@ public class MemPointIteratorFactory {
List<AlignedTVList> alignedTvLists,
int maxNumberOfPointsInPage) {
return new OrderedMultiAlignedTVListIterator(
- tsDataTypes, columnIndexList, alignedTvLists, null, null, null, maxNumberOfPointsInPage);
+ tsDataTypes,
+ columnIndexList,
+ alignedTvLists,
+ Ordering.ASC,
+ null,
+ null,
+ null,
+ null,
+ maxNumberOfPointsInPage);
}
private static MemPointIterator ordered(
@@ -214,6 +283,8 @@ public class MemPointIteratorFactory {
tsDataTypes,
columnIndexList,
alignedTvLists,
+ Ordering.ASC,
+ null,
valueColumnsDeletionList,
null,
null,
@@ -224,6 +295,8 @@ public class MemPointIteratorFactory {
List<TSDataType> tsDataTypes,
List<Integer> columnIndexList,
List<AlignedTVList> alignedTvLists,
+ Ordering scanOrder,
+ Filter globalTimeFilter,
List<List<TimeRange>> valueColumnsDeletionList,
Integer floatPrecision,
List<TSEncoding> encodingList,
@@ -232,6 +305,8 @@ public class MemPointIteratorFactory {
tsDataTypes,
columnIndexList,
alignedTvLists,
+ scanOrder,
+ globalTimeFilter,
valueColumnsDeletionList,
floatPrecision,
encodingList,
@@ -266,18 +341,41 @@ public class MemPointIteratorFactory {
public static MemPointIterator create(
TSDataType tsDataType,
List<TVList> tvLists,
+ Ordering scanOrder,
+ Filter globalTimeFilter,
List<TimeRange> deletionList,
Integer floatPrecision,
TSEncoding encoding,
int maxNumberOfPointsInPage) {
if (tvLists.size() == 1) {
- return single(tvLists, deletionList, floatPrecision, encoding, maxNumberOfPointsInPage);
+ return single(
+ tvLists,
+ scanOrder,
+ globalTimeFilter,
+ deletionList,
+ floatPrecision,
+ encoding,
+ maxNumberOfPointsInPage);
} else if (isCompleteOrdered(tvLists)) {
return ordered(
- tsDataType, tvLists, deletionList, floatPrecision, encoding, maxNumberOfPointsInPage);
+ tsDataType,
+ tvLists,
+ scanOrder,
+ globalTimeFilter,
+ deletionList,
+ floatPrecision,
+ encoding,
+ maxNumberOfPointsInPage);
} else {
return mergeSort(
- tsDataType, tvLists, deletionList, floatPrecision, encoding, maxNumberOfPointsInPage);
+ tsDataType,
+ tvLists,
+ scanOrder,
+ globalTimeFilter,
+ deletionList,
+ floatPrecision,
+ encoding,
+ maxNumberOfPointsInPage);
}
}
@@ -329,6 +427,8 @@ public class MemPointIteratorFactory {
List<TSDataType> tsDataTypes,
List<Integer> columnIndexList,
List<AlignedTVList> alignedTvLists,
+ Ordering scanOrder,
+ Filter globalTimeFilter,
List<List<TimeRange>> valueColumnsDeletionList,
Integer floatPrecision,
List<TSEncoding> encodingList,
@@ -338,6 +438,8 @@ public class MemPointIteratorFactory {
tsDataTypes,
columnIndexList,
alignedTvLists,
+ scanOrder,
+ globalTimeFilter,
valueColumnsDeletionList,
floatPrecision,
encodingList,
@@ -347,6 +449,8 @@ public class MemPointIteratorFactory {
tsDataTypes,
columnIndexList,
alignedTvLists,
+ scanOrder,
+ globalTimeFilter,
valueColumnsDeletionList,
floatPrecision,
encodingList,
@@ -356,6 +460,8 @@ public class MemPointIteratorFactory {
tsDataTypes,
columnIndexList,
alignedTvLists,
+ scanOrder,
+ globalTimeFilter,
valueColumnsDeletionList,
floatPrecision,
encodingList,
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/MergeSortMultiAlignedTVListIterator.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/MergeSortMultiAlignedTVListIterator.java
index 42fbf6fb4fd..bf96e822b06 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/MergeSortMultiAlignedTVListIterator.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/MergeSortMultiAlignedTVListIterator.java
@@ -19,9 +19,12 @@
package org.apache.iotdb.db.utils.datastructure;
+import org.apache.iotdb.db.queryengine.plan.statement.component.Ordering;
+
import org.apache.tsfile.enums.TSDataType;
import org.apache.tsfile.file.metadata.enums.TSEncoding;
import org.apache.tsfile.read.common.TimeRange;
+import org.apache.tsfile.read.filter.basic.Filter;
import org.apache.tsfile.utils.BitMap;
import org.apache.tsfile.utils.Pair;
import org.apache.tsfile.write.UnSupportedDataTypeException;
@@ -29,7 +32,6 @@ import org.apache.tsfile.write.chunk.AlignedChunkWriterImpl;
import org.apache.tsfile.write.chunk.IChunkWriter;
import org.apache.tsfile.write.chunk.ValueChunkWriter;
-import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.PriorityQueue;
@@ -45,16 +47,15 @@ public class MergeSortMultiAlignedTVListIterator extends MultiAlignedTVListItera
private final int[] rowIndices;
private final BitMap bitMap;
- private final List<int[]> valueColumnDeleteCursor;
// Min-Heap: minimal timestamp; if same timestamp, maximum TVList index
- private final PriorityQueue<Pair<Long, Integer>> minHeap =
- new PriorityQueue<>(
- (a, b) -> a.left.equals(b.left) ? b.right.compareTo(a.right) : a.left.compareTo(b.left));
+ private final PriorityQueue<Pair<Long, Integer>> heap;
public MergeSortMultiAlignedTVListIterator(
List<TSDataType> tsDataTypes,
List<Integer> columnIndexList,
List<AlignedTVList> alignedTvLists,
+ Ordering scanOrder,
+ Filter globalTimeFilter,
List<List<TimeRange>> valueColumnsDeletionList,
Integer floatPrecision,
List<TSEncoding> encodingList,
@@ -63,6 +64,8 @@ public class MergeSortMultiAlignedTVListIterator extends MultiAlignedTVListItera
tsDataTypes,
columnIndexList,
alignedTvLists,
+ scanOrder,
+ globalTimeFilter,
valueColumnsDeletionList,
floatPrecision,
encodingList,
@@ -72,10 +75,13 @@ public class MergeSortMultiAlignedTVListIterator extends MultiAlignedTVListItera
this.bitMap = new BitMap(tsDataTypeList.size());
this.iteratorIndices = new int[tsDataTypeList.size()];
this.rowIndices = new int[tsDataTypeList.size()];
- this.valueColumnDeleteCursor = new ArrayList<>();
- for (int i = 0; i < tsDataTypeList.size(); i++) {
- valueColumnDeleteCursor.add(new int[] {0});
- }
+ this.heap =
+ new PriorityQueue<>(
+ scanOrder.isAscending()
+ ? (a, b) ->
+ a.left.equals(b.left) ? b.right.compareTo(a.right) : a.left.compareTo(b.left)
+ : (a, b) ->
+ a.left.equals(b.left) ? a.right.compareTo(b.right) : b.left.compareTo(a.left));
}
@Override
@@ -84,14 +90,14 @@ public class MergeSortMultiAlignedTVListIterator extends MultiAlignedTVListItera
for (int i : probeIterators) {
AlignedTVList.AlignedTVListIterator iterator = alignedTvListIterators.get(i);
if (iterator.hasNextTimeValuePair()) {
- minHeap.add(new Pair<>(iterator.currentTime(), i));
+ heap.add(new Pair<>(iterator.currentTime(), i));
}
}
probeIterators.clear();
- while (!minHeap.isEmpty() && !hasNext) {
+ while (!heap.isEmpty() && !hasNext) {
bitMap.reset();
- Pair<Long, Integer> top = minHeap.poll();
+ Pair<Long, Integer> top = heap.poll();
currentTime = top.left;
probeIterators.add(top.right);
@@ -104,18 +110,35 @@ public class MergeSortMultiAlignedTVListIterator extends MultiAlignedTVListItera
.isNullValue(rowIndices[columnIndex], columnIndex)) {
bitMap.mark(columnIndex);
}
+ // check valueColumnsDeletionList
+ if (valueColumnsDeletionList != null
+ && isPointDeleted(
+ currentTime,
+ valueColumnsDeletionList.get(columnIndex),
+ valueColumnDeleteCursor.get(columnIndex),
+ scanOrder)) {
+ iteratorIndices[columnIndex] = -1;
+ bitMap.mark(columnIndex);
+ continue;
+ }
}
hasNext = true;
// duplicated timestamps
- while (!minHeap.isEmpty() && minHeap.peek().left == currentTime) {
- Pair<Long, Integer> element = minHeap.poll();
+ while (!heap.isEmpty() && heap.peek().left == currentTime) {
+ Pair<Long, Integer> element = heap.poll();
probeIterators.add(element.right);
for (int columnIndex = 0; columnIndex < tsDataTypeList.size(); columnIndex++) {
// if current column null, it needs update
+ int iteratorIndex = currentIteratorIndex(columnIndex);
+ if (iteratorIndex == -1) {
+ // -1 means all point of this timestamp was deleted by Deletion and no further
+ // processing is required.
+ continue;
+ }
if (alignedTvListIterators
- .get(iteratorIndices[columnIndex])
+ .get(iteratorIndex)
.isNullValue(rowIndices[columnIndex], columnIndex)) {
iteratorIndices[columnIndex] = element.right;
rowIndices[columnIndex] =
@@ -132,7 +155,8 @@ public class MergeSortMultiAlignedTVListIterator extends MultiAlignedTVListItera
&& isPointDeleted(
currentTime,
valueColumnsDeletionList.get(columnIndex),
- valueColumnDeleteCursor.get(columnIndex))) {
+ valueColumnDeleteCursor.get(columnIndex),
+ scanOrder)) {
iteratorIndices[columnIndex] = -1;
bitMap.mark(columnIndex);
}
@@ -146,7 +170,7 @@ public class MergeSortMultiAlignedTVListIterator extends MultiAlignedTVListItera
AlignedTVList.AlignedTVListIterator iterator = alignedTvListIterators.get(idx);
iterator.next();
if (iterator.hasNextTimeValuePair()) {
- minHeap.add(new Pair<>(iterator.currentTime(), idx));
+ heap.add(new Pair<>(iterator.currentTime(), idx));
} else {
it.remove();
}
@@ -173,8 +197,12 @@ public class MergeSortMultiAlignedTVListIterator extends MultiAlignedTVListItera
for (int columnIndex = 0; columnIndex < tsDataTypeList.size(); columnIndex++) {
ValueChunkWriter valueChunkWriter =
alignedChunkWriterImpl.getValueChunkWriterByIndex(columnIndex);
- AlignedTVList alignedTVList =
- alignedTvListIterators.get(currentIteratorIndex(columnIndex)).getAlignedTVList();
+ int iteratorIndex = currentIteratorIndex(columnIndex);
+ if (iteratorIndex == -1) {
+ valueChunkWriter.write(currentTime, null, true);
+ continue;
+ }
+ AlignedTVList alignedTVList = alignedTvListIterators.get(iteratorIndex).getAlignedTVList();
// sanity check
int validColumnIndex =
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/MergeSortMultiTVListIterator.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/MergeSortMultiTVListIterator.java
index 74636222acc..44fa0d47807 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/MergeSortMultiTVListIterator.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/MergeSortMultiTVListIterator.java
@@ -19,9 +19,12 @@
package org.apache.iotdb.db.utils.datastructure;
+import org.apache.iotdb.db.queryengine.plan.statement.component.Ordering;
+
import org.apache.tsfile.enums.TSDataType;
import org.apache.tsfile.file.metadata.enums.TSEncoding;
import org.apache.tsfile.read.common.TimeRange;
+import org.apache.tsfile.read.filter.basic.Filter;
import org.apache.tsfile.utils.Binary;
import org.apache.tsfile.utils.Pair;
import org.apache.tsfile.write.UnSupportedDataTypeException;
@@ -37,20 +40,35 @@ import static org.apache.iotdb.db.utils.MemUtils.getBinarySize;
public class MergeSortMultiTVListIterator extends MultiTVListIterator {
private final List<Integer> probeIterators;
- private final PriorityQueue<Pair<Long, Integer>> minHeap =
- new PriorityQueue<>(
- (a, b) -> a.left.equals(b.left) ? b.right.compareTo(a.right) : a.left.compareTo(b.left));
+ private final PriorityQueue<Pair<Long, Integer>> heap;
public MergeSortMultiTVListIterator(
+ Ordering scanOrder,
+ Filter globalTimeFilter,
TSDataType tsDataType,
List<TVList> tvLists,
List<TimeRange> deletionList,
Integer floatPrecision,
TSEncoding encoding,
int maxNumberOfPointsInPage) {
- super(tsDataType, tvLists, deletionList, floatPrecision, encoding, maxNumberOfPointsInPage);
+ super(
+ scanOrder,
+ globalTimeFilter,
+ tsDataType,
+ tvLists,
+ deletionList,
+ floatPrecision,
+ encoding,
+ maxNumberOfPointsInPage);
this.probeIterators =
IntStream.range(0, tvListIterators.size()).boxed().collect(Collectors.toList());
+ this.heap =
+ new PriorityQueue<>(
+ scanOrder.isAscending()
+ ? (a, b) ->
+ a.left.equals(b.left) ? b.right.compareTo(a.right) : a.left.compareTo(b.left)
+ : (a, b) ->
+ a.left.equals(b.left) ? a.right.compareTo(b.right) : b.left.compareTo(a.left));
}
@Override
@@ -59,13 +77,13 @@ public class MergeSortMultiTVListIterator extends MultiTVListIterator {
for (int i : probeIterators) {
TVList.TVListIterator iterator = tvListIterators.get(i);
if (iterator.hasNextTimeValuePair()) {
- minHeap.add(new Pair<>(iterator.currentTime(), i));
+ heap.add(new Pair<>(iterator.currentTime(), i));
}
}
probeIterators.clear();
- if (!minHeap.isEmpty()) {
- Pair<Long, Integer> top = minHeap.poll();
+ if (!heap.isEmpty()) {
+ Pair<Long, Integer> top = heap.poll();
currentTime = top.left;
probeIterators.add(top.right);
@@ -74,8 +92,8 @@ public class MergeSortMultiTVListIterator extends MultiTVListIterator {
hasNext = true;
// duplicated timestamps
- while (!minHeap.isEmpty() && minHeap.peek().left == currentTime) {
- Pair<Long, Integer> element = minHeap.poll();
+ while (!heap.isEmpty() && heap.peek().left == currentTime) {
+ Pair<Long, Integer> element = heap.poll();
probeIterators.add(element.right);
}
}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/MultiAlignedTVListIterator.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/MultiAlignedTVListIterator.java
index 42292dc27fc..64ed298da24 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/MultiAlignedTVListIterator.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/MultiAlignedTVListIterator.java
@@ -19,6 +19,8 @@
package org.apache.iotdb.db.utils.datastructure;
+import org.apache.iotdb.db.queryengine.plan.statement.component.Ordering;
+
import org.apache.tsfile.block.column.ColumnBuilder;
import org.apache.tsfile.enums.TSDataType;
import org.apache.tsfile.file.metadata.enums.TSEncoding;
@@ -26,7 +28,10 @@ import org.apache.tsfile.read.TimeValuePair;
import org.apache.tsfile.read.common.TimeRange;
import org.apache.tsfile.read.common.block.TsBlock;
import org.apache.tsfile.read.common.block.TsBlockBuilder;
+import org.apache.tsfile.read.common.block.TsBlockUtil;
import org.apache.tsfile.read.common.block.column.TimeColumnBuilder;
+import org.apache.tsfile.read.filter.basic.Filter;
+import org.apache.tsfile.read.reader.series.PaginationController;
import org.apache.tsfile.utils.TsPrimitiveType;
import org.apache.tsfile.write.UnSupportedDataTypeException;
@@ -34,7 +39,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
-public abstract class MultiAlignedTVListIterator implements MemPointIterator {
+public abstract class MultiAlignedTVListIterator extends MemPointIterator {
protected List<TSDataType> tsDataTypeList;
protected List<Integer> columnIndexList;
protected List<AlignedTVList.AlignedTVListIterator> alignedTvListIterators;
@@ -45,46 +50,81 @@ public abstract class MultiAlignedTVListIterator implements MemPointIterator {
protected boolean probeNext = false;
protected boolean hasNext = false;
- protected List<TsBlock> tsBlocks;
protected long currentTime;
// used by nextBatch during query
protected final int maxNumberOfPointsInPage;
+ protected final List<int[]> valueColumnDeleteCursor;
protected MultiAlignedTVListIterator(
List<TSDataType> tsDataTypeList,
List<Integer> columnIndexList,
List<AlignedTVList> alignedTvLists,
+ Ordering scanOrder,
+ Filter globalTimeFilter,
List<List<TimeRange>> valueColumnsDeletionList,
Integer floatPrecision,
List<TSEncoding> encodingList,
int maxNumberOfPointsInPage) {
+ super(scanOrder);
this.tsDataTypeList = tsDataTypeList;
this.columnIndexList = columnIndexList;
this.alignedTvListIterators = new ArrayList<>(alignedTvLists.size());
- for (AlignedTVList alignedTvList : alignedTvLists) {
- alignedTvListIterators.add(
- alignedTvList.iterator(
- tsDataTypeList,
- columnIndexList,
- null,
- floatPrecision,
- encodingList,
- maxNumberOfPointsInPage));
+ if (scanOrder.isAscending()) {
+ for (AlignedTVList alignedTVList : alignedTvLists) {
+ AlignedTVList.AlignedTVListIterator iterator =
+ alignedTVList.iterator(
+ scanOrder,
+ globalTimeFilter,
+ tsDataTypeList,
+ columnIndexList,
+ null,
+ floatPrecision,
+ encodingList,
+ maxNumberOfPointsInPage);
+ alignedTvListIterators.add(iterator);
+ }
+ } else {
+ for (int i = alignedTvLists.size() - 1; i >= 0; i--) {
+ AlignedTVList alignedTVList = alignedTvLists.get(i);
+ AlignedTVList.AlignedTVListIterator iterator =
+ alignedTVList.iterator(
+ scanOrder,
+ globalTimeFilter,
+ tsDataTypeList,
+ columnIndexList,
+ null,
+ floatPrecision,
+ encodingList,
+ maxNumberOfPointsInPage);
+ alignedTvListIterators.add(iterator);
+ }
}
this.valueColumnsDeletionList = valueColumnsDeletionList;
this.floatPrecision = floatPrecision != null ? floatPrecision : 0;
this.encodingList = encodingList;
- this.tsBlocks = new ArrayList<>();
this.maxNumberOfPointsInPage = maxNumberOfPointsInPage;
+ this.valueColumnDeleteCursor = new ArrayList<>();
+ for (int i = 0; i < tsDataTypeList.size(); i++) {
+ List<TimeRange> valueColumnDeletions =
+ valueColumnsDeletionList == null ? null : valueColumnsDeletionList.get(i);
+ int cursor =
+ (valueColumnDeletions == null || scanOrder.isAscending())
+ ? 0
+ : (valueColumnDeletions.size() - 1);
+ valueColumnDeleteCursor.add(new int[] {cursor});
+ }
}
@Override
public boolean hasNextTimeValuePair() {
+ if (!paginationController.hasCurLimit()) {
+ return false;
+ }
if (!probeNext) {
prepareNext();
}
- return hasNext;
+ return hasNext && !isCurrentTimeExceedTimeRange(currentTime);
}
@Override
@@ -94,8 +134,11 @@ public abstract class MultiAlignedTVListIterator implements MemPointIterator {
}
TsPrimitiveType[] vector = new TsPrimitiveType[tsDataTypeList.size()];
for (int columnIndex = 0; columnIndex < tsDataTypeList.size(); columnIndex++) {
- AlignedTVList.AlignedTVListIterator iterator =
- alignedTvListIterators.get(currentIteratorIndex(columnIndex));
+ int iteratorIndex = currentIteratorIndex(columnIndex);
+ if (iteratorIndex == -1) {
+ continue;
+ }
+ AlignedTVList.AlignedTVListIterator iterator = alignedTvListIterators.get(iteratorIndex);
vector[columnIndex] =
iterator.getPrimitiveTypeObject(currentRowIndex(columnIndex), columnIndex);
}
@@ -112,8 +155,11 @@ public abstract class MultiAlignedTVListIterator implements MemPointIterator {
}
TsPrimitiveType[] vector = new TsPrimitiveType[tsDataTypeList.size()];
for (int columnIndex = 0; columnIndex < tsDataTypeList.size(); columnIndex++) {
- AlignedTVList.AlignedTVListIterator iterator =
- alignedTvListIterators.get(currentIteratorIndex(columnIndex));
+ int iteratorIndex = currentIteratorIndex(columnIndex);
+ if (iteratorIndex == -1) {
+ continue;
+ }
+ AlignedTVList.AlignedTVListIterator iterator = alignedTvListIterators.get(iteratorIndex);
vector[columnIndex] =
iterator.getPrimitiveTypeObject(currentRowIndex(columnIndex), columnIndex);
}
@@ -127,7 +173,7 @@ public abstract class MultiAlignedTVListIterator implements MemPointIterator {
@Override
public TsBlock nextBatch() {
- TsBlockBuilder builder = new TsBlockBuilder(tsDataTypeList);
+ TsBlockBuilder builder = new TsBlockBuilder(maxNumberOfPointsInPage, tsDataTypeList);
// Time column
TimeColumnBuilder timeBuilder = builder.getTimeColumnBuilder();
@@ -136,8 +182,14 @@ public abstract class MultiAlignedTVListIterator implements MemPointIterator {
for (int columnIndex = 0; columnIndex < tsDataTypeList.size(); columnIndex++) {
// Value column
ColumnBuilder valueBuilder = builder.getColumnBuilder(columnIndex);
- AlignedTVList alignedTVList =
- alignedTvListIterators.get(currentIteratorIndex(columnIndex)).getAlignedTVList();
+ int currentIteratorIndex = currentIteratorIndex(columnIndex);
+ if (currentIteratorIndex == -1) {
+ valueBuilder.appendNull();
+ continue;
+ }
+ AlignedTVList.AlignedTVListIterator alignedTVListIterator =
+ alignedTvListIterators.get(currentIteratorIndex);
+ AlignedTVList alignedTVList = alignedTVListIterator.getAlignedTVList();
// sanity check
int validColumnIndex =
@@ -147,7 +199,9 @@ public abstract class MultiAlignedTVListIterator implements MemPointIterator {
continue;
}
- int valueIndex = alignedTVList.getValueIndex(currentRowIndex(columnIndex));
+ int valueIndex =
+ alignedTVList.getValueIndex(
+ alignedTVListIterator.getScanOrderIndex(currentRowIndex(columnIndex)));
// null value
if (alignedTVList.isNullValue(valueIndex, validColumnIndex)) {
valueBuilder.appendNull();
@@ -201,7 +255,18 @@ public abstract class MultiAlignedTVListIterator implements MemPointIterator {
builder.declarePosition();
}
TsBlock tsBlock = builder.build();
- tsBlocks.add(tsBlock);
+ if (pushDownFilter != null) {
+ tsBlock =
+ TsBlockUtil.applyFilterAndLimitOffsetToTsBlock(
+ tsBlock,
+ new TsBlockBuilder(
+ Math.min(maxNumberOfPointsInPage, tsBlock.getPositionCount()), tsDataTypeList),
+ pushDownFilter,
+ paginationController);
+ } else {
+ tsBlock = paginationController.applyTsBlock(tsBlock);
+ }
+ addTsBlock(tsBlock);
return tsBlock;
}
@@ -229,4 +294,22 @@ public abstract class MultiAlignedTVListIterator implements MemPointIterator {
protected abstract void prepareNext();
protected abstract void next();
+
+ @Override
+ public void setPushDownFilter(Filter pushDownFilter) {
+ for (AlignedTVList.AlignedTVListIterator iterator : alignedTvListIterators) {
+ iterator.setPushDownFilter(pushDownFilter);
+ }
+ this.pushDownFilter = pushDownFilter;
+ }
+
+ @Override
+ public void setLimitAndOffset(PaginationController paginationController) {
+ for (AlignedTVList.AlignedTVListIterator iterator : alignedTvListIterators) {
+ iterator.setLimitAndOffset(
+ new PaginationController(
+ paginationController.getCurLimit() + paginationController.getCurOffset(), 0));
+ }
+ this.paginationController = paginationController;
+ }
}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/MultiTVListIterator.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/MultiTVListIterator.java
index aa9ec257311..a8d5879b767 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/MultiTVListIterator.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/MultiTVListIterator.java
@@ -19,23 +19,26 @@
package org.apache.iotdb.db.utils.datastructure;
+import org.apache.iotdb.db.queryengine.plan.statement.component.Ordering;
+
import org.apache.tsfile.enums.TSDataType;
import org.apache.tsfile.file.metadata.enums.TSEncoding;
import org.apache.tsfile.read.TimeValuePair;
import org.apache.tsfile.read.common.TimeRange;
import org.apache.tsfile.read.common.block.TsBlock;
import org.apache.tsfile.read.common.block.TsBlockBuilder;
+import org.apache.tsfile.read.filter.basic.Filter;
+import org.apache.tsfile.read.reader.series.PaginationController;
+import org.apache.tsfile.utils.Binary;
import org.apache.tsfile.write.UnSupportedDataTypeException;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-public abstract class MultiTVListIterator implements MemPointIterator {
+public abstract class MultiTVListIterator extends MemPointIterator {
protected TSDataType tsDataType;
protected List<TVList.TVListIterator> tvListIterators;
- protected List<TsBlock> tsBlocks;
protected int floatPrecision;
protected TSEncoding encoding;
@@ -49,29 +52,47 @@ public abstract class MultiTVListIterator implements MemPointIterator {
protected final int maxNumberOfPointsInPage;
protected MultiTVListIterator(
+ Ordering scanOrder,
+ Filter globalTimeFilter,
TSDataType tsDataType,
List<TVList> tvLists,
List<TimeRange> deletionList,
Integer floatPrecision,
TSEncoding encoding,
int maxNumberOfPointsInPage) {
+ super(scanOrder);
this.tsDataType = tsDataType;
this.tvListIterators = new ArrayList<>(tvLists.size());
- for (TVList tvList : tvLists) {
- tvListIterators.add(tvList.iterator(deletionList, null, null, maxNumberOfPointsInPage));
+ if (scanOrder.isAscending()) {
+ for (TVList tvList : tvLists) {
+ TVList.TVListIterator iterator =
+ tvList.iterator(
+ scanOrder, globalTimeFilter, deletionList, null, null, maxNumberOfPointsInPage);
+ tvListIterators.add(iterator);
+ }
+ } else {
+ for (int i = tvLists.size() - 1; i >= 0; i--) {
+ TVList tvList = tvLists.get(i);
+ TVList.TVListIterator iterator =
+ tvList.iterator(
+ scanOrder, globalTimeFilter, deletionList, null, null, maxNumberOfPointsInPage);
+ tvListIterators.add(iterator);
+ }
}
this.floatPrecision = floatPrecision != null ? floatPrecision : 0;
this.encoding = encoding;
- this.tsBlocks = new ArrayList<>();
this.maxNumberOfPointsInPage = maxNumberOfPointsInPage;
}
@Override
public boolean hasNextTimeValuePair() {
+ if (!paginationController.hasCurLimit()) {
+ return false;
+ }
if (!probeNext) {
prepareNext();
}
- return hasNext;
+ return hasNext && !isCurrentTimeExceedTimeRange(currentTime);
}
@Override
@@ -81,7 +102,10 @@ public abstract class MultiTVListIterator implements MemPointIterator {
}
TVList.TVListIterator iterator = tvListIterators.get(iteratorIndex);
TimeValuePair currentTvPair =
- iterator.getTVList().getTimeValuePair(rowIndex, currentTime, floatPrecision, encoding);
+ iterator
+ .getTVList()
+ .getTimeValuePair(
+ iterator.getScanOrderIndex(rowIndex), currentTime, floatPrecision, encoding);
next();
return currentTvPair;
}
@@ -103,52 +127,101 @@ public abstract class MultiTVListIterator implements MemPointIterator {
@Override
public TsBlock nextBatch() {
TsBlockBuilder builder = new TsBlockBuilder(Collections.singletonList(tsDataType));
- while (hasNextTimeValuePair() && builder.getPositionCount() < maxNumberOfPointsInPage) {
- TVList.TVListIterator iterator = tvListIterators.get(iteratorIndex);
- builder.getTimeColumnBuilder().writeLong(currentTime);
- switch (tsDataType) {
- case BOOLEAN:
- builder.getColumnBuilder(0).writeBoolean(iterator.getTVList().getBoolean(rowIndex));
- break;
- case INT32:
- case DATE:
- builder.getColumnBuilder(0).writeInt(iterator.getTVList().getInt(rowIndex));
- break;
- case INT64:
- case TIMESTAMP:
- builder.getColumnBuilder(0).writeLong(iterator.getTVList().getLong(rowIndex));
- break;
- case FLOAT:
+ switch (tsDataType) {
+ case BOOLEAN:
+ while (hasNextTimeValuePair() && builder.getPositionCount() < maxNumberOfPointsInPage) {
+ TVList.TVListIterator iterator = tvListIterators.get(iteratorIndex);
+ boolean aBoolean = iterator.getTVList().getBoolean(iterator.getScanOrderIndex(rowIndex));
+ if (pushDownFilter == null || pushDownFilter.satisfyBoolean(currentTime, aBoolean)) {
+ builder.getTimeColumnBuilder().writeLong(currentTime);
+ builder.getColumnBuilder(0).writeBoolean(aBoolean);
+ builder.declarePosition();
+ }
+ next();
+ }
+ break;
+ case INT32:
+ case DATE:
+ while (hasNextTimeValuePair() && builder.getPositionCount() < maxNumberOfPointsInPage) {
+ TVList.TVListIterator iterator = tvListIterators.get(iteratorIndex);
+ int anInt = iterator.getTVList().getInt(iterator.getScanOrderIndex(rowIndex));
+ if (pushDownFilter == null || pushDownFilter.satisfyInteger(currentTime, anInt)) {
+ builder.getTimeColumnBuilder().writeLong(currentTime);
+ builder.getColumnBuilder(0).writeInt(anInt);
+ builder.declarePosition();
+ }
+ next();
+ }
+ break;
+ case INT64:
+ case TIMESTAMP:
+ while (hasNextTimeValuePair() && builder.getPositionCount() < maxNumberOfPointsInPage) {
+ TVList.TVListIterator iterator = tvListIterators.get(iteratorIndex);
+ long aLong = iterator.getTVList().getLong(iterator.getScanOrderIndex(rowIndex));
+ if (pushDownFilter == null || pushDownFilter.satisfyLong(currentTime, aLong)) {
+ builder.getTimeColumnBuilder().writeLong(currentTime);
+ builder.getColumnBuilder(0).writeLong(aLong);
+ builder.declarePosition();
+ }
+ next();
+ }
+ break;
+ case FLOAT:
+ while (hasNextTimeValuePair() && builder.getPositionCount() < maxNumberOfPointsInPage) {
+ TVList.TVListIterator iterator = tvListIterators.get(iteratorIndex);
TVList floatTvList = iterator.getTVList();
- builder
- .getColumnBuilder(0)
- .writeFloat(
- floatTvList.roundValueWithGivenPrecision(
- floatTvList.getFloat(rowIndex), floatPrecision, encoding));
- break;
- case DOUBLE:
+ float aFloat =
+ floatTvList.roundValueWithGivenPrecision(
+ floatTvList.getFloat(iterator.getScanOrderIndex(rowIndex)),
+ floatPrecision,
+ encoding);
+ if (pushDownFilter == null || pushDownFilter.satisfyFloat(currentTime, aFloat)) {
+ builder.getTimeColumnBuilder().writeLong(currentTime);
+ builder.getColumnBuilder(0).writeFloat(aFloat);
+ builder.declarePosition();
+ }
+ next();
+ }
+ break;
+ case DOUBLE:
+ while (hasNextTimeValuePair() && builder.getPositionCount() < maxNumberOfPointsInPage) {
+ TVList.TVListIterator iterator = tvListIterators.get(iteratorIndex);
TVList doubleTvList = iterator.getTVList();
- builder
- .getColumnBuilder(0)
- .writeDouble(
- doubleTvList.roundValueWithGivenPrecision(
- doubleTvList.getDouble(rowIndex), floatPrecision, encoding));
- break;
- case TEXT:
- case BLOB:
- case STRING:
- builder.getColumnBuilder(0).writeBinary(iterator.getTVList().getBinary(rowIndex));
- break;
- default:
- throw new UnSupportedDataTypeException(
- String.format("Data type %s is not supported.", tsDataType));
- }
- next();
-
- builder.declarePosition();
+ double aDouble =
+ doubleTvList.roundValueWithGivenPrecision(
+ doubleTvList.getDouble(iterator.getScanOrderIndex(rowIndex)),
+ floatPrecision,
+ encoding);
+ if (pushDownFilter == null || pushDownFilter.satisfyDouble(currentTime, aDouble)) {
+ builder.getTimeColumnBuilder().writeLong(currentTime);
+ builder.getColumnBuilder(0).writeDouble(aDouble);
+ builder.declarePosition();
+ }
+ next();
+ }
+ break;
+ case TEXT:
+ case BLOB:
+ case STRING:
+ while (hasNextTimeValuePair() && builder.getPositionCount() < maxNumberOfPointsInPage) {
+ TVList.TVListIterator iterator = tvListIterators.get(iteratorIndex);
+ Binary binary = iterator.getTVList().getBinary(iterator.getScanOrderIndex(rowIndex));
+ if (pushDownFilter == null || pushDownFilter.satisfyBinary(currentTime, binary)) {
+ builder.getTimeColumnBuilder().writeLong(currentTime);
+ builder.getColumnBuilder(0).writeBinary(binary);
+ builder.declarePosition();
+ }
+ next();
+ }
+ break;
+ default:
+ throw new UnSupportedDataTypeException(
+ String.format("Data type %s is not supported.", tsDataType));
}
- TsBlock tsBlock = builder.build();
- tsBlocks.add(tsBlock);
+ // There is no need to process pushDownFilter here because it has been applied when
+ // constructing the tsBlock
+ TsBlock tsBlock = paginationController.applyTsBlock(builder.build());
+ addTsBlock(tsBlock);
return tsBlock;
}
@@ -166,12 +239,23 @@ public abstract class MultiTVListIterator implements MemPointIterator {
return 0;
}
- @Override
- public void close() throws IOException {
- tsBlocks.clear();
- }
-
protected abstract void prepareNext();
protected abstract void next();
+
+ @Override
+ public void setPushDownFilter(Filter pushDownFilter) {
+ for (TVList.TVListIterator iterator : tvListIterators) {
+ iterator.setPushDownFilter(pushDownFilter);
+ }
+ this.pushDownFilter = pushDownFilter;
+ }
+
+ @Override
+ public void setLimitAndOffset(PaginationController paginationController) {
+ for (TVList.TVListIterator iterator : tvListIterators) {
+ iterator.setLimitAndOffset(paginationController);
+ }
+ this.paginationController = paginationController;
+ }
}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/OrderedMultiAlignedTVListIterator.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/OrderedMultiAlignedTVListIterator.java
index ecd6c496dfb..c138b1ff07b 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/OrderedMultiAlignedTVListIterator.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/OrderedMultiAlignedTVListIterator.java
@@ -19,20 +19,21 @@
package org.apache.iotdb.db.utils.datastructure;
+import org.apache.iotdb.db.queryengine.plan.statement.component.Ordering;
+
import org.apache.tsfile.enums.TSDataType;
import org.apache.tsfile.file.metadata.enums.TSEncoding;
import org.apache.tsfile.read.common.TimeRange;
+import org.apache.tsfile.read.filter.basic.Filter;
import org.apache.tsfile.utils.BitMap;
import org.apache.tsfile.write.chunk.IChunkWriter;
-import java.util.ArrayList;
import java.util.List;
import static org.apache.iotdb.db.utils.ModificationUtils.isPointDeleted;
public class OrderedMultiAlignedTVListIterator extends MultiAlignedTVListIterator {
private final BitMap bitMap;
- private final List<int[]> valueColumnDeleteCursor;
private int iteratorIndex = 0;
private int[] rowIndices;
@@ -40,6 +41,8 @@ public class OrderedMultiAlignedTVListIterator extends MultiAlignedTVListIterato
List<TSDataType> tsDataTypes,
List<Integer> columnIndexList,
List<AlignedTVList> alignedTvLists,
+ Ordering scanOrder,
+ Filter globalTimeFilter,
List<List<TimeRange>> valueColumnsDeletionList,
Integer floatPrecision,
List<TSEncoding> encodingList,
@@ -48,15 +51,13 @@ public class OrderedMultiAlignedTVListIterator extends MultiAlignedTVListIterato
tsDataTypes,
columnIndexList,
alignedTvLists,
+ scanOrder,
+ globalTimeFilter,
valueColumnsDeletionList,
floatPrecision,
encodingList,
maxNumberOfPointsInPage);
this.bitMap = new BitMap(tsDataTypeList.size());
- this.valueColumnDeleteCursor = new ArrayList<>();
- for (int i = 0; i < tsDataTypeList.size(); i++) {
- valueColumnDeleteCursor.add(new int[] {0});
- }
}
@Override
@@ -81,7 +82,8 @@ public class OrderedMultiAlignedTVListIterator extends MultiAlignedTVListIterato
&& isPointDeleted(
currentTime,
valueColumnsDeletionList.get(columnIndex),
- valueColumnDeleteCursor.get(columnIndex)))
+ valueColumnDeleteCursor.get(columnIndex),
+ scanOrder))
|| iterator.isNullValue(rowIndices[columnIndex], columnIndex)) {
bitMap.mark(columnIndex);
}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/OrderedMultiTVListIterator.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/OrderedMultiTVListIterator.java
index eeb69ddb95b..c7ae99386c5 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/OrderedMultiTVListIterator.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/OrderedMultiTVListIterator.java
@@ -19,22 +19,35 @@
package org.apache.iotdb.db.utils.datastructure;
+import org.apache.iotdb.db.queryengine.plan.statement.component.Ordering;
+
import org.apache.tsfile.enums.TSDataType;
import org.apache.tsfile.file.metadata.enums.TSEncoding;
import org.apache.tsfile.read.common.TimeRange;
+import org.apache.tsfile.read.filter.basic.Filter;
import org.apache.tsfile.write.chunk.IChunkWriter;
import java.util.List;
public class OrderedMultiTVListIterator extends MultiTVListIterator {
public OrderedMultiTVListIterator(
+ Ordering scanOrder,
+ Filter globalTimeFilter,
TSDataType tsDataType,
List<TVList> tvLists,
List<TimeRange> deletionList,
Integer floatPrecision,
TSEncoding encoding,
int maxNumberOfPointsInPage) {
- super(tsDataType, tvLists, deletionList, floatPrecision, encoding, maxNumberOfPointsInPage);
+ super(
+ scanOrder,
+ globalTimeFilter,
+ tsDataType,
+ tvLists,
+ deletionList,
+ floatPrecision,
+ encoding,
+ maxNumberOfPointsInPage);
}
@Override
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/TVList.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/TVList.java
index cc499ac1e0b..3d5ee978469 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/TVList.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/TVList.java
@@ -21,6 +21,7 @@ package org.apache.iotdb.db.utils.datastructure;
import org.apache.iotdb.commons.utils.TestOnly;
import org.apache.iotdb.db.queryengine.execution.fragment.QueryContext;
+import org.apache.iotdb.db.queryengine.plan.statement.component.Ordering;
import org.apache.iotdb.db.storageengine.dataregion.wal.buffer.WALEntryValue;
import org.apache.iotdb.db.storageengine.rescon.memory.PrimitiveArrayManager;
import org.apache.iotdb.db.utils.MathUtils;
@@ -31,6 +32,7 @@ import org.apache.tsfile.read.TimeValuePair;
import org.apache.tsfile.read.common.TimeRange;
import org.apache.tsfile.read.common.block.TsBlock;
import org.apache.tsfile.read.common.block.TsBlockBuilder;
+import org.apache.tsfile.read.filter.basic.Filter;
import org.apache.tsfile.utils.Binary;
import org.apache.tsfile.utils.BitMap;
import org.apache.tsfile.utils.ReadWriteIOUtils;
@@ -244,6 +246,10 @@ public abstract class TVList implements WALEntryValue {
return indices.get(arrayIndex)[elementIndex];
}
+ public int getValueIndex(int index, Ordering ordering) {
+ return ordering.isAscending() ? getValueIndex(index) : getValueIndex(rowCount - 1 - index);
+ }
+
protected void markNullValue(int arrayIndex, int elementIndex) {
// init bitMap if doesn't have
if (bitMap == null) {
@@ -643,22 +649,30 @@ public abstract class TVList implements WALEntryValue {
}
public TVListIterator iterator(
+ Ordering scanOrder,
+ Filter globalTimeFilter,
List<TimeRange> deletionList,
Integer floatPrecision,
TSEncoding encoding,
int maxNumberOfPointsInPage) {
- return new TVListIterator(deletionList, floatPrecision, encoding, maxNumberOfPointsInPage);
+ return new TVListIterator(
+ scanOrder,
+ globalTimeFilter,
+ deletionList,
+ floatPrecision,
+ encoding,
+ maxNumberOfPointsInPage);
}
/* TVList Iterator */
- public class TVListIterator implements MemPointIterator {
+ public class TVListIterator extends MemPointIterator {
protected int index;
protected int rows;
protected boolean probeNext;
- protected List<TsBlock> tsBlocks;
+ protected final Filter globalTimeFilter;
private final List<TimeRange> deletionList;
- private final int[] deleteCursor = {0};
+ private final int[] deleteCursor;
private final int floatPrecision;
private final TSEncoding encoding;
@@ -666,41 +680,96 @@ public abstract class TVList implements WALEntryValue {
protected final int maxNumberOfPointsInPage;
public TVListIterator(
+ Ordering scanOrder,
+ Filter globalTimeFilter,
List<TimeRange> deletionList,
Integer floatPrecision,
TSEncoding encoding,
int maxNumberOfPointsInPage) {
+ super(scanOrder);
+ this.globalTimeFilter = globalTimeFilter;
this.deletionList = deletionList;
this.floatPrecision = floatPrecision != null ? floatPrecision : 0;
this.encoding = encoding;
this.index = 0;
this.rows = rowCount;
this.probeNext = false;
- this.tsBlocks = new ArrayList<>();
this.maxNumberOfPointsInPage = maxNumberOfPointsInPage;
+ int cursor =
+ (deletionList == null || scanOrder.isAscending()) ? 0 : (deletionList.size() - 1);
+ deleteCursor = new int[] {cursor};
}
protected void prepareNext() {
- // skip deleted rows
- while (index < rows
- && (isNullValue(getValueIndex(index))
- || isPointDeleted(getTime(index), deletionList, deleteCursor))) {
- index++;
+ if (scanOrder.isAscending()) {
+ // For ASC traversal, we first find a valid index and then handle duplicate timestamps.
+ // example:
+ // index: 0 scanOrderIndex: 0 (time: 0 value: 0) (deleted)
+ // index: 1 scanOrderIndex: 1 (time: 1 value: 1)
+ // index: 2 scanOrderIndex: 2 (time: 1 value: 2)
+ // index: 3 scanOrderIndex: 3 (time: 2 value: 2) (deleted)
+ // we will move to index 2 finally, and the index track is (0 -> 1 -> 2)
+
+ // skip deleted rows
+ skipDeletedOrTimeNotSatisfiedRows();
+ // skip duplicated timestamp
+ while (index + 1 < rows
+ && getTime(getScanOrderIndex(index + 1)) == getTime(getScanOrderIndex(index))) {
+ index++;
+ }
+ } else {
+ // For DESC traversal, we first handle duplicate timestamps and then find a valid index.
+ // example:
+ // index: 0 scanOrderIndex: 3 (time: 0 value: 0) (deleted)
+ // index: 1 scanOrderIndex: 2 (time: 1 value: 1)
+ // index: 2 scanOrderIndex: 1 (time: 1 value: 2)
+ // index: 3 scanOrderIndex: 0 (time: 2 value: 2) (deleted)
+ // we will move to index 2 finally, and the index track is (3 -> 2)
+
+ // First skip the duplicate timestamps of the latest value that has been used in last call,
+ // and then skip the deleted points. At this time, the first valid point we encounter is a
+ // valid one.
+
+ // skip duplicated timestamp
+ while (index > 0
+ && (index <= rows - 1)
+ && getTime(getScanOrderIndex(index - 1)) == getTime(getScanOrderIndex(index))) {
+ index++;
+ }
+ // skip deleted rows
+ skipDeletedOrTimeNotSatisfiedRows();
}
+ probeNext = true;
+ }
- // skip duplicated timestamp
- while (index + 1 < rows && getTime(index + 1) == getTime(index)) {
+ protected void skipDeletedOrTimeNotSatisfiedRows() {
+ while (index < rows) {
+ if (!isNullValue(getValueIndex(getScanOrderIndex(index)))) {
+ long time = getTime(getScanOrderIndex(index));
+ if (!isPointDeleted(time, deletionList, deleteCursor, scanOrder)
+ && isTimeSatisfied(time)) {
+ break;
+ }
+ }
index++;
}
- probeNext = true;
}
+ protected boolean isTimeSatisfied(long timestamp) {
+ return globalTimeFilter == null || globalTimeFilter.satisfyRow(timestamp, null);
+ }
+
+ // When used as a point reader, we should not apply a pagination controller or push down filter
+ // because it has not yet been merged with other data.
@Override
public boolean hasNextTimeValuePair() {
+ if (!paginationController.hasCurLimit()) {
+ return false;
+ }
if (!probeNext) {
prepareNext();
}
- return index < rows;
+ return index < rows && !isCurrentTimeExceedTimeRange(getTime(getScanOrderIndex(index)));
}
@Override
@@ -708,7 +777,7 @@ public abstract class TVList implements WALEntryValue {
if (!hasNextTimeValuePair()) {
return null;
}
- TimeValuePair tvp = getTimeValuePair(index);
+ TimeValuePair tvp = getTimeValuePair(getScanOrderIndex(index));
next();
return tvp;
}
@@ -718,7 +787,7 @@ public abstract class TVList implements WALEntryValue {
if (!hasNextTimeValuePair()) {
return null;
}
- return getTimeValuePair(index);
+ return getTimeValuePair(getScanOrderIndex(index));
}
@Override
@@ -731,6 +800,9 @@ public abstract class TVList implements WALEntryValue {
@Override
public boolean hasNextBatch() {
+ if (!paginationController.hasCurLimit()) {
+ return false;
+ }
return hasNextTimeValuePair();
}
@@ -741,13 +813,17 @@ public abstract class TVList implements WALEntryValue {
switch (dataType) {
case BOOLEAN:
while (index < rows && builder.getPositionCount() < maxNumberOfPointsInPage) {
- long time = getTime(index);
- if (!isNullValue(getValueIndex(index))
- && !isPointDeleted(time, deletionList, deleteCursor)
- && (index == rows - 1 || time != getTime(index + 1))) {
- builder.getTimeColumnBuilder().writeLong(time);
- builder.getColumnBuilder(0).writeBoolean(getBoolean(index));
- builder.declarePosition();
+ long time = getTime(getScanOrderIndex(index));
+ if (!isNullValue(getValueIndex(getScanOrderIndex(index)))
+ && !isPointDeleted(time, deletionList, deleteCursor, scanOrder)
+ && isLatestPoint(index, time)
+ && isTimeSatisfied(time)) {
+ boolean aBoolean = getBoolean(getScanOrderIndex(index));
+ if (pushDownFilter == null || pushDownFilter.satisfyBoolean(time, aBoolean)) {
+ builder.getTimeColumnBuilder().writeLong(time);
+ builder.getColumnBuilder(0).writeBoolean(aBoolean);
+ builder.declarePosition();
+ }
}
index++;
}
@@ -755,13 +831,17 @@ public abstract class TVList implements WALEntryValue {
case INT32:
case DATE:
while (index < rows && builder.getPositionCount() < maxNumberOfPointsInPage) {
- long time = getTime(index);
- if (!isNullValue(getValueIndex(index))
- && !isPointDeleted(time, deletionList, deleteCursor)
- && (index == rows - 1 || time != getTime(index + 1))) {
- builder.getTimeColumnBuilder().writeLong(time);
- builder.getColumnBuilder(0).writeInt(getInt(index));
- builder.declarePosition();
+ long time = getTime(getScanOrderIndex(index));
+ if (!isNullValue(getValueIndex(getScanOrderIndex(index)))
+ && !isPointDeleted(time, deletionList, deleteCursor, scanOrder)
+ && isLatestPoint(index, time)
+ && isTimeSatisfied(time)) {
+ int anInt = getInt(getScanOrderIndex(index));
+ if (pushDownFilter == null || pushDownFilter.satisfyInteger(time, anInt)) {
+ builder.getTimeColumnBuilder().writeLong(time);
+ builder.getColumnBuilder(0).writeInt(anInt);
+ builder.declarePosition();
+ }
}
index++;
}
@@ -769,45 +849,55 @@ public abstract class TVList implements WALEntryValue {
case INT64:
case TIMESTAMP:
while (index < rows && builder.getPositionCount() < maxNumberOfPointsInPage) {
- long time = getTime(index);
- if (!isNullValue(getValueIndex(index))
- && !isPointDeleted(time, deletionList, deleteCursor)
- && (index == rows - 1 || time != getTime(index + 1))) {
- builder.getTimeColumnBuilder().writeLong(time);
- builder.getColumnBuilder(0).writeLong(getLong(index));
- builder.declarePosition();
+ long time = getTime(getScanOrderIndex(index));
+ if (!isNullValue(getValueIndex(getScanOrderIndex(index)))
+ && !isPointDeleted(time, deletionList, deleteCursor, scanOrder)
+ && isLatestPoint(index, time)
+ && isTimeSatisfied(time)) {
+ long aLong = getLong(getScanOrderIndex(index));
+ if (pushDownFilter == null || pushDownFilter.satisfyLong(time, aLong)) {
+ builder.getTimeColumnBuilder().writeLong(time);
+ builder.getColumnBuilder(0).writeLong(aLong);
+ builder.declarePosition();
+ }
}
index++;
}
break;
case FLOAT:
while (index < rows && builder.getPositionCount() < maxNumberOfPointsInPage) {
- long time = getTime(index);
- if (!isNullValue(getValueIndex(index))
- && !isPointDeleted(time, deletionList, deleteCursor)
- && (index == rows - 1 || time != getTime(index + 1))) {
- builder.getTimeColumnBuilder().writeLong(time);
- builder
- .getColumnBuilder(0)
- .writeFloat(
- roundValueWithGivenPrecision(getFloat(index), floatPrecision, encoding));
- builder.declarePosition();
+ long time = getTime(getScanOrderIndex(index));
+ if (!isNullValue(getValueIndex(getScanOrderIndex(index)))
+ && !isPointDeleted(time, deletionList, deleteCursor, scanOrder)
+ && isLatestPoint(index, time)
+ && isTimeSatisfied(time)) {
+ float aFloat =
+ roundValueWithGivenPrecision(
+ getFloat(getScanOrderIndex(index)), floatPrecision, encoding);
+ if (pushDownFilter == null || pushDownFilter.satisfyFloat(time, aFloat)) {
+ builder.getTimeColumnBuilder().writeLong(time);
+ builder.getColumnBuilder(0).writeFloat(aFloat);
+ builder.declarePosition();
+ }
}
index++;
}
break;
case DOUBLE:
while (index < rows && builder.getPositionCount() < maxNumberOfPointsInPage) {
- long time = getTime(index);
- if (!isNullValue(getValueIndex(index))
- && !isPointDeleted(time, deletionList, deleteCursor)
- && (index == rows - 1 || time != getTime(index + 1))) {
- builder.getTimeColumnBuilder().writeLong(time);
- builder
- .getColumnBuilder(0)
- .writeDouble(
- roundValueWithGivenPrecision(getDouble(index), floatPrecision, encoding));
- builder.declarePosition();
+ long time = getTime(getScanOrderIndex(index));
+ if (!isNullValue(getValueIndex(getScanOrderIndex(index)))
+ && !isPointDeleted(time, deletionList, deleteCursor, scanOrder)
+ && isLatestPoint(index, time)
+ && isTimeSatisfied(time)) {
+ double aDouble =
+ roundValueWithGivenPrecision(
+ getDouble(getScanOrderIndex(index)), floatPrecision, encoding);
+ if (pushDownFilter == null || pushDownFilter.satisfyDouble(time, aDouble)) {
+ builder.getTimeColumnBuilder().writeLong(time);
+ builder.getColumnBuilder(0).writeDouble(aDouble);
+ builder.declarePosition();
+ }
}
index++;
}
@@ -816,13 +906,17 @@ public abstract class TVList implements WALEntryValue {
case BLOB:
case STRING:
while (index < rows && builder.getPositionCount() < maxNumberOfPointsInPage) {
- long time = getTime(index);
- if (!isNullValue(getValueIndex(index))
- && !isPointDeleted(time, deletionList, deleteCursor)
- && (index == rows - 1 || time != getTime(index + 1))) {
- builder.getTimeColumnBuilder().writeLong(time);
- builder.getColumnBuilder(0).writeBinary(getBinary(index));
- builder.declarePosition();
+ long time = getTime(getScanOrderIndex(index));
+ if (!isNullValue(getValueIndex(getScanOrderIndex(index)))
+ && !isPointDeleted(time, deletionList, deleteCursor, scanOrder)
+ && isLatestPoint(index, time)
+ && isTimeSatisfied(time)) {
+ Binary binary = getBinary(getScanOrderIndex(index));
+ if (pushDownFilter == null || pushDownFilter.satisfyBinary(time, binary)) {
+ builder.getTimeColumnBuilder().writeLong(time);
+ builder.getColumnBuilder(0).writeBinary(binary);
+ builder.declarePosition();
+ }
}
index++;
}
@@ -831,11 +925,26 @@ public abstract class TVList implements WALEntryValue {
throw new UnSupportedDataTypeException(
String.format("Data type %s is not supported.", dataType));
}
- TsBlock tsBlock = builder.build();
- tsBlocks.add(tsBlock);
+ // There is no need to process pushDownFilter here because it has been applied when
+ // constructing the tsBlock
+ TsBlock tsBlock = paginationController.applyTsBlock(builder.build());
+ addTsBlock(tsBlock);
return tsBlock;
}
+ protected boolean isLatestPoint(int rowIndex, long currentTime) {
+ if (scanOrder.isAscending()) {
+ return rowIndex == rows - 1 || currentTime != getTime(getScanOrderIndex(rowIndex + 1));
+ } else {
+ return rowIndex == 0 || currentTime != getTime(getScanOrderIndex(rowIndex - 1));
+ }
+ }
+
+ // When traversing in desc order, the index needs to be converted
+ public int getScanOrderIndex(int rowIndex) {
+ return scanOrder.isAscending() ? rowIndex : rowCount - 1 - rowIndex;
+ }
+
@Override
public void encodeBatch(IChunkWriter chunkWriter, BatchEncodeInfo encodeInfo, long[] times) {
TSDataType dataType = getDataType();
@@ -906,11 +1015,6 @@ public abstract class TVList implements WALEntryValue {
return 0;
}
- @Override
- public void close() throws IOException {
- tsBlocks.clear();
- }
-
public void next() {
index++;
probeNext = false;
@@ -924,7 +1028,7 @@ public abstract class TVList implements WALEntryValue {
if (!hasCurrent()) {
return Long.MIN_VALUE;
}
- return getTime(index);
+ return getTime(getScanOrderIndex(index));
}
public int getIndex() {
diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/memtable/AlignedTVListIteratorTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/memtable/AlignedTVListIteratorTest.java
new file mode 100644
index 00000000000..6e3e21ff904
--- /dev/null
+++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/memtable/AlignedTVListIteratorTest.java
@@ -0,0 +1,807 @@
+/*
+ * 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.storageengine.dataregion.memtable;
+
+import org.apache.iotdb.commons.concurrent.IoTDBThreadPoolFactory;
+import org.apache.iotdb.db.queryengine.common.FragmentInstanceId;
+import org.apache.iotdb.db.queryengine.common.PlanFragmentId;
+import org.apache.iotdb.db.queryengine.execution.fragment.FragmentInstanceContext;
+import org.apache.iotdb.db.queryengine.execution.fragment.FragmentInstanceStateMachine;
+import org.apache.iotdb.db.queryengine.plan.statement.component.Ordering;
+import org.apache.iotdb.db.utils.datastructure.AlignedTVList;
+import org.apache.iotdb.db.utils.datastructure.MemPointIterator;
+import org.apache.iotdb.db.utils.datastructure.TVList;
+
+import org.apache.tsfile.enums.TSDataType;
+import org.apache.tsfile.file.metadata.enums.CompressionType;
+import org.apache.tsfile.file.metadata.enums.TSEncoding;
+import org.apache.tsfile.file.metadata.statistics.Statistics;
+import org.apache.tsfile.read.TimeValuePair;
+import org.apache.tsfile.read.common.TimeRange;
+import org.apache.tsfile.read.common.block.TsBlock;
+import org.apache.tsfile.read.filter.basic.Filter;
+import org.apache.tsfile.read.filter.operator.LongFilterOperators;
+import org.apache.tsfile.read.filter.operator.TimeFilterOperators;
+import org.apache.tsfile.read.reader.series.PaginationController;
+import org.apache.tsfile.write.schema.IMeasurementSchema;
+import org.apache.tsfile.write.schema.VectorMeasurementSchema;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+
+import static org.apache.iotdb.commons.path.AlignedPath.VECTOR_PLACEHOLDER;
+import static org.apache.iotdb.db.queryengine.execution.fragment.FragmentInstanceContext.createFragmentInstanceContext;
+
+public class AlignedTVListIteratorTest {
+ private static FragmentInstanceId instanceId;
+ private static ExecutorService instanceNotificationExecutor;
+ private static FragmentInstanceStateMachine stateMachine;
+ private static FragmentInstanceContext fragmentInstanceContext;
+
+ private static Map<TVList, Integer> largeSingleTvListMap;
+ private static Map<TVList, Integer> largeOrderedMultiTvListMap;
+ private static Map<TVList, Integer> largeMergeSortMultiTvListMap;
+
+ @BeforeClass
+ public static void setup() {
+ instanceId = new FragmentInstanceId(new PlanFragmentId("1", 0), "stub-instance");
+ instanceNotificationExecutor =
+ IoTDBThreadPoolFactory.newFixedThreadPool(1, "test-instance-notification");
+ stateMachine = new FragmentInstanceStateMachine(instanceId, instanceNotificationExecutor);
+ fragmentInstanceContext = createFragmentInstanceContext(instanceId, stateMachine);
+
+ largeSingleTvListMap =
+ buildAlignedSingleTvListMap(Collections.singletonList(new TimeRange(1, 400000)));
+ largeOrderedMultiTvListMap =
+ buildAlignedMultiTvListMap(
+ Arrays.asList(
+ new TimeRange(1, 100000),
+ new TimeRange(100001, 200000),
+ new TimeRange(200001, 300000),
+ new TimeRange(300001, 400000)));
+ largeMergeSortMultiTvListMap =
+ buildAlignedMultiTvListMap(
+ Arrays.asList(
+ new TimeRange(1, 20000),
+ new TimeRange(1, 100000),
+ new TimeRange(100001, 200000),
+ new TimeRange(200001, 300000),
+ new TimeRange(250001, 300000),
+ new TimeRange(250001, 300000),
+ new TimeRange(300001, 400000)));
+ }
+
+ @AfterClass
+ public static void tearDown() {
+ instanceNotificationExecutor.shutdown();
+ }
+
+ @Test
+ public void otherTest() throws IOException {
+ Map<TVList, Integer> tvListMap =
+ buildAlignedSingleTvListMap(Collections.singletonList(new TimeRange(1, 1)));
+ testAligned(
+ tvListMap,
+ Ordering.ASC,
+ null,
+ null,
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Collections.emptyList(),
+ Arrays.asList(Collections.emptyList(), Collections.emptyList(), Collections.emptyList()),
+ false,
+ 1);
+ testAligned(
+ tvListMap,
+ Ordering.DESC,
+ null,
+ null,
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Collections.emptyList(),
+ Arrays.asList(Collections.emptyList(), Collections.emptyList(), Collections.emptyList()),
+ false,
+ 1);
+
+ tvListMap = buildAlignedSingleTvListMap(Collections.singletonList(new TimeRange(1, 10000)));
+ AlignedTVList tvList = (AlignedTVList) tvListMap.keySet().iterator().next();
+ tvList.delete(1, 10, 0);
+ testAligned(
+ tvListMap,
+ Ordering.ASC,
+ new TimeFilterOperators.TimeBetweenAnd(110L, 200L),
+ new LongFilterOperators.ValueBetweenAnd(0, 100, 200),
+ new PaginationController(10, 10),
+ Collections.emptyList(),
+ Arrays.asList(
+ Collections.singletonList(new TimeRange(1, 10)),
+ Collections.emptyList(),
+ Collections.emptyList()),
+ false,
+ 10);
+ testAligned(
+ tvListMap,
+ Ordering.DESC,
+ new TimeFilterOperators.TimeBetweenAnd(110L, 200L),
+ new LongFilterOperators.ValueBetweenAnd(0, 100, 200),
+ new PaginationController(10, 10),
+ Collections.emptyList(),
+ Arrays.asList(
+ Collections.singletonList(new TimeRange(1, 10)),
+ Collections.emptyList(),
+ Collections.emptyList()),
+ false,
+ 10);
+ }
+
+ @Test
+ public void testAlignedWithDeletionsInTVList() throws IOException {
+ Map<TVList, Integer> tvListMap =
+ buildAlignedSingleTvListMap(Collections.singletonList(new TimeRange(1, 1000)));
+ AlignedTVList tvList = (AlignedTVList) tvListMap.keySet().iterator().next();
+
+ // deletion in one value column
+ tvListMap = buildAlignedSingleTvListMap(Collections.singletonList(new TimeRange(1, 1000)));
+ tvList = (AlignedTVList) tvListMap.keySet().iterator().next();
+ tvList.delete(1, 10, 0);
+ testAligned(
+ tvListMap,
+ Ordering.ASC,
+ null,
+ null,
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Collections.emptyList(),
+ Arrays.asList(
+ Collections.singletonList(new TimeRange(1, 10)),
+ Collections.emptyList(),
+ Collections.emptyList()),
+ false,
+ 1000);
+ testAligned(
+ tvListMap,
+ Ordering.DESC,
+ null,
+ null,
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Collections.emptyList(),
+ Arrays.asList(
+ Collections.singletonList(new TimeRange(1, 10)),
+ Collections.emptyList(),
+ Collections.emptyList()),
+ false,
+ 1000);
+
+ // deletion in all value column
+ tvListMap = buildAlignedSingleTvListMap(Collections.singletonList(new TimeRange(1, 1000)));
+ tvList = (AlignedTVList) tvListMap.keySet().iterator().next();
+ tvList.delete(1, 10);
+ testAligned(
+ tvListMap,
+ Ordering.ASC,
+ null,
+ null,
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Collections.singletonList(new TimeRange(1, 10)),
+ Arrays.asList(
+ Collections.singletonList(new TimeRange(1, 10)),
+ Collections.singletonList(new TimeRange(0, 10)),
+ Collections.singletonList(new TimeRange(0, 10))),
+ false,
+ 990);
+ testAligned(
+ tvListMap,
+ Ordering.DESC,
+ null,
+ null,
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Collections.singletonList(new TimeRange(1, 10)),
+ Arrays.asList(
+ Collections.singletonList(new TimeRange(1, 10)),
+ Collections.singletonList(new TimeRange(0, 10)),
+ Collections.singletonList(new TimeRange(0, 10))),
+ false,
+ 990);
+ }
+
+ @Test
+ public void testAlignedAsc() throws IOException {
+ testAligned(
+ Ordering.ASC,
+ null,
+ null,
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Collections.emptyList(),
+ Arrays.asList(Collections.emptyList(), Collections.emptyList(), Collections.emptyList()),
+ 400000);
+ testAligned(
+ Ordering.ASC,
+ null,
+ null,
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Arrays.asList(new TimeRange(10001, 20000), new TimeRange(50001, 60000)),
+ Arrays.asList(
+ Arrays.asList(new TimeRange(10001, 20000), new TimeRange(50001, 60000)),
+ Arrays.asList(new TimeRange(10001, 20000), new TimeRange(50001, 60000)),
+ Arrays.asList(new TimeRange(10001, 20000), new TimeRange(50001, 60000))),
+ 380000);
+ testAligned(
+ Ordering.ASC,
+ null,
+ null,
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Collections.singletonList(new TimeRange(0, 1000000)),
+ Arrays.asList(
+ Collections.singletonList(new TimeRange(0, 1000000)),
+ Collections.singletonList(new TimeRange(0, 1000000)),
+ Collections.singletonList(new TimeRange(0, 1000000))),
+ 0);
+ testAligned(
+ Ordering.ASC,
+ null,
+ null,
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Collections.emptyList(),
+ Arrays.asList(
+ Collections.singletonList(new TimeRange(0, 1000000)),
+ Collections.emptyList(),
+ Collections.emptyList()),
+ 400000);
+ testAligned(
+ Ordering.ASC,
+ null,
+ null,
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Collections.emptyList(),
+ Arrays.asList(
+ Arrays.asList(new TimeRange(10001, 20000), new TimeRange(100001, 120000)),
+ Collections.singletonList(new TimeRange(50001, 60000)),
+ Collections.emptyList()),
+ 400000);
+ }
+
+ @Test
+ public void testAlignedAscWithGlobalTimeFilter() throws IOException {
+ testAligned(
+ Ordering.ASC,
+ new TimeFilterOperators.TimeNotBetweenAnd(1L, 30000L),
+ null,
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Collections.emptyList(),
+ Arrays.asList(Collections.emptyList(), Collections.emptyList(), Collections.emptyList()),
+ 370000);
+ testAligned(
+ Ordering.ASC,
+ new TimeFilterOperators.TimeNotBetweenAnd(1001L, 30000L),
+ null,
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Collections.emptyList(),
+ Arrays.asList(Collections.emptyList(), Collections.emptyList(), Collections.emptyList()),
+ 371000);
+ testAligned(
+ Ordering.ASC,
+ new TimeFilterOperators.TimeNotBetweenAnd(1L, 3000000L),
+ null,
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Collections.emptyList(),
+ Arrays.asList(Collections.emptyList(), Collections.emptyList(), Collections.emptyList()),
+ 0);
+ }
+
+ @Test
+ public void testAlignedAscWithPushDownFilter() throws IOException {
+ testAligned(
+ Ordering.ASC,
+ null,
+ new LongFilterOperators.ValueEq(0, 10000),
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Collections.emptyList(),
+ Arrays.asList(Collections.emptyList(), Collections.emptyList(), Collections.emptyList()),
+ 1);
+ testAligned(
+ Ordering.ASC,
+ null,
+ new LongFilterOperators.ValueEq(0, -1),
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Collections.emptyList(),
+ Arrays.asList(Collections.emptyList(), Collections.emptyList(), Collections.emptyList()),
+ 0);
+ testAligned(
+ Ordering.ASC,
+ null,
+ new LongFilterOperators.ValueBetweenAnd(0, 10001, 20000),
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Collections.emptyList(),
+ Arrays.asList(Collections.emptyList(), Collections.emptyList(), Collections.emptyList()),
+ 10000);
+ }
+
+ @Test
+ public void testAlignedAscWithLimitAndOffset() throws IOException {
+ testAligned(
+ Ordering.ASC,
+ null,
+ null,
+ new PaginationController(10000, 0),
+ Collections.emptyList(),
+ Arrays.asList(Collections.emptyList(), Collections.emptyList(), Collections.emptyList()),
+ 10000);
+ testAligned(
+ Ordering.ASC,
+ null,
+ null,
+ new PaginationController(10000, 10),
+ Collections.emptyList(),
+ Arrays.asList(Collections.emptyList(), Collections.emptyList(), Collections.emptyList()),
+ 10000);
+ testAligned(
+ Ordering.ASC,
+ null,
+ null,
+ new PaginationController(10000, 1000000),
+ Collections.emptyList(),
+ Arrays.asList(Collections.emptyList(), Collections.emptyList(), Collections.emptyList()),
+ 0);
+ testAligned(
+ Ordering.ASC,
+ null,
+ null,
+ new PaginationController(100000, 0),
+ Collections.emptyList(),
+ Arrays.asList(Collections.emptyList(), Collections.emptyList(), Collections.emptyList()),
+ 100000);
+ testAligned(
+ Ordering.ASC,
+ null,
+ null,
+ new PaginationController(200000, 0),
+ Collections.emptyList(),
+ Arrays.asList(Collections.emptyList(), Collections.emptyList(), Collections.emptyList()),
+ 200000);
+ }
+
+ @Test
+ public void testAlignedDesc() throws IOException {
+ testAligned(
+ Ordering.DESC,
+ null,
+ null,
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Collections.emptyList(),
+ Arrays.asList(Collections.emptyList(), Collections.emptyList(), Collections.emptyList()),
+ 400000);
+ testAligned(
+ Ordering.DESC,
+ null,
+ null,
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Arrays.asList(new TimeRange(10001, 20000), new TimeRange(50001, 60000)),
+ Arrays.asList(
+ Arrays.asList(new TimeRange(10001, 20000), new TimeRange(50001, 60000)),
+ Arrays.asList(new TimeRange(10001, 20000), new TimeRange(50001, 60000)),
+ Arrays.asList(new TimeRange(10001, 20000), new TimeRange(50001, 60000))),
+ 380000);
+ testAligned(
+ Ordering.DESC,
+ null,
+ null,
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Collections.singletonList(new TimeRange(0, 1000000)),
+ Arrays.asList(
+ Collections.singletonList(new TimeRange(0, 1000000)),
+ Collections.singletonList(new TimeRange(0, 1000000)),
+ Collections.singletonList(new TimeRange(0, 1000000))),
+ 0);
+ testAligned(
+ Ordering.DESC,
+ null,
+ null,
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Collections.emptyList(),
+ Arrays.asList(
+ Collections.singletonList(new TimeRange(0, 1000000)),
+ Collections.emptyList(),
+ Collections.emptyList()),
+ 400000);
+ testAligned(
+ Ordering.DESC,
+ null,
+ null,
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Collections.emptyList(),
+ Arrays.asList(
+ Arrays.asList(new TimeRange(10001, 20000), new TimeRange(100001, 120000)),
+ Collections.singletonList(new TimeRange(50001, 60000)),
+ Collections.emptyList()),
+ 400000);
+ }
+
+ @Test
+ public void testAlignedDescWithGlobalTimeFilter() throws IOException {
+ testAligned(
+ Ordering.DESC,
+ new TimeFilterOperators.TimeNotBetweenAnd(1L, 30000L),
+ null,
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Collections.emptyList(),
+ Arrays.asList(Collections.emptyList(), Collections.emptyList(), Collections.emptyList()),
+ 370000);
+ testAligned(
+ Ordering.DESC,
+ new TimeFilterOperators.TimeNotBetweenAnd(1001L, 30000L),
+ null,
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Collections.emptyList(),
+ Arrays.asList(Collections.emptyList(), Collections.emptyList(), Collections.emptyList()),
+ 371000);
+ testAligned(
+ Ordering.DESC,
+ new TimeFilterOperators.TimeNotBetweenAnd(1L, 3000000L),
+ null,
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Collections.emptyList(),
+ Arrays.asList(Collections.emptyList(), Collections.emptyList(), Collections.emptyList()),
+ 0);
+ }
+
+ @Test
+ public void testAlignedDescWithPushDownFilter() throws IOException {
+ testAligned(
+ Ordering.DESC,
+ null,
+ new LongFilterOperators.ValueEq(0, 10000),
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Collections.emptyList(),
+ Arrays.asList(Collections.emptyList(), Collections.emptyList(), Collections.emptyList()),
+ 1);
+ testAligned(
+ Ordering.DESC,
+ null,
+ new LongFilterOperators.ValueEq(0, -1),
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Collections.emptyList(),
+ Arrays.asList(Collections.emptyList(), Collections.emptyList(), Collections.emptyList()),
+ 0);
+ testAligned(
+ Ordering.DESC,
+ null,
+ new LongFilterOperators.ValueBetweenAnd(0, 10001, 20000),
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Collections.emptyList(),
+ Arrays.asList(Collections.emptyList(), Collections.emptyList(), Collections.emptyList()),
+ 10000);
+ }
+
+ @Test
+ public void testAlignedDescWithLimitAndOffset() throws IOException {
+ testAligned(
+ Ordering.DESC,
+ null,
+ null,
+ new PaginationController(10000, 0),
+ Collections.emptyList(),
+ Arrays.asList(Collections.emptyList(), Collections.emptyList(), Collections.emptyList()),
+ 10000);
+ testAligned(
+ Ordering.DESC,
+ null,
+ null,
+ new PaginationController(10000, 10),
+ Collections.emptyList(),
+ Arrays.asList(Collections.emptyList(), Collections.emptyList(), Collections.emptyList()),
+ 10000);
+ testAligned(
+ Ordering.DESC,
+ null,
+ null,
+ new PaginationController(10000, 1000000),
+ Collections.emptyList(),
+ Arrays.asList(Collections.emptyList(), Collections.emptyList(), Collections.emptyList()),
+ 0);
+ testAligned(
+ Ordering.DESC,
+ null,
+ null,
+ new PaginationController(100000, 0),
+ Collections.emptyList(),
+ Arrays.asList(Collections.emptyList(), Collections.emptyList(), Collections.emptyList()),
+ 100000);
+ testAligned(
+ Ordering.DESC,
+ null,
+ null,
+ new PaginationController(200000, 0),
+ Collections.emptyList(),
+ Arrays.asList(Collections.emptyList(), Collections.emptyList(), Collections.emptyList()),
+ 200000);
+ }
+
+ private void testAligned(
+ Ordering scanOrder,
+ Filter globalTimeFilter,
+ Filter pushDownFilter,
+ PaginationController paginationController,
+ List<TimeRange> timeDeletions,
+ List<List<TimeRange>> valueDeletions,
+ int expectedCount)
+ throws IOException {
+
+ testAligned(
+ largeSingleTvListMap,
+ scanOrder,
+ globalTimeFilter,
+ pushDownFilter,
+ duplicatePaginationController(paginationController),
+ timeDeletions,
+ valueDeletions,
+ true,
+ expectedCount);
+ testAligned(
+ largeOrderedMultiTvListMap,
+ scanOrder,
+ globalTimeFilter,
+ pushDownFilter,
+ duplicatePaginationController(paginationController),
+ timeDeletions,
+ valueDeletions,
+ true,
+ expectedCount);
+ testAligned(
+ largeMergeSortMultiTvListMap,
+ scanOrder,
+ globalTimeFilter,
+ pushDownFilter,
+ duplicatePaginationController(paginationController),
+ timeDeletions,
+ valueDeletions,
+ true,
+ expectedCount);
+ }
+
+ private void testAligned(
+ Map<TVList, Integer> tvListMap,
+ Ordering scanOrder,
+ Filter globalTimeFilter,
+ Filter pushDownFilter,
+ PaginationController paginationController,
+ List<TimeRange> timeDeletions,
+ List<List<TimeRange>> valueDeletions,
+ boolean isDeletedAsModification,
+ int expectedCount)
+ throws IOException {
+ long endTime = tvListMap.keySet().stream().mapToLong(TVList::getMaxTime).max().getAsLong();
+ List<Integer> columnIdxList = Arrays.asList(0, 1, 2);
+ IMeasurementSchema measurementSchema = getMeasurementSchema();
+ AlignedReadOnlyMemChunk chunk =
+ new AlignedReadOnlyMemChunk(
+ fragmentInstanceContext,
+ columnIdxList,
+ measurementSchema,
+ tvListMap,
+ isDeletedAsModification
+ ? valueDeletions
+ : Arrays.asList(
+ Collections.emptyList(), Collections.emptyList(), Collections.emptyList()));
+
+ chunk.sortTvLists();
+ chunk.initChunkMetaFromTVListsWithFakeStatistics();
+
+ MemPointIterator memPointIterator = chunk.createMemPointIterator(scanOrder, globalTimeFilter);
+ memPointIterator.setLimitAndOffset(paginationController);
+ memPointIterator.setPushDownFilter(pushDownFilter);
+ List<Statistics<? extends Serializable>> pageStatisticsList = chunk.getTimeStatisticsList();
+ int count = 0;
+ long offset = paginationController.getCurOffset();
+ for (Statistics<? extends Serializable> statistics : pageStatisticsList) {
+ if (statistics.getStartTime() <= statistics.getEndTime()) {
+ memPointIterator.setCurrentPageTimeRange(
+ new TimeRange(statistics.getStartTime(), statistics.getEndTime()));
+ }
+ while (memPointIterator.hasNextBatch()) {
+ TsBlock tsBlock = memPointIterator.nextBatch();
+ for (int i = 0; i < tsBlock.getPositionCount(); i++) {
+ long expectedTimestamp;
+ if (scanOrder.isAscending()) {
+ count++;
+ expectedTimestamp = count + offset;
+ } else {
+ expectedTimestamp = endTime - count - offset;
+ count++;
+ }
+ long currentTimestamp = tsBlock.getTimeByIndex(i);
+ Long int64Value = tsBlock.getColumn(0).isNull(i) ? null : tsBlock.getColumn(0).getLong(i);
+ Boolean boolValue =
+ tsBlock.getColumn(1).isNull(i) ? null : tsBlock.getColumn(1).getBoolean(i);
+ boolean isLast = tsBlock.getColumn(2).getBoolean(i);
+ Assert.assertTrue(isLast);
+ List<TimeRange> int64Deletions = valueDeletions.get(0);
+ List<TimeRange> boolDeletions = valueDeletions.get(1);
+
+ if (int64Value != null) {
+ Assert.assertEquals(currentTimestamp, int64Value.longValue());
+ } else {
+ Assert.assertTrue(
+ int64Deletions.stream().anyMatch(range -> range.contains(currentTimestamp)));
+ }
+ if (boolValue != null) {
+ Assert.assertEquals(currentTimestamp % 2 == 0, boolValue.booleanValue());
+ } else {
+ Assert.assertTrue(
+ boolDeletions.stream().anyMatch(range -> range.contains(currentTimestamp)));
+ }
+ if (globalTimeFilter != null) {
+ Assert.assertTrue(globalTimeFilter.satisfyRow(currentTimestamp, null));
+ }
+ if (pushDownFilter != null) {
+ Assert.assertTrue(
+ pushDownFilter.satisfyRow(currentTimestamp, new Object[] {int64Value, boolValue}));
+ }
+ if (!timeDeletions.isEmpty()) {
+ timeDeletions.stream()
+ .map(deletion -> deletion.contains(currentTimestamp))
+ .forEach(Assert::assertFalse);
+ }
+ if (pushDownFilter == null
+ && globalTimeFilter == null
+ && paginationController == PaginationController.UNLIMITED_PAGINATION_CONTROLLER
+ && timeDeletions.isEmpty()) {
+ Assert.assertEquals(expectedTimestamp, currentTimestamp);
+ }
+ }
+ }
+ }
+ Assert.assertEquals(expectedCount, count);
+
+ if (pushDownFilter != null) {
+ return;
+ }
+
+ chunk.initChunkMetaFromTVListsWithFakeStatistics();
+ memPointIterator = chunk.createMemPointIterator(scanOrder, globalTimeFilter);
+ count = 0;
+ while (memPointIterator.hasNextTimeValuePair()) {
+ TimeValuePair timeValuePair = memPointIterator.nextTimeValuePair();
+ long currentTimestamp = timeValuePair.getTimestamp();
+ Long value = (Long) timeValuePair.getValues()[0];
+ Boolean boolValue = (Boolean) timeValuePair.getValues()[1];
+ boolean isLast = (boolean) timeValuePair.getValues()[2];
+ Assert.assertTrue(isLast);
+
+ if (value != null) {
+ Assert.assertEquals(currentTimestamp, value.longValue());
+ }
+ if (boolValue != null) {
+ Assert.assertEquals(currentTimestamp % 2 == 0, boolValue.booleanValue());
+ }
+ long expectedTimestamp;
+ if (scanOrder.isAscending()) {
+ count++;
+ expectedTimestamp = count + offset;
+ } else {
+ expectedTimestamp = endTime - count - offset;
+ count++;
+ }
+
+ if (globalTimeFilter != null) {
+ Assert.assertTrue(globalTimeFilter.satisfyRow(currentTimestamp, null));
+ }
+ if (!timeDeletions.isEmpty()) {
+ timeDeletions.stream()
+ .map(deletion -> deletion.contains(currentTimestamp))
+ .forEach(Assert::assertFalse);
+ }
+ if (globalTimeFilter == null
+ && paginationController == PaginationController.UNLIMITED_PAGINATION_CONTROLLER
+ && timeDeletions.isEmpty()) {
+ Assert.assertEquals(expectedTimestamp, currentTimestamp);
+ }
+ }
+ }
+
+ public VectorMeasurementSchema getMeasurementSchema() {
+ String[] array = new String[] {"s1", "s2", "s3"};
+ TSDataType[] types =
+ new TSDataType[] {TSDataType.INT64, TSDataType.BOOLEAN, TSDataType.BOOLEAN};
+ TSEncoding[] encodings =
+ new TSEncoding[] {TSEncoding.PLAIN, TSEncoding.PLAIN, TSEncoding.PLAIN};
+ return new VectorMeasurementSchema(
+ VECTOR_PLACEHOLDER, array, types, encodings, CompressionType.UNCOMPRESSED);
+ }
+
+ private static Map<TVList, Integer> buildAlignedSingleTvListMap(List<TimeRange> timeRanges) {
+ AlignedTVList alignedTVList =
+ AlignedTVList.newAlignedList(
+ Arrays.asList(TSDataType.INT64, TSDataType.BOOLEAN, TSDataType.BOOLEAN));
+ int rowCount = 0;
+ for (TimeRange timeRange : timeRanges) {
+ long start = timeRange.getMin();
+ long end = timeRange.getMax();
+ List<Long> timestamps = new ArrayList<>((int) (end - start + 1));
+ for (long timestamp = start; timestamp <= end; timestamp++) {
+ timestamps.add(timestamp);
+ }
+ Collections.shuffle(timestamps);
+ for (Long timestamp : timestamps) {
+ if (timestamp % 5000 == 1) {
+ // add some duplicated timestamp
+ for (int i = 0; i < 4; i++) {
+ alignedTVList.putAlignedValue(
+ timestamp, new Object[] {timestamp, timestamp % 2 == 0, false});
+ }
+ }
+ alignedTVList.putAlignedValue(
+ timestamp, new Object[] {timestamp, timestamp % 2 == 0, true});
+ rowCount++;
+ }
+ }
+ Map<TVList, Integer> tvListMap = new HashMap<>();
+ tvListMap.put(alignedTVList, rowCount);
+ return tvListMap;
+ }
+
+ private static Map<TVList, Integer> buildAlignedMultiTvListMap(List<TimeRange> timeRanges) {
+ Map<TVList, Integer> tvListMap = new LinkedHashMap<>();
+ for (int i = 0; i < timeRanges.size(); i++) {
+ TimeRange timeRange = timeRanges.get(i);
+ AlignedTVList alignedTVList =
+ AlignedTVList.newAlignedList(
+ Arrays.asList(TSDataType.INT64, TSDataType.BOOLEAN, TSDataType.BOOLEAN));
+ int rowCount = 0;
+ long start = timeRange.getMin();
+ long end = timeRange.getMax();
+ List<Long> timestamps = new ArrayList<>((int) (end - start + 1));
+ for (long timestamp = start; timestamp <= end; timestamp++) {
+ timestamps.add(timestamp);
+ }
+ Collections.shuffle(timestamps);
+ for (Long timestamp : timestamps) {
+ boolean isLast = true;
+ for (int j = i + 1; j < timeRanges.size(); j++) {
+ if (timeRanges.get(j).contains(timestamp)) {
+ isLast = false;
+ break;
+ }
+ }
+ alignedTVList.putAlignedValue(
+ timestamp, new Object[] {timestamp, timestamp % 2 == 0, isLast});
+ rowCount++;
+ }
+ tvListMap.put(alignedTVList, rowCount);
+ }
+ return tvListMap;
+ }
+
+ private PaginationController duplicatePaginationController(
+ PaginationController paginationController) {
+ return paginationController == PaginationController.UNLIMITED_PAGINATION_CONTROLLER
+ ? paginationController
+ : new PaginationController(
+ paginationController.getCurLimit(), paginationController.getCurOffset());
+ }
+}
diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/memtable/NonAlignedTVListIteratorTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/memtable/NonAlignedTVListIteratorTest.java
new file mode 100644
index 00000000000..62c801f4e34
--- /dev/null
+++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/memtable/NonAlignedTVListIteratorTest.java
@@ -0,0 +1,630 @@
+/*
+ * 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.storageengine.dataregion.memtable;
+
+import org.apache.iotdb.commons.concurrent.IoTDBThreadPoolFactory;
+import org.apache.iotdb.db.exception.query.QueryProcessException;
+import org.apache.iotdb.db.queryengine.common.FragmentInstanceId;
+import org.apache.iotdb.db.queryengine.common.PlanFragmentId;
+import org.apache.iotdb.db.queryengine.execution.fragment.FragmentInstanceContext;
+import org.apache.iotdb.db.queryengine.execution.fragment.FragmentInstanceStateMachine;
+import org.apache.iotdb.db.queryengine.plan.statement.component.Ordering;
+import org.apache.iotdb.db.utils.datastructure.MemPointIterator;
+import org.apache.iotdb.db.utils.datastructure.TVList;
+
+import org.apache.tsfile.enums.TSDataType;
+import org.apache.tsfile.file.metadata.enums.TSEncoding;
+import org.apache.tsfile.file.metadata.statistics.Statistics;
+import org.apache.tsfile.read.TimeValuePair;
+import org.apache.tsfile.read.common.TimeRange;
+import org.apache.tsfile.read.common.block.TsBlock;
+import org.apache.tsfile.read.filter.basic.Filter;
+import org.apache.tsfile.read.filter.operator.LongFilterOperators;
+import org.apache.tsfile.read.filter.operator.TimeFilterOperators;
+import org.apache.tsfile.read.reader.series.PaginationController;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+
+import static org.apache.iotdb.db.queryengine.execution.fragment.FragmentInstanceContext.createFragmentInstanceContext;
+
+public class NonAlignedTVListIteratorTest {
+
+ private static FragmentInstanceId instanceId;
+ private static ExecutorService instanceNotificationExecutor;
+ private static FragmentInstanceStateMachine stateMachine;
+ private static FragmentInstanceContext fragmentInstanceContext;
+
+ private static Map<TVList, Integer> largeSingleTvListMap;
+ private static Map<TVList, Integer> largeOrderedMultiTvListMap;
+ private static Map<TVList, Integer> largeMergeSortMultiTvListMap;
+
+ @BeforeClass
+ public static void setup() {
+ instanceId = new FragmentInstanceId(new PlanFragmentId("1", 0), "stub-instance");
+ instanceNotificationExecutor =
+ IoTDBThreadPoolFactory.newFixedThreadPool(1, "test-instance-notification");
+ stateMachine = new FragmentInstanceStateMachine(instanceId, instanceNotificationExecutor);
+ fragmentInstanceContext = createFragmentInstanceContext(instanceId, stateMachine);
+
+ largeSingleTvListMap =
+ buildNonAlignedSingleTvListMap(Collections.singletonList(new TimeRange(1, 400000)));
+ largeOrderedMultiTvListMap =
+ buildNonAlignedMultiTvListMap(
+ Arrays.asList(
+ new TimeRange(1, 100000),
+ new TimeRange(100001, 200000),
+ new TimeRange(200001, 300000),
+ new TimeRange(300001, 400000)));
+ largeMergeSortMultiTvListMap =
+ buildNonAlignedMultiTvListMap(
+ Arrays.asList(
+ new TimeRange(1, 20000),
+ new TimeRange(1, 100000),
+ new TimeRange(100001, 200000),
+ new TimeRange(200001, 300000),
+ new TimeRange(250001, 300000),
+ new TimeRange(300001, 400000)));
+ }
+
+ @AfterClass
+ public static void tearDown() {
+ instanceNotificationExecutor.shutdown();
+ }
+
+ @Test
+ public void otherTest() throws QueryProcessException, IOException {
+ Map<TVList, Integer> tvListMap =
+ buildNonAlignedSingleTvListMap(Collections.singletonList(new TimeRange(1, 1)));
+ testNonAligned(
+ tvListMap,
+ Ordering.ASC,
+ null,
+ null,
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Collections.emptyList(),
+ false,
+ 1);
+ testNonAligned(
+ tvListMap,
+ Ordering.DESC,
+ null,
+ null,
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Collections.emptyList(),
+ false,
+ 1);
+
+ tvListMap = buildNonAlignedSingleTvListMap(Collections.singletonList(new TimeRange(1, 10000)));
+ TVList tvList = tvListMap.keySet().iterator().next();
+ tvList.delete(1, 10);
+ testNonAligned(
+ tvListMap,
+ Ordering.ASC,
+ new TimeFilterOperators.TimeBetweenAnd(110L, 200L),
+ new LongFilterOperators.ValueBetweenAnd(0, 100, 200),
+ new PaginationController(10, 10),
+ Collections.singletonList(new TimeRange(1, 10)),
+ false,
+ 10);
+ testNonAligned(
+ tvListMap,
+ Ordering.DESC,
+ new TimeFilterOperators.TimeBetweenAnd(110L, 200L),
+ new LongFilterOperators.ValueBetweenAnd(0, 100, 200),
+ new PaginationController(10, 10),
+ Collections.singletonList(new TimeRange(1, 10)),
+ false,
+ 10);
+ }
+
+ @Test
+ public void testNonAlignedWithDeletionInTVList() throws QueryProcessException, IOException {
+ Map<TVList, Integer> tvListMap =
+ buildNonAlignedSingleTvListMap(Collections.singletonList(new TimeRange(1, 1000)));
+ TVList tvList = tvListMap.keySet().iterator().next();
+ tvList.delete(1, 1000);
+ testNonAligned(
+ tvListMap,
+ Ordering.ASC,
+ null,
+ null,
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Collections.singletonList(new TimeRange(1, 1000)),
+ false,
+ 0);
+ testNonAligned(
+ tvListMap,
+ Ordering.DESC,
+ null,
+ null,
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Collections.singletonList(new TimeRange(1, 1000)),
+ false,
+ 0);
+
+ tvListMap = buildNonAlignedSingleTvListMap(Collections.singletonList(new TimeRange(1, 1000)));
+ tvList = tvListMap.keySet().iterator().next();
+ tvList.delete(1, 10);
+ testNonAligned(
+ tvListMap,
+ Ordering.ASC,
+ null,
+ null,
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Collections.singletonList(new TimeRange(1, 10)),
+ false,
+ 990);
+ testNonAligned(
+ tvListMap,
+ Ordering.DESC,
+ null,
+ null,
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Collections.singletonList(new TimeRange(1, 10)),
+ false,
+ 990);
+ }
+
+ @Test
+ public void testNonAlignedAsc() throws IOException, QueryProcessException {
+ testNonAligned(
+ Ordering.ASC,
+ null,
+ null,
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Collections.emptyList(),
+ 400000);
+ testNonAligned(
+ Ordering.ASC,
+ null,
+ null,
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Arrays.asList(new TimeRange(10001, 20000), new TimeRange(50001, 60000)),
+ 380000);
+ testNonAligned(
+ Ordering.ASC,
+ null,
+ null,
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Collections.singletonList(new TimeRange(0, 1000000)),
+ 0);
+ }
+
+ @Test
+ public void testNonAlignedAscWithGlobalTimeFilter() throws IOException, QueryProcessException {
+ testNonAligned(
+ Ordering.ASC,
+ new TimeFilterOperators.TimeNotBetweenAnd(1L, 30000L),
+ null,
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Collections.emptyList(),
+ 370000);
+ testNonAligned(
+ Ordering.ASC,
+ new TimeFilterOperators.TimeNotBetweenAnd(1001L, 30000L),
+ null,
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Collections.emptyList(),
+ 371000);
+ testNonAligned(
+ Ordering.ASC,
+ new TimeFilterOperators.TimeNotBetweenAnd(1L, 3000000L),
+ null,
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Collections.emptyList(),
+ 0);
+ }
+
+ @Test
+ public void testNonAlignedAscWithPushDownFilter() throws QueryProcessException, IOException {
+ testNonAligned(
+ Ordering.ASC,
+ null,
+ new LongFilterOperators.ValueEq(0, 10000),
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Collections.emptyList(),
+ 1);
+ testNonAligned(
+ Ordering.ASC,
+ null,
+ new LongFilterOperators.ValueEq(0, -1),
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Collections.emptyList(),
+ 0);
+ testNonAligned(
+ Ordering.ASC,
+ null,
+ new LongFilterOperators.ValueBetweenAnd(0, 10001, 20000),
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Collections.emptyList(),
+ 10000);
+ }
+
+ @Test
+ public void testNonAlignedAscWithLimitAndOffset() throws IOException, QueryProcessException {
+ testNonAligned(
+ Ordering.ASC,
+ null,
+ null,
+ new PaginationController(10000, 0),
+ Collections.emptyList(),
+ 10000);
+ testNonAligned(
+ Ordering.ASC,
+ null,
+ null,
+ new PaginationController(10000, 10),
+ Collections.emptyList(),
+ 10000);
+ testNonAligned(
+ Ordering.ASC,
+ null,
+ null,
+ new PaginationController(10000, 1000000),
+ Collections.emptyList(),
+ 0);
+ testNonAligned(
+ Ordering.ASC,
+ null,
+ null,
+ new PaginationController(100000, 0),
+ Collections.emptyList(),
+ 100000);
+ testNonAligned(
+ Ordering.ASC,
+ null,
+ null,
+ new PaginationController(200000, 0),
+ Collections.emptyList(),
+ 200000);
+ }
+
+ @Test
+ public void testNonAlignedDesc() throws IOException, QueryProcessException {
+ testNonAligned(
+ Ordering.DESC,
+ null,
+ null,
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Collections.emptyList(),
+ 400000);
+ testNonAligned(
+ Ordering.DESC,
+ null,
+ null,
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Arrays.asList(new TimeRange(10001, 20000), new TimeRange(50001, 60000)),
+ 380000);
+ testNonAligned(
+ Ordering.DESC,
+ null,
+ null,
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Collections.singletonList(new TimeRange(0, 1000000)),
+ 0);
+ }
+
+ @Test
+ public void testNonAlignedDescWithGlobalTimeFilter() throws IOException, QueryProcessException {
+ testNonAligned(
+ Ordering.DESC,
+ new TimeFilterOperators.TimeNotBetweenAnd(1L, 30000L),
+ null,
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Collections.emptyList(),
+ 370000);
+ testNonAligned(
+ Ordering.DESC,
+ new TimeFilterOperators.TimeNotBetweenAnd(1001L, 30000L),
+ null,
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Collections.emptyList(),
+ 371000);
+ testNonAligned(
+ Ordering.DESC,
+ new TimeFilterOperators.TimeNotBetweenAnd(1L, 3000000L),
+ null,
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Collections.emptyList(),
+ 0);
+ }
+
+ @Test
+ public void testNonAlignedDescWithPushDownFilter() throws QueryProcessException, IOException {
+ testNonAligned(
+ Ordering.DESC,
+ null,
+ new LongFilterOperators.ValueEq(0, 10000),
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Collections.emptyList(),
+ 1);
+ testNonAligned(
+ Ordering.DESC,
+ null,
+ new LongFilterOperators.ValueEq(0, -1),
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Collections.emptyList(),
+ 0);
+ testNonAligned(
+ Ordering.DESC,
+ null,
+ new LongFilterOperators.ValueBetweenAnd(0, 10001, 20000),
+ PaginationController.UNLIMITED_PAGINATION_CONTROLLER,
+ Collections.emptyList(),
+ 10000);
+ }
+
+ @Test
+ public void testNonAlignedDescWithLimitAndOffset() throws IOException, QueryProcessException {
+ testNonAligned(
+ Ordering.DESC,
+ null,
+ null,
+ new PaginationController(10000, 0),
+ Collections.emptyList(),
+ 10000);
+ testNonAligned(
+ Ordering.DESC,
+ null,
+ null,
+ new PaginationController(10000, 10),
+ Collections.emptyList(),
+ 10000);
+ testNonAligned(
+ Ordering.DESC,
+ null,
+ null,
+ new PaginationController(10000, 1000000),
+ Collections.emptyList(),
+ 0);
+ testNonAligned(
+ Ordering.DESC,
+ null,
+ null,
+ new PaginationController(100000, 0),
+ Collections.emptyList(),
+ 100000);
+ testNonAligned(
+ Ordering.DESC,
+ null,
+ null,
+ new PaginationController(200000, 0),
+ Collections.emptyList(),
+ 200000);
+ }
+
+ private void testNonAligned(
+ Ordering scanOrder,
+ Filter globalTimeFilter,
+ Filter pushDownFilter,
+ PaginationController paginationController,
+ List<TimeRange> deletions,
+ int expectedCount)
+ throws QueryProcessException, IOException {
+ testNonAligned(
+ largeSingleTvListMap,
+ scanOrder,
+ globalTimeFilter,
+ pushDownFilter,
+ duplicatePaginationController(paginationController),
+ deletions,
+ true,
+ expectedCount);
+ testNonAligned(
+ largeOrderedMultiTvListMap,
+ scanOrder,
+ globalTimeFilter,
+ pushDownFilter,
+ duplicatePaginationController(paginationController),
+ deletions,
+ true,
+ expectedCount);
+ testNonAligned(
+ largeMergeSortMultiTvListMap,
+ scanOrder,
+ globalTimeFilter,
+ pushDownFilter,
+ duplicatePaginationController(paginationController),
+ deletions,
+ true,
+ expectedCount);
+ }
+
+ private PaginationController duplicatePaginationController(
+ PaginationController paginationController) {
+ return paginationController == PaginationController.UNLIMITED_PAGINATION_CONTROLLER
+ ? paginationController
+ : new PaginationController(
+ paginationController.getCurLimit(), paginationController.getCurOffset());
+ }
+
+ private void testNonAligned(
+ Map<TVList, Integer> tvListMap,
+ Ordering scanOrder,
+ Filter globalTimeFilter,
+ Filter pushDownFilter,
+ PaginationController paginationController,
+ List<TimeRange> deletions,
+ boolean isDeletedAsModification,
+ int expectedCount)
+ throws IOException, QueryProcessException {
+ long endTime = tvListMap.keySet().stream().mapToLong(TVList::getMaxTime).max().getAsLong();
+ ReadOnlyMemChunk chunk =
+ new ReadOnlyMemChunk(
+ fragmentInstanceContext,
+ "s1",
+ TSDataType.INT64,
+ TSEncoding.PLAIN,
+ tvListMap,
+ null,
+ isDeletedAsModification ? deletions : Collections.emptyList());
+ chunk.sortTvLists();
+ chunk.initChunkMetaFromTVListsWithFakeStatistics();
+
+ MemPointIterator memPointIterator = chunk.createMemPointIterator(scanOrder, globalTimeFilter);
+ memPointIterator.setLimitAndOffset(paginationController);
+ memPointIterator.setPushDownFilter(pushDownFilter);
+ List<Statistics<? extends Serializable>> pageStatisticsList = chunk.getPageStatisticsList();
+ int count = 0;
+ long offset = paginationController.getCurOffset();
+ for (Statistics<? extends Serializable> statistics : pageStatisticsList) {
+ memPointIterator.setCurrentPageTimeRange(
+ new TimeRange(statistics.getStartTime(), statistics.getEndTime()));
+ while (memPointIterator.hasNextBatch()) {
+ TsBlock tsBlock = memPointIterator.nextBatch();
+ for (int i = 0; i < tsBlock.getPositionCount(); i++) {
+ long expectedTimestamp;
+ if (scanOrder.isAscending()) {
+ count++;
+ expectedTimestamp = count + offset;
+ } else {
+ expectedTimestamp = endTime - count - offset;
+ count++;
+ }
+ long currentTimestamp = tsBlock.getTimeByIndex(i);
+ long value = tsBlock.getColumn(0).getLong(i);
+ Assert.assertEquals(currentTimestamp, value);
+ if (globalTimeFilter != null) {
+ Assert.assertTrue(globalTimeFilter.satisfyRow(currentTimestamp, null));
+ }
+ if (pushDownFilter != null) {
+ Assert.assertTrue(pushDownFilter.satisfyLong(currentTimestamp, value));
+ }
+ if (!deletions.isEmpty()) {
+ deletions.stream()
+ .map(deletion -> deletion.contains(currentTimestamp))
+ .forEach(Assert::assertFalse);
+ }
+ if (pushDownFilter == null
+ && globalTimeFilter == null
+ && paginationController == PaginationController.UNLIMITED_PAGINATION_CONTROLLER
+ && deletions.isEmpty()) {
+ Assert.assertEquals(expectedTimestamp, currentTimestamp);
+ }
+ }
+ }
+ }
+ Assert.assertEquals(expectedCount, count);
+
+ if (pushDownFilter != null) {
+ return;
+ }
+
+ chunk.initChunkMetaFromTVListsWithFakeStatistics();
+ memPointIterator = chunk.createMemPointIterator(scanOrder, globalTimeFilter);
+ count = 0;
+ while (memPointIterator.hasNextTimeValuePair()) {
+ TimeValuePair timeValuePair = memPointIterator.nextTimeValuePair();
+ long currentTimestamp = timeValuePair.getTimestamp();
+ if (currentTimestamp == 60001) {
+ System.out.println();
+ }
+ long value = timeValuePair.getValue().getLong();
+ Assert.assertEquals(currentTimestamp, value);
+ long expectedTimestamp;
+ if (scanOrder.isAscending()) {
+ count++;
+ expectedTimestamp = count + offset;
+ } else {
+ expectedTimestamp = endTime - count - offset;
+ count++;
+ }
+
+ if (globalTimeFilter != null) {
+ Assert.assertTrue(globalTimeFilter.satisfyRow(currentTimestamp, null));
+ }
+ if (!deletions.isEmpty()) {
+ try {
+ deletions.stream()
+ .map(deletion -> deletion.contains(currentTimestamp))
+ .forEach(Assert::assertFalse);
+ } catch (AssertionError e) {
+ System.out.println();
+ }
+ }
+ if (globalTimeFilter == null
+ && paginationController == PaginationController.UNLIMITED_PAGINATION_CONTROLLER
+ && deletions.isEmpty()) {
+ Assert.assertEquals(expectedTimestamp, currentTimestamp);
+ }
+ }
+ }
+
+ private static Map<TVList, Integer> buildNonAlignedSingleTvListMap(List<TimeRange> timeRanges) {
+ TVList tvList = TVList.newList(TSDataType.INT64);
+ int rowCount = 0;
+ for (TimeRange timeRange : timeRanges) {
+ long start = timeRange.getMin();
+ long end = timeRange.getMax();
+ List<Long> timestamps = new ArrayList<>((int) (end - start + 1));
+ for (long timestamp = start; timestamp <= end; timestamp++) {
+ timestamps.add(timestamp);
+ }
+ Collections.shuffle(timestamps);
+ for (Long timestamp : timestamps) {
+ if (timestamp % 5000 == 1) {
+ // add some duplicated timestamp
+ for (int i = 0; i < 4; i++) {
+ tvList.putLong(timestamp, timestamp - i);
+ }
+ }
+ tvList.putLong(timestamp, timestamp);
+ rowCount++;
+ }
+ }
+ Map<TVList, Integer> tvListMap = new HashMap<>();
+ tvListMap.put(tvList, rowCount);
+ return tvListMap;
+ }
+
+ private static Map<TVList, Integer> buildNonAlignedMultiTvListMap(List<TimeRange> timeRanges) {
+ Map<TVList, Integer> tvListMap = new LinkedHashMap<>();
+ for (TimeRange timeRange : timeRanges) {
+ TVList tvList = TVList.newList(TSDataType.INT64);
+ int rowCount = 0;
+ long start = timeRange.getMin();
+ long end = timeRange.getMax();
+ List<Long> timestamps = new ArrayList<>((int) (end - start + 1));
+ for (long timestamp = start; timestamp <= end; timestamp++) {
+ timestamps.add(timestamp);
+ }
+ Collections.shuffle(timestamps);
+ for (Long timestamp : timestamps) {
+ tvList.putLong(timestamp, timestamp);
+ rowCount++;
+ }
+ tvListMap.put(tvList, rowCount);
+ }
+ return tvListMap;
+ }
+}
diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/read/reader/chunk/MemAlignedChunkLoaderTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/read/reader/chunk/MemAlignedChunkLoaderTest.java
index feea095d389..87c6e28ea55 100644
--- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/read/reader/chunk/MemAlignedChunkLoaderTest.java
+++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/read/reader/chunk/MemAlignedChunkLoaderTest.java
@@ -115,6 +115,7 @@ public class MemAlignedChunkLoaderTest {
alignedTvListMap.keySet().stream().map(x -> (AlignedTVList) x).collect(Collectors.toList());
MemPointIterator timeValuePairIterator =
MemPointIteratorFactory.create(dataTypes, null, alignedTvLists, maxNumberOfPointsInPage);
+ timeValuePairIterator.setStreamingQueryMemChunk(false);
timeValuePairIterator.nextBatch();
Mockito.when(chunk.getMemPointIterator()).thenReturn(timeValuePairIterator);
diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/read/reader/chunk/MemChunkLoaderTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/read/reader/chunk/MemChunkLoaderTest.java
index 9ea7da676f9..e852c656253 100644
--- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/read/reader/chunk/MemChunkLoaderTest.java
+++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/read/reader/chunk/MemChunkLoaderTest.java
@@ -70,6 +70,7 @@ public class MemChunkLoaderTest {
List<TVList> booleanTvLists = new ArrayList<>(booleanTvListMap.keySet());
MemPointIterator timeValuePairIterator =
MemPointIteratorFactory.create(TSDataType.BOOLEAN, booleanTvLists, maxNumberOfPointsInPage);
+ timeValuePairIterator.setStreamingQueryMemChunk(false);
timeValuePairIterator.nextBatch();
Mockito.when(chunk.getMemPointIterator()).thenReturn(timeValuePairIterator);
@@ -148,6 +149,7 @@ public class MemChunkLoaderTest {
List<TVList> int32TvLists = new ArrayList<>(int32TvListMap.keySet());
MemPointIterator timeValuePairIterator =
MemPointIteratorFactory.create(TSDataType.INT32, int32TvLists, maxNumberOfPointsInPage);
+ timeValuePairIterator.setStreamingQueryMemChunk(false);
timeValuePairIterator.nextBatch();
Mockito.when(chunk.getMemPointIterator()).thenReturn(timeValuePairIterator);
@@ -227,6 +229,7 @@ public class MemChunkLoaderTest {
List<TVList> int64TvLists = new ArrayList<>(int64TvListMap.keySet());
MemPointIterator timeValuePairIterator =
MemPointIteratorFactory.create(TSDataType.INT64, int64TvLists, maxNumberOfPointsInPage);
+ timeValuePairIterator.setStreamingQueryMemChunk(false);
timeValuePairIterator.nextBatch();
Mockito.when(chunk.getMemPointIterator()).thenReturn(timeValuePairIterator);
@@ -306,6 +309,7 @@ public class MemChunkLoaderTest {
List<TVList> floatTvLists = new ArrayList<>(floatTvListMap.keySet());
MemPointIterator timeValuePairIterator =
MemPointIteratorFactory.create(TSDataType.FLOAT, floatTvLists, maxNumberOfPointsInPage);
+ timeValuePairIterator.setStreamingQueryMemChunk(false);
timeValuePairIterator.nextBatch();
Mockito.when(chunk.getMemPointIterator()).thenReturn(timeValuePairIterator);
@@ -385,6 +389,7 @@ public class MemChunkLoaderTest {
List<TVList> doubleTvLists = new ArrayList<>(doubleTvListMap.keySet());
MemPointIterator timeValuePairIterator =
MemPointIteratorFactory.create(TSDataType.DOUBLE, doubleTvLists, maxNumberOfPointsInPage);
+ timeValuePairIterator.setStreamingQueryMemChunk(false);
timeValuePairIterator.nextBatch();
Mockito.when(chunk.getMemPointIterator()).thenReturn(timeValuePairIterator);
@@ -464,6 +469,7 @@ public class MemChunkLoaderTest {
List<TVList> textTvLists = new ArrayList<>(textTvListMap.keySet());
MemPointIterator timeValuePairIterator =
MemPointIteratorFactory.create(TSDataType.TEXT, textTvLists, maxNumberOfPointsInPage);
+ timeValuePairIterator.setStreamingQueryMemChunk(false);
timeValuePairIterator.nextBatch();
Mockito.when(chunk.getMemPointIterator()).thenReturn(timeValuePairIterator);