This is an automated email from the ASF dual-hosted git repository. jackietien pushed a commit to branch MPPIT in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 03dbdda41f4f7de8e087903fc9a72f3568f5057d Author: JackieTien97 <[email protected]> AuthorDate: Tue Jun 7 20:24:48 2022 +0800 Add IT for raw query --- .../org/apache/iotdb/it/env/ClusterEnvBase.java | 1 + .../org/apache/iotdb/it/env/ClusterEnvConfig.java | 29 + .../apache/iotdb/itbase/constant/TestConstant.java | 143 +++++ .../org/apache/iotdb/itbase/env/BaseConfig.java | 24 + .../iotdb/db/it/aligned/AlignedWriteUtil.java | 147 +++++ .../iotdb/db/it/aligned/IoTDBLastQuery2IT.java | 58 ++ .../iotdb/db/it/aligned/IoTDBLastQueryIT.java | 327 ++++++++++ .../aligned/IoTDBLastQueryWithoutLastCache2IT.java | 60 ++ .../aligned/IoTDBLastQueryWithoutLastCacheIT.java | 330 ++++++++++ .../aligned/IoTDBRawQueryWithValueFilter2IT.java | 58 ++ .../it/aligned/IoTDBRawQueryWithValueFilterIT.java | 679 +++++++++++++++++++++ .../IoTDBRawQueryWithoutValueFilter2IT.java | 58 ++ .../IoTDBRawQueryWithoutValueFilter3IT.java | 58 ++ .../aligned/IoTDBRawQueryWithoutValueFilterIT.java | 581 ++++++++++++++++++ .../iotdb/db/it/env/StandaloneEnvConfig.java | 51 ++ .../query/reader/chunk/MemAlignedPageReader.java | 52 +- 16 files changed, 2632 insertions(+), 24 deletions(-) diff --git a/integration-test/src/main/java/org/apache/iotdb/it/env/ClusterEnvBase.java b/integration-test/src/main/java/org/apache/iotdb/it/env/ClusterEnvBase.java index 1fd072d760..8b1803617b 100644 --- a/integration-test/src/main/java/org/apache/iotdb/it/env/ClusterEnvBase.java +++ b/integration-test/src/main/java/org/apache/iotdb/it/env/ClusterEnvBase.java @@ -137,6 +137,7 @@ public abstract class ClusterEnvBase implements BaseEnv { ResultSet resultSet = statement.getResultSet(); if (resultSet.next()) { statement.execute("DELETE STORAGE GROUP root.*"); + logger.info("init done"); break; } } diff --git a/integration-test/src/main/java/org/apache/iotdb/it/env/ClusterEnvConfig.java b/integration-test/src/main/java/org/apache/iotdb/it/env/ClusterEnvConfig.java index 5a818ca25c..f0a3e2d957 100644 --- a/integration-test/src/main/java/org/apache/iotdb/it/env/ClusterEnvConfig.java +++ b/integration-test/src/main/java/org/apache/iotdb/it/env/ClusterEnvConfig.java @@ -31,78 +31,93 @@ public class ClusterEnvConfig implements BaseConfig { clusterProperties = new Properties(); } + @Override public void clearAllProperties() { engineProperties.clear(); clusterProperties.clear(); } + @Override public Properties getEngineProperties() { return this.engineProperties; } + @Override public Properties getClusterProperties() { return this.clusterProperties; } + @Override public BaseConfig setMaxNumberOfPointsInPage(int maxNumberOfPointsInPage) { engineProperties.setProperty( "max_number_of_points_in_page", String.valueOf(maxNumberOfPointsInPage)); return this; } + @Override public BaseConfig setPageSizeInByte(int pageSizeInByte) { engineProperties.setProperty("page_size_in_byte", String.valueOf(pageSizeInByte)); return this; } + @Override public BaseConfig setGroupSizeInByte(int groupSizeInByte) { engineProperties.setProperty("group_size_in_byte", String.valueOf(groupSizeInByte)); return this; } + @Override public BaseConfig setMemtableSizeThreshold(long memtableSizeThreshold) { engineProperties.setProperty("memtable_size_threshold", String.valueOf(memtableSizeThreshold)); return this; } + @Override public BaseConfig setDataRegionNum(int dataRegionNum) { engineProperties.setProperty("data_region_num", String.valueOf(dataRegionNum)); return this; } + @Override public BaseConfig setPartitionInterval(long partitionInterval) { engineProperties.setProperty("partition_interval", String.valueOf(partitionInterval)); return this; } + @Override public BaseConfig setCompressor(String compressor) { engineProperties.setProperty("compressor", compressor); return this; } + @Override public BaseConfig setMaxQueryDeduplicatedPathNum(int maxQueryDeduplicatedPathNum) { engineProperties.setProperty( "max_deduplicated_path_num", String.valueOf(maxQueryDeduplicatedPathNum)); return this; } + @Override public BaseConfig setRpcThriftCompressionEnable(boolean rpcThriftCompressionEnable) { engineProperties.setProperty( "rpc_thrift_compression_enable", String.valueOf(rpcThriftCompressionEnable)); return this; } + @Override public BaseConfig setRpcAdvancedCompressionEnable(boolean rpcAdvancedCompressionEnable) { engineProperties.setProperty( "rpc_advanced_compression_enable", String.valueOf(rpcAdvancedCompressionEnable)); return this; } + @Override public BaseConfig setEnablePartition(boolean enablePartition) { engineProperties.setProperty("enable_partition", String.valueOf(enablePartition)); return this; } + @Override public BaseConfig setUdfCollectorMemoryBudgetInMB(float udfCollectorMemoryBudgetInMB) { // udf_memory_budget_in_mb // udf_reader_transformer_collector_memory_proportion @@ -111,49 +126,63 @@ public class ClusterEnvConfig implements BaseConfig { return this; } + @Override public BaseConfig setUdfTransformerMemoryBudgetInMB(float udfTransformerMemoryBudgetInMB) { engineProperties.setProperty( "udf_memory_budget_in_mb", String.valueOf(udfTransformerMemoryBudgetInMB * 3)); return this; } + @Override public BaseConfig setUdfReaderMemoryBudgetInMB(float udfReaderMemoryBudgetInMB) { engineProperties.setProperty( "udf_memory_budget_in_mb", String.valueOf(udfReaderMemoryBudgetInMB * 3)); return this; } + @Override public BaseConfig setEnableSeqSpaceCompaction(boolean enableSeqSpaceCompaction) { engineProperties.setProperty( "enable_seq_space_compaction", String.valueOf(enableSeqSpaceCompaction)); return this; } + @Override public BaseConfig setEnableUnseqSpaceCompaction(boolean enableUnseqSpaceCompaction) { engineProperties.setProperty( "enable_unseq_space_compaction", String.valueOf(enableUnseqSpaceCompaction)); return this; } + @Override public BaseConfig setEnableCrossSpaceCompaction(boolean enableCrossSpaceCompaction) { engineProperties.setProperty( "enable_cross_space_compaction", String.valueOf(enableCrossSpaceCompaction)); return this; } + @Override public BaseConfig setEnableIDTable(boolean isEnableIDTable) { engineProperties.setProperty("enable_id_table", String.valueOf(isEnableIDTable)); return this; } + @Override public BaseConfig setDeviceIDTransformationMethod(String deviceIDTransformationMethod) { engineProperties.setProperty("device_id_transformation_method", deviceIDTransformationMethod); return this; } + @Override public BaseConfig setAutoCreateSchemaEnabled(boolean enableAutoCreateSchema) { clusterProperties.setProperty( "enable_auto_create_schema", String.valueOf(enableAutoCreateSchema)); return this; } + + @Override + public BaseConfig setEnableLastCache(boolean lastCacheEnable) { + engineProperties.setProperty("enable_last_cache", String.valueOf(lastCacheEnable)); + return this; + } } diff --git a/integration-test/src/main/java/org/apache/iotdb/itbase/constant/TestConstant.java b/integration-test/src/main/java/org/apache/iotdb/itbase/constant/TestConstant.java new file mode 100644 index 0000000000..29361299ad --- /dev/null +++ b/integration-test/src/main/java/org/apache/iotdb/itbase/constant/TestConstant.java @@ -0,0 +1,143 @@ +/* + * 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.itbase.constant; + +import org.apache.iotdb.tsfile.utils.FilePathUtils; +import org.apache.iotdb.tsfile.write.record.TSRecord; +import org.apache.iotdb.tsfile.write.record.datapoint.DataPoint; + +import java.io.File; + +public class TestConstant { + + public static final String BASE_OUTPUT_PATH = "target".concat(File.separator); + public static final String OUTPUT_DATA_DIR = + BASE_OUTPUT_PATH.concat("data").concat(File.separator); + public static final String PARTIAL_PATH_STRING = + "%s" + File.separator + "%d" + File.separator + "%d" + File.separator; + public static final String TEST_TSFILE_PATH = + BASE_OUTPUT_PATH + "testTsFile".concat(File.separator) + PARTIAL_PATH_STRING; + + public static final String d0 = "root.vehicle.d0"; + public static final String s0 = "s0"; + public static final String s1 = "s1"; + public static final String s2 = "s2"; + public static final String s3 = "s3"; + public static final String s4 = "s4"; + public static final String s5 = "s5"; + public static final String d1 = "root.vehicle.d1"; + public static final String TIMESTAMP_STR = "Time"; + public static boolean testFlag = true; + public static String[] stringValue = new String[] {"A", "B", "C", "D", "E"}; + public static String[] booleanValue = new String[] {"true", "false"}; + public static final String TIMESEIRES_STR = "timeseries"; + public static final String VALUE_STR = "value"; + public static final String DATA_TYPE_STR = "dataType"; + + public static String[] createSql = + new String[] { + "SET STORAGE GROUP TO root.vehicle", + "CREATE TIMESERIES root.vehicle.d0.s0 WITH DATATYPE=INT32, ENCODING=RLE", + "CREATE TIMESERIES root.vehicle.d0.s1 WITH DATATYPE=INT64, ENCODING=RLE", + "CREATE TIMESERIES root.vehicle.d0.s2 WITH DATATYPE=FLOAT, ENCODING=RLE", + "CREATE TIMESERIES root.vehicle.d0.s3 WITH DATATYPE=TEXT, ENCODING=PLAIN", + "CREATE TIMESERIES root.vehicle.d0.s4 WITH DATATYPE=BOOLEAN, ENCODING=PLAIN", + "CREATE TIMESERIES root.vehicle.d0.s5 WITH DATATYPE=DOUBLE, ENCODING=RLE", + "CREATE TIMESERIES root.vehicle.d1.s0 WITH DATATYPE=INT32, ENCODING=RLE", + "CREATE TIMESERIES root.vehicle.d1.s1 WITH DATATYPE=INT64, ENCODING=RLE", + }; + + public static String insertTemplate = "insert into %s(timestamp%s) values(%d%s)"; + + public static String firstValue(String path) { + return String.format("first_value(%s)", path); + } + + public static String lastValue(String path) { + return String.format("last_value(%s)", path); + } + + public static String sum(String path) { + return String.format("sum(%s)", path); + } + + public static String avg(String path) { + return String.format("avg(%s)", path); + } + + public static String count(String path) { + return String.format("count(%s)", path); + } + + public static String maxTime(String path) { + return String.format("max_time(%s)", path); + } + + public static String minTime(String path) { + return String.format("min_time(%s)", path); + } + + public static String maxValue(String path) { + return String.format("max_value(%s)", path); + } + + public static String extreme(String path) { + return String.format("extreme(%s)", path); + } + + public static String minValue(String path) { + return String.format("min_value(%s)", path); + } + + public static String recordToInsert(TSRecord record) { + StringBuilder measurements = new StringBuilder(); + StringBuilder values = new StringBuilder(); + for (DataPoint dataPoint : record.dataPointList) { + measurements.append(",").append(dataPoint.getMeasurementId()); + values.append(",").append(dataPoint.getValue()); + } + return String.format(insertTemplate, record.deviceId, measurements, record.time, values); + } + + public static String getTestTsFilePath( + String logicalStorageGroupName, + long VirtualStorageGroupId, + long TimePartitionId, + long tsFileVersion) { + String filePath = + String.format( + TEST_TSFILE_PATH, logicalStorageGroupName, VirtualStorageGroupId, TimePartitionId); + String fileName = + System.currentTimeMillis() + + FilePathUtils.FILE_NAME_SEPARATOR + + tsFileVersion + + "-0-0.tsfile"; + return filePath.concat(fileName); + } + + public static String getTestTsFileDir( + String logicalStorageGroupName, long VirtualStorageGroupId, long TimePartitionId) { + return String.format( + TestConstant.TEST_TSFILE_PATH, + logicalStorageGroupName, + VirtualStorageGroupId, + TimePartitionId); + } +} diff --git a/integration-test/src/main/java/org/apache/iotdb/itbase/env/BaseConfig.java b/integration-test/src/main/java/org/apache/iotdb/itbase/env/BaseConfig.java index 1fd81d1775..28f015b850 100644 --- a/integration-test/src/main/java/org/apache/iotdb/itbase/env/BaseConfig.java +++ b/integration-test/src/main/java/org/apache/iotdb/itbase/env/BaseConfig.java @@ -94,14 +94,26 @@ public interface BaseConfig { return this; } + default boolean isEnableSeqSpaceCompaction() { + return true; + } + default BaseConfig setEnableUnseqSpaceCompaction(boolean enableUnseqSpaceCompaction) { return this; } + default boolean isEnableUnseqSpaceCompaction() { + return true; + } + default BaseConfig setEnableCrossSpaceCompaction(boolean enableCrossSpaceCompaction) { return this; } + default boolean isEnableCrossSpaceCompaction() { + return true; + } + default BaseConfig setEnableIDTable(boolean isEnableIDTable) { return this; } @@ -113,4 +125,16 @@ public interface BaseConfig { default BaseConfig setAutoCreateSchemaEnabled(boolean enableAutoCreateSchema) { return this; } + + default BaseConfig setEnableLastCache(boolean lastCacheEnable) { + return this; + } + + default boolean isLastCacheEnabled() { + return true; + } + + default int getMaxNumberOfPointsInPage() { + return 1024 * 1024; + } } diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/AlignedWriteUtil.java b/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/AlignedWriteUtil.java new file mode 100644 index 0000000000..2145da4c2e --- /dev/null +++ b/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/AlignedWriteUtil.java @@ -0,0 +1,147 @@ +/* + * 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 java.sql.Connection; +import java.sql.Statement; + +import static org.junit.Assert.fail; + +/** + * This class generates data for test cases in aligned time series scenarios. + * + * <p>You can comprehensively view the generated data in the following online doc: + * + * <p>https://docs.google.com/spreadsheets/d/1kfrSR1_paSd9B1Z0jnPBD3WQIMDslDuNm4R0mpWx9Ms/edit?usp=sharing + */ +public class AlignedWriteUtil { + + private static final String[] sqls = + new String[] { + "SET STORAGE GROUP TO root.sg1", + "create aligned timeseries root.sg1.d1(s1 FLOAT encoding=RLE, s2 INT32 encoding=Gorilla compression=SNAPPY, s3 INT64, s4 BOOLEAN, s5 TEXT)", + "create timeseries root.sg1.d2.s1 WITH DATATYPE=FLOAT, encoding=RLE", + "create timeseries root.sg1.d2.s2 WITH DATATYPE=INT32, encoding=Gorilla", + "create timeseries root.sg1.d2.s3 WITH DATATYPE=INT64", + "create timeseries root.sg1.d2.s4 WITH DATATYPE=BOOLEAN", + "create timeseries root.sg1.d2.s5 WITH DATATYPE=TEXT", + "insert into root.sg1.d1(time, s1, s2, s3, s4, s5) aligned values(1, 1.0, 1, 1, TRUE, 'aligned_test1')", + "insert into root.sg1.d1(time, s1, s2, s3, s5) aligned values(2, 2.0, 2, 2, 'aligned_test2')", + "insert into root.sg1.d1(time, s1, s3, s4, s5) aligned values(3, 3.0, 3, FALSE, 'aligned_test3')", + "insert into root.sg1.d1(time, s1, s2, s4, s5) aligned values(4, 4.0, 4, TRUE, 'aligned_test4')", + "insert into root.sg1.d1(time, s1, s2, s4, s5) aligned values(5, 5.0, 5, TRUE, 'aligned_test5')", + "insert into root.sg1.d1(time, s1, s2, s3, s4) aligned values(6, 6.0, 6, 6, TRUE)", + "insert into root.sg1.d1(time, s1, s2, s3, s4, s5) aligned values(7, 7.0, 7, 7, FALSE, 'aligned_test7')", + "insert into root.sg1.d1(time, s1, s2, s3, s5) aligned values(8, 8.0, 8, 8, 'aligned_test8')", + "insert into root.sg1.d1(time, s1, s2, s3, s4, s5) aligned values(9, 9.0, 9, 9, FALSE, 'aligned_test9')", + "insert into root.sg1.d1(time, s2, s3, s4, s5) aligned values(10, 10, 10, TRUE, 'aligned_test10')", + "insert into root.sg1.d2(time, s1, s2, s3, s4, s5) values(1, 1.0, 1, 1, TRUE, 'non_aligned_test1')", + "insert into root.sg1.d2(time, s1, s2, s3, s5) values(2, 2.0, 2, 2, 'non_aligned_test2')", + "insert into root.sg1.d2(time, s1, s3, s4, s5) values(3, 3.0, 3, FALSE, 'non_aligned_test3')", + "insert into root.sg1.d2(time, s1, s2, s4, s5) values(4, 4.0, 4, TRUE, 'non_aligned_test4')", + "insert into root.sg1.d2(time, s1, s2, s4, s5) values(5, 5.0, 5, TRUE, 'non_aligned_test5')", + "insert into root.sg1.d2(time, s1, s2, s3, s4) values(6, 6.0, 6, 6, TRUE)", + "insert into root.sg1.d2(time, s1, s2, s3, s4, s5) values(7, 7.0, 7, 7, FALSE, 'non_aligned_test7')", + "insert into root.sg1.d2(time, s1, s2, s3, s5) values(8, 8.0, 8, 8, 'non_aligned_test8')", + "insert into root.sg1.d2(time, s1, s2, s3, s4, s5) values(9, 9.0, 9, 9, FALSE, 'non_aligned_test9')", + "insert into root.sg1.d2(time, s2, s3, s4, s5) values(10, 10, 10, TRUE, 'non_aligned_test10')", + // "flush", + "insert into root.sg1.d1(time, s1, s3, s4, s5) aligned values(3, 30000.0, 30000, TRUE, 'aligned_unseq_test3')", + "insert into root.sg1.d1(time, s1, s2, s3) aligned values(11, 11.0, 11, 11)", + "insert into root.sg1.d1(time, s1, s2, s3) aligned values(12, 12.0, 12, 12)", + "insert into root.sg1.d1(time, s1, s2, s3) aligned values(13, 13.0, 13, 13)", + "insert into root.sg1.d1(time, s1, s2, s3) aligned values(14, 14.0, 14, 14)", + "insert into root.sg1.d1(time, s1, s2, s3) aligned values(15, 15.0, 15, 15)", + "insert into root.sg1.d1(time, s1, s2, s3) aligned values(16, 16.0, 16, 16)", + "insert into root.sg1.d1(time, s1, s2, s3) aligned values(17, 17.0, 17, 17)", + "insert into root.sg1.d1(time, s1, s2, s3) aligned values(18, 18.0, 18, 18)", + "insert into root.sg1.d1(time, s1, s2, s3) aligned values(19, 19.0, 19, 19)", + "insert into root.sg1.d1(time, s1, s2, s3) aligned values(20, 20.0, 20, 20)", + "insert into root.sg1.d2(time, s1, s2, s3) values(11, 11.0, 11, 11)", + "insert into root.sg1.d2(time, s1, s2, s3) values(12, 12.0, 12, 12)", + "insert into root.sg1.d2(time, s1, s2, s3) values(13, 13.0, 13, 13)", + "insert into root.sg1.d2(time, s1, s2, s3) values(14, 14.0, 14, 14)", + "insert into root.sg1.d2(time, s1, s2, s3) values(15, 15.0, 15, 15)", + "insert into root.sg1.d2(time, s1, s2, s3) values(16, 16.0, 16, 16)", + "insert into root.sg1.d2(time, s1, s2, s3) values(17, 17.0, 17, 17)", + "insert into root.sg1.d2(time, s1, s2, s3) values(18, 18.0, 18, 18)", + "insert into root.sg1.d2(time, s1, s2, s3) values(19, 19.0, 19, 19)", + "insert into root.sg1.d2(time, s1, s2, s3) values(20, 20.0, 20, 20)", + // "flush", + "insert into root.sg1.d1(time, s1, s2, s3, s4, s5) aligned values(13, 130000.0, 130000, 130000, TRUE, 'aligned_unseq_test13')", + "insert into root.sg1.d1(time, s3, s4) aligned values(21, 21, TRUE)", + "insert into root.sg1.d1(time, s3, s4) aligned values(22, 22, TRUE)", + "insert into root.sg1.d1(time, s3, s4) aligned values(23, 23, TRUE)", + "insert into root.sg1.d1(time, s3, s4) aligned values(24, 24, TRUE)", + "insert into root.sg1.d1(time, s3, s4) aligned values(25, 25, TRUE)", + "insert into root.sg1.d1(time, s3, s4) aligned values(26, 26, FALSE)", + "insert into root.sg1.d1(time, s3, s4) aligned values(27, 27, FALSE)", + "insert into root.sg1.d1(time, s3, s4) aligned values(28, 28, FALSE)", + "insert into root.sg1.d1(time, s3, s4) aligned values(29, 29, FALSE)", + "insert into root.sg1.d1(time, s3, s4) aligned values(30, 30, FALSE)", + "insert into root.sg1.d2(time, s3, s4) values(21, 21, TRUE)", + "insert into root.sg1.d2(time, s3, s4) values(22, 22, TRUE)", + "insert into root.sg1.d2(time, s3, s4) values(23, 23, TRUE)", + "insert into root.sg1.d2(time, s3, s4) values(24, 24, TRUE)", + "insert into root.sg1.d2(time, s3, s4) values(25, 25, TRUE)", + "insert into root.sg1.d2(time, s3, s4) values(26, 26, FALSE)", + "insert into root.sg1.d2(time, s3, s4) values(27, 27, FALSE)", + "insert into root.sg1.d2(time, s3, s4) values(28, 28, FALSE)", + "insert into root.sg1.d2(time, s3, s4) values(29, 29, FALSE)", + "insert into root.sg1.d2(time, s3, s4) values(30, 30, FALSE)", + // "flush", + "insert into root.sg1.d1(time, s1, s3, s4) aligned values(23, 230000.0, 230000, FALSE)", + "insert into root.sg1.d1(time, s2, s5) aligned values(31, 31, 'aligned_test31')", + "insert into root.sg1.d1(time, s2, s5) aligned values(32, 32, 'aligned_test32')", + "insert into root.sg1.d1(time, s2, s5) aligned values(33, 33, 'aligned_test33')", + "insert into root.sg1.d1(time, s2, s5) aligned values(34, 34, 'aligned_test34')", + "insert into root.sg1.d1(time, s2, s5) aligned values(35, 35, 'aligned_test35')", + "insert into root.sg1.d1(time, s2, s5) aligned values(36, 36, 'aligned_test36')", + "insert into root.sg1.d1(time, s2, s5) aligned values(37, 37, 'aligned_test37')", + "insert into root.sg1.d1(time, s2, s5) aligned values(38, 38, 'aligned_test38')", + "insert into root.sg1.d1(time, s2, s5) aligned values(39, 39, 'aligned_test39')", + "insert into root.sg1.d1(time, s2, s5) aligned values(40, 40, 'aligned_test40')", + "insert into root.sg1.d2(time, s2, s5) values(31, 31, 'non_aligned_test31')", + "insert into root.sg1.d2(time, s2, s5) values(32, 32, 'non_aligned_test32')", + "insert into root.sg1.d2(time, s2, s5) values(33, 33, 'non_aligned_test33')", + "insert into root.sg1.d2(time, s2, s5) values(34, 34, 'non_aligned_test34')", + "insert into root.sg1.d2(time, s2, s5) values(35, 35, 'non_aligned_test35')", + "insert into root.sg1.d2(time, s2, s5) values(36, 36, 'non_aligned_test36')", + "insert into root.sg1.d2(time, s2, s5) values(37, 37, 'non_aligned_test37')", + "insert into root.sg1.d2(time, s2, s5) values(38, 38, 'non_aligned_test38')", + "insert into root.sg1.d2(time, s2, s5) values(39, 39, 'non_aligned_test39')", + "insert into root.sg1.d2(time, s2, s5) values(40, 40, 'non_aligned_test40')", + }; + + public static void insertData() throws ClassNotFoundException { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + + // create aligned and non-aligned time series + for (String sql : sqls) { + statement.execute(sql); + } + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + } +} diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBLastQuery2IT.java b/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBLastQuery2IT.java new file mode 100644 index 0000000000..b3578c3039 --- /dev/null +++ b/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBLastQuery2IT.java @@ -0,0 +1,58 @@ +/* + * 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.ConfigFactory; +import org.apache.iotdb.it.env.EnvFactory; +import org.apache.iotdb.itbase.category.ClusterIT; +import org.apache.iotdb.itbase.category.LocalStandaloneIT; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.experimental.categories.Category; + +@Category({LocalStandaloneIT.class, ClusterIT.class}) +public class IoTDBLastQuery2IT extends IoTDBLastQueryIT { + + private static int numOfPointsPerPage; + + @BeforeClass + public static void setUp() throws Exception { + enableSeqSpaceCompaction = ConfigFactory.getConfig().isEnableSeqSpaceCompaction(); + enableUnseqSpaceCompaction = ConfigFactory.getConfig().isEnableUnseqSpaceCompaction(); + enableCrossSpaceCompaction = ConfigFactory.getConfig().isEnableCrossSpaceCompaction(); + numOfPointsPerPage = ConfigFactory.getConfig().getMaxNumberOfPointsInPage(); + + ConfigFactory.getConfig().setEnableSeqSpaceCompaction(false); + ConfigFactory.getConfig().setEnableUnseqSpaceCompaction(false); + ConfigFactory.getConfig().setEnableCrossSpaceCompaction(false); + ConfigFactory.getConfig().setMaxNumberOfPointsInPage(3); + EnvFactory.getEnv().initBeforeClass(); + AlignedWriteUtil.insertData(); + } + + @AfterClass + public static void tearDown() throws Exception { + EnvFactory.getEnv().cleanAfterClass(); + ConfigFactory.getConfig().setEnableSeqSpaceCompaction(enableSeqSpaceCompaction); + ConfigFactory.getConfig().setEnableUnseqSpaceCompaction(enableUnseqSpaceCompaction); + ConfigFactory.getConfig().setEnableCrossSpaceCompaction(enableCrossSpaceCompaction); + ConfigFactory.getConfig().setMaxNumberOfPointsInPage(numOfPointsPerPage); + } +} diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBLastQueryIT.java b/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBLastQueryIT.java new file mode 100644 index 0000000000..28b80d0eae --- /dev/null +++ b/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBLastQueryIT.java @@ -0,0 +1,327 @@ +/* + * 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.ConfigFactory; +import org.apache.iotdb.it.env.EnvFactory; +import org.apache.iotdb.itbase.category.ClusterIT; +import org.apache.iotdb.itbase.category.LocalStandaloneIT; + +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +import static org.apache.iotdb.itbase.constant.TestConstant.DATA_TYPE_STR; +import static org.apache.iotdb.itbase.constant.TestConstant.TIMESEIRES_STR; +import static org.apache.iotdb.itbase.constant.TestConstant.TIMESTAMP_STR; +import static org.apache.iotdb.itbase.constant.TestConstant.VALUE_STR; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +@Category({LocalStandaloneIT.class, ClusterIT.class}) +public class IoTDBLastQueryIT { + + protected static boolean enableSeqSpaceCompaction; + protected static boolean enableUnseqSpaceCompaction; + protected static boolean enableCrossSpaceCompaction; + + @BeforeClass + public static void setUp() throws Exception { + enableSeqSpaceCompaction = ConfigFactory.getConfig().isEnableSeqSpaceCompaction(); + enableUnseqSpaceCompaction = ConfigFactory.getConfig().isEnableUnseqSpaceCompaction(); + enableCrossSpaceCompaction = ConfigFactory.getConfig().isEnableCrossSpaceCompaction(); + ConfigFactory.getConfig().setEnableSeqSpaceCompaction(false); + ConfigFactory.getConfig().setEnableUnseqSpaceCompaction(false); + ConfigFactory.getConfig().setEnableCrossSpaceCompaction(false); + EnvFactory.getEnv().initBeforeClass(); + AlignedWriteUtil.insertData(); + } + + @AfterClass + public static void tearDown() throws Exception { + EnvFactory.getEnv().cleanAfterClass(); + ConfigFactory.getConfig().setEnableSeqSpaceCompaction(enableSeqSpaceCompaction); + ConfigFactory.getConfig().setEnableUnseqSpaceCompaction(enableUnseqSpaceCompaction); + ConfigFactory.getConfig().setEnableCrossSpaceCompaction(enableCrossSpaceCompaction); + } + + @Test + public void selectAllAlignedLastTest() { + Set<String> retSet = + new HashSet<>( + Arrays.asList( + "23,root.sg1.d1.s1,230000.0,FLOAT", + "40,root.sg1.d1.s2,40,INT32", + "30,root.sg1.d1.s3,30,INT64", + "30,root.sg1.d1.s4,false,BOOLEAN", + "40,root.sg1.d1.s5,aligned_test40,TEXT")); + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + + try (ResultSet resultSet = statement.executeQuery("select last * from root.sg1.d1")) { + int cnt = 0; + while (resultSet.next()) { + String ans = + resultSet.getString(TIMESTAMP_STR) + + "," + + resultSet.getString(TIMESEIRES_STR) + + "," + + resultSet.getString(VALUE_STR) + + "," + + resultSet.getString(DATA_TYPE_STR); + Assert.assertTrue(retSet.contains(ans)); + cnt++; + } + assertEquals(retSet.size(), cnt); + } + + } catch (SQLException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } + + @Test + public void selectAllAlignedAndNonAlignedLastTest() { + + Set<String> retSet = + new HashSet<>( + Arrays.asList( + "23,root.sg1.d1.s1,230000.0,FLOAT", + "40,root.sg1.d1.s2,40,INT32", + "30,root.sg1.d1.s3,30,INT64", + "30,root.sg1.d1.s4,false,BOOLEAN", + "40,root.sg1.d1.s5,aligned_test40,TEXT", + "20,root.sg1.d2.s1,20.0,FLOAT", + "40,root.sg1.d2.s2,40,INT32", + "30,root.sg1.d2.s3,30,INT64", + "30,root.sg1.d2.s4,false,BOOLEAN", + "40,root.sg1.d2.s5,non_aligned_test40,TEXT")); + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + + try (ResultSet resultSet = statement.executeQuery("select last * from root.sg1.*")) { + int cnt = 0; + while (resultSet.next()) { + String ans = + resultSet.getString(TIMESTAMP_STR) + + "," + + resultSet.getString(TIMESEIRES_STR) + + "," + + resultSet.getString(VALUE_STR) + + "," + + resultSet.getString(DATA_TYPE_STR); + Assert.assertTrue(retSet.contains(ans)); + cnt++; + } + assertEquals(retSet.size(), cnt); + } + + } catch (SQLException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } + + @Test + public void selectAllAlignedLastWithTimeFilterTest() { + + Set<String> retSet = + new HashSet<>( + Arrays.asList("40,root.sg1.d1.s2,40,INT32", "40,root.sg1.d1.s5,aligned_test40,TEXT")); + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + + try (ResultSet resultSet = + statement.executeQuery("select last * from root.sg1.d1 where time > 30")) { + int cnt = 0; + while (resultSet.next()) { + String ans = + resultSet.getString(TIMESTAMP_STR) + + "," + + resultSet.getString(TIMESEIRES_STR) + + "," + + resultSet.getString(VALUE_STR) + + "," + + resultSet.getString(DATA_TYPE_STR); + Assert.assertTrue(retSet.contains(ans)); + cnt++; + } + assertEquals(retSet.size(), cnt); + } + + } catch (SQLException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } + + @Test + public void selectSomeAlignedLastTest1() { + Set<String> retSet = + new HashSet<>( + Arrays.asList( + "23,root.sg1.d1.s1,230000.0,FLOAT", + "30,root.sg1.d1.s4,false,BOOLEAN", + "40,root.sg1.d1.s5,aligned_test40,TEXT")); + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + + try (ResultSet resultSet = + statement.executeQuery("select last s1, s4, s5 from root.sg1.d1")) { + int cnt = 0; + while (resultSet.next()) { + String ans = + resultSet.getString(TIMESTAMP_STR) + + "," + + resultSet.getString(TIMESEIRES_STR) + + "," + + resultSet.getString(VALUE_STR) + + "," + + resultSet.getString(DATA_TYPE_STR); + Assert.assertTrue(retSet.contains(ans)); + cnt++; + } + assertEquals(retSet.size(), cnt); + } + + } catch (SQLException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } + + @Test + public void selectSomeAlignedLastTest2() { + Set<String> retSet = + new HashSet<>( + Arrays.asList("23,root.sg1.d1.s1,230000.0,FLOAT", "30,root.sg1.d1.s4,false,BOOLEAN")); + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + + try (ResultSet resultSet = statement.executeQuery("select last s1, s4 from root.sg1.d1")) { + int cnt = 0; + while (resultSet.next()) { + String ans = + resultSet.getString(TIMESTAMP_STR) + + "," + + resultSet.getString(TIMESEIRES_STR) + + "," + + resultSet.getString(VALUE_STR) + + "," + + resultSet.getString(DATA_TYPE_STR); + Assert.assertTrue(retSet.contains(ans)); + cnt++; + } + assertEquals(retSet.size(), cnt); + } + + } catch (SQLException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } + + @Test + public void selectSomeAlignedLastWithTimeFilterTest() { + + Set<String> retSet = + new HashSet<>(Collections.singletonList("40,root.sg1.d1.s5,aligned_test40,TEXT")); + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + + try (ResultSet resultSet = + statement.executeQuery("select last s1, s4, s5 from root.sg1.d1 where time > 30")) { + int cnt = 0; + while (resultSet.next()) { + String ans = + resultSet.getString(TIMESTAMP_STR) + + "," + + resultSet.getString(TIMESEIRES_STR) + + "," + + resultSet.getString(VALUE_STR) + + "," + + resultSet.getString(DATA_TYPE_STR); + Assert.assertTrue(retSet.contains(ans)); + cnt++; + } + assertEquals(retSet.size(), cnt); + } + + } catch (SQLException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } + + @Test + public void selectSomeAlignedAndNonAlignedLastWithTimeFilterTest() { + + Set<String> retSet = + new HashSet<>( + Arrays.asList( + "40,root.sg1.d1.s5,aligned_test40,TEXT", + "40,root.sg1.d2.s5,non_aligned_test40,TEXT")); + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + + // 1 4 5 + try (ResultSet resultSet = + statement.executeQuery( + "select last d2.s5, d1.s4, d2.s1, d1.s5, d2.s4, d1.s1 from root.sg1 where time > 30")) { + int cnt = 0; + while (resultSet.next()) { + String ans = + resultSet.getString(TIMESTAMP_STR) + + "," + + resultSet.getString(TIMESEIRES_STR) + + "," + + resultSet.getString(VALUE_STR) + + "," + + resultSet.getString(DATA_TYPE_STR); + Assert.assertTrue(retSet.contains(ans)); + cnt++; + } + assertEquals(retSet.size(), cnt); + } + + } catch (SQLException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } +} diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBLastQueryWithoutLastCache2IT.java b/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBLastQueryWithoutLastCache2IT.java new file mode 100644 index 0000000000..8882cdb719 --- /dev/null +++ b/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBLastQueryWithoutLastCache2IT.java @@ -0,0 +1,60 @@ +/* + * 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.ConfigFactory; +import org.apache.iotdb.it.env.EnvFactory; +import org.apache.iotdb.itbase.category.ClusterIT; +import org.apache.iotdb.itbase.category.LocalStandaloneIT; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.experimental.categories.Category; + +@Category({LocalStandaloneIT.class, ClusterIT.class}) +public class IoTDBLastQueryWithoutLastCache2IT extends IoTDBLastQueryWithoutLastCacheIT { + + private static int numOfPointsPerPage; + + @BeforeClass + public static void setUp() throws Exception { + enableSeqSpaceCompaction = ConfigFactory.getConfig().isEnableSeqSpaceCompaction(); + enableUnseqSpaceCompaction = ConfigFactory.getConfig().isEnableUnseqSpaceCompaction(); + enableCrossSpaceCompaction = ConfigFactory.getConfig().isEnableCrossSpaceCompaction(); + enableLastCache = ConfigFactory.getConfig().isLastCacheEnabled(); + numOfPointsPerPage = ConfigFactory.getConfig().getMaxNumberOfPointsInPage(); + ConfigFactory.getConfig().setEnableSeqSpaceCompaction(false); + ConfigFactory.getConfig().setEnableUnseqSpaceCompaction(false); + ConfigFactory.getConfig().setEnableCrossSpaceCompaction(false); + ConfigFactory.getConfig().setEnableLastCache(false); + ConfigFactory.getConfig().setMaxNumberOfPointsInPage(3); + EnvFactory.getEnv().initBeforeClass(); + AlignedWriteUtil.insertData(); + } + + @AfterClass + public static void tearDown() throws Exception { + EnvFactory.getEnv().cleanAfterClass(); + ConfigFactory.getConfig().setEnableSeqSpaceCompaction(enableSeqSpaceCompaction); + ConfigFactory.getConfig().setEnableUnseqSpaceCompaction(enableUnseqSpaceCompaction); + ConfigFactory.getConfig().setEnableCrossSpaceCompaction(enableCrossSpaceCompaction); + ConfigFactory.getConfig().setEnableLastCache(enableLastCache); + ConfigFactory.getConfig().setMaxNumberOfPointsInPage(numOfPointsPerPage); + } +} diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBLastQueryWithoutLastCacheIT.java b/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBLastQueryWithoutLastCacheIT.java new file mode 100644 index 0000000000..d73feed4a3 --- /dev/null +++ b/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBLastQueryWithoutLastCacheIT.java @@ -0,0 +1,330 @@ +/* + * 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.ConfigFactory; +import org.apache.iotdb.it.env.EnvFactory; +import org.apache.iotdb.itbase.category.ClusterIT; +import org.apache.iotdb.itbase.category.LocalStandaloneIT; + +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +import static org.apache.iotdb.itbase.constant.TestConstant.DATA_TYPE_STR; +import static org.apache.iotdb.itbase.constant.TestConstant.TIMESEIRES_STR; +import static org.apache.iotdb.itbase.constant.TestConstant.TIMESTAMP_STR; +import static org.apache.iotdb.itbase.constant.TestConstant.VALUE_STR; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +@Category({LocalStandaloneIT.class, ClusterIT.class}) +public class IoTDBLastQueryWithoutLastCacheIT { + + protected static boolean enableSeqSpaceCompaction; + protected static boolean enableUnseqSpaceCompaction; + protected static boolean enableCrossSpaceCompaction; + protected static boolean enableLastCache; + + @BeforeClass + public static void setUp() throws Exception { + enableSeqSpaceCompaction = ConfigFactory.getConfig().isEnableSeqSpaceCompaction(); + enableUnseqSpaceCompaction = ConfigFactory.getConfig().isEnableUnseqSpaceCompaction(); + enableCrossSpaceCompaction = ConfigFactory.getConfig().isEnableCrossSpaceCompaction(); + enableLastCache = ConfigFactory.getConfig().isLastCacheEnabled(); + ConfigFactory.getConfig().setEnableSeqSpaceCompaction(false); + ConfigFactory.getConfig().setEnableUnseqSpaceCompaction(false); + ConfigFactory.getConfig().setEnableCrossSpaceCompaction(false); + ConfigFactory.getConfig().setEnableLastCache(false); + EnvFactory.getEnv().initBeforeClass(); + AlignedWriteUtil.insertData(); + } + + @AfterClass + public static void tearDown() throws Exception { + EnvFactory.getEnv().cleanAfterClass(); + ConfigFactory.getConfig().setEnableSeqSpaceCompaction(enableSeqSpaceCompaction); + ConfigFactory.getConfig().setEnableUnseqSpaceCompaction(enableUnseqSpaceCompaction); + ConfigFactory.getConfig().setEnableCrossSpaceCompaction(enableCrossSpaceCompaction); + ConfigFactory.getConfig().setEnableLastCache(enableLastCache); + } + + @Test + public void selectAllAlignedLastTest() { + Set<String> retSet = + new HashSet<>( + Arrays.asList( + "23,root.sg1.d1.s1,230000.0,FLOAT", + "40,root.sg1.d1.s2,40,INT32", + "30,root.sg1.d1.s3,30,INT64", + "30,root.sg1.d1.s4,false,BOOLEAN", + "40,root.sg1.d1.s5,aligned_test40,TEXT")); + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + + try (ResultSet resultSet = statement.executeQuery("select last * from root.sg1.d1")) { + int cnt = 0; + while (resultSet.next()) { + String ans = + resultSet.getString(TIMESTAMP_STR) + + "," + + resultSet.getString(TIMESEIRES_STR) + + "," + + resultSet.getString(VALUE_STR) + + "," + + resultSet.getString(DATA_TYPE_STR); + Assert.assertTrue(retSet.contains(ans)); + cnt++; + } + assertEquals(retSet.size(), cnt); + } + + } catch (SQLException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } + + @Test + public void selectAllAlignedAndNonAlignedLastTest() { + + Set<String> retSet = + new HashSet<>( + Arrays.asList( + "23,root.sg1.d1.s1,230000.0,FLOAT", + "40,root.sg1.d1.s2,40,INT32", + "30,root.sg1.d1.s3,30,INT64", + "30,root.sg1.d1.s4,false,BOOLEAN", + "40,root.sg1.d1.s5,aligned_test40,TEXT", + "20,root.sg1.d2.s1,20.0,FLOAT", + "40,root.sg1.d2.s2,40,INT32", + "30,root.sg1.d2.s3,30,INT64", + "30,root.sg1.d2.s4,false,BOOLEAN", + "40,root.sg1.d2.s5,non_aligned_test40,TEXT")); + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + + try (ResultSet resultSet = statement.executeQuery("select last * from root.sg1.*")) { + int cnt = 0; + while (resultSet.next()) { + String ans = + resultSet.getString(TIMESTAMP_STR) + + "," + + resultSet.getString(TIMESEIRES_STR) + + "," + + resultSet.getString(VALUE_STR) + + "," + + resultSet.getString(DATA_TYPE_STR); + Assert.assertTrue(retSet.contains(ans)); + cnt++; + } + assertEquals(retSet.size(), cnt); + } + + } catch (SQLException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } + + @Test + public void selectAllAlignedLastWithTimeFilterTest() { + + Set<String> retSet = + new HashSet<>( + Arrays.asList("40,root.sg1.d1.s2,40,INT32", "40,root.sg1.d1.s5,aligned_test40,TEXT")); + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + + try (ResultSet resultSet = + statement.executeQuery("select last * from root.sg1.d1 where time > 30")) { + int cnt = 0; + while (resultSet.next()) { + String ans = + resultSet.getString(TIMESTAMP_STR) + + "," + + resultSet.getString(TIMESEIRES_STR) + + "," + + resultSet.getString(VALUE_STR) + + "," + + resultSet.getString(DATA_TYPE_STR); + Assert.assertTrue(retSet.contains(ans)); + cnt++; + } + assertEquals(retSet.size(), cnt); + } + + } catch (SQLException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } + + @Test + public void selectSomeAlignedLastTest1() { + Set<String> retSet = + new HashSet<>( + Arrays.asList( + "23,root.sg1.d1.s1,230000.0,FLOAT", + "30,root.sg1.d1.s4,false,BOOLEAN", + "40,root.sg1.d1.s5,aligned_test40,TEXT")); + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + + try (ResultSet resultSet = + statement.executeQuery("select last s1, s4, s5 from root.sg1.d1")) { + int cnt = 0; + while (resultSet.next()) { + String ans = + resultSet.getString(TIMESTAMP_STR) + + "," + + resultSet.getString(TIMESEIRES_STR) + + "," + + resultSet.getString(VALUE_STR) + + "," + + resultSet.getString(DATA_TYPE_STR); + Assert.assertTrue(retSet.contains(ans)); + cnt++; + } + assertEquals(retSet.size(), cnt); + } + + } catch (SQLException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } + + @Test + public void selectSomeAlignedLastTest2() { + Set<String> retSet = + new HashSet<>( + Arrays.asList("23,root.sg1.d1.s1,230000.0,FLOAT", "30,root.sg1.d1.s4,false,BOOLEAN")); + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + + try (ResultSet resultSet = statement.executeQuery("select last s1, s4 from root.sg1.d1")) { + int cnt = 0; + while (resultSet.next()) { + String ans = + resultSet.getString(TIMESTAMP_STR) + + "," + + resultSet.getString(TIMESEIRES_STR) + + "," + + resultSet.getString(VALUE_STR) + + "," + + resultSet.getString(DATA_TYPE_STR); + Assert.assertTrue(retSet.contains(ans)); + cnt++; + } + assertEquals(retSet.size(), cnt); + } + + } catch (SQLException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } + + @Test + public void selectSomeAlignedLastWithTimeFilterTest() { + + Set<String> retSet = + new HashSet<>(Collections.singletonList("40,root.sg1.d1.s5,aligned_test40,TEXT")); + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + + try (ResultSet resultSet = + statement.executeQuery("select last s1, s4, s5 from root.sg1.d1 where time > 30")) { + int cnt = 0; + while (resultSet.next()) { + String ans = + resultSet.getString(TIMESTAMP_STR) + + "," + + resultSet.getString(TIMESEIRES_STR) + + "," + + resultSet.getString(VALUE_STR) + + "," + + resultSet.getString(DATA_TYPE_STR); + Assert.assertTrue(retSet.contains(ans)); + cnt++; + } + assertEquals(retSet.size(), cnt); + } + + } catch (SQLException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } + + @Test + public void selectSomeAlignedAndNonAlignedLastWithTimeFilterTest() { + + Set<String> retSet = + new HashSet<>( + Arrays.asList( + "40,root.sg1.d1.s5,aligned_test40,TEXT", + "40,root.sg1.d2.s5,non_aligned_test40,TEXT")); + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + + try (ResultSet resultSet = + statement.executeQuery( + "select last d2.s5, d1.s4, d2.s1, d1.s5, d2.s4, d1.s1 from root.sg1 where time > 30")) { + int cnt = 0; + while (resultSet.next()) { + String ans = + resultSet.getString(TIMESTAMP_STR) + + "," + + resultSet.getString(TIMESEIRES_STR) + + "," + + resultSet.getString(VALUE_STR) + + "," + + resultSet.getString(DATA_TYPE_STR); + Assert.assertTrue(retSet.contains(ans)); + cnt++; + } + assertEquals(retSet.size(), cnt); + } + + } catch (SQLException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } +} diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBRawQueryWithValueFilter2IT.java b/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBRawQueryWithValueFilter2IT.java new file mode 100644 index 0000000000..83edafbfa5 --- /dev/null +++ b/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBRawQueryWithValueFilter2IT.java @@ -0,0 +1,58 @@ +/* + * 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.ConfigFactory; +import org.apache.iotdb.it.env.EnvFactory; +import org.apache.iotdb.itbase.category.ClusterIT; +import org.apache.iotdb.itbase.category.LocalStandaloneIT; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.experimental.categories.Category; + +@Category({LocalStandaloneIT.class, ClusterIT.class}) +public class IoTDBRawQueryWithValueFilter2IT extends IoTDBRawQueryWithValueFilterIT { + + private static int numOfPointsPerPage; + + @BeforeClass + public static void setUp() throws Exception { + enableSeqSpaceCompaction = ConfigFactory.getConfig().isEnableSeqSpaceCompaction(); + enableUnseqSpaceCompaction = ConfigFactory.getConfig().isEnableUnseqSpaceCompaction(); + enableCrossSpaceCompaction = ConfigFactory.getConfig().isEnableCrossSpaceCompaction(); + numOfPointsPerPage = ConfigFactory.getConfig().getMaxNumberOfPointsInPage(); + + ConfigFactory.getConfig().setEnableSeqSpaceCompaction(false); + ConfigFactory.getConfig().setEnableUnseqSpaceCompaction(false); + ConfigFactory.getConfig().setEnableCrossSpaceCompaction(false); + ConfigFactory.getConfig().setMaxNumberOfPointsInPage(3); + EnvFactory.getEnv().initBeforeClass(); + AlignedWriteUtil.insertData(); + } + + @AfterClass + public static void tearDown() throws Exception { + EnvFactory.getEnv().cleanAfterClass(); + ConfigFactory.getConfig().setEnableSeqSpaceCompaction(enableSeqSpaceCompaction); + ConfigFactory.getConfig().setEnableUnseqSpaceCompaction(enableUnseqSpaceCompaction); + ConfigFactory.getConfig().setEnableCrossSpaceCompaction(enableCrossSpaceCompaction); + ConfigFactory.getConfig().setMaxNumberOfPointsInPage(numOfPointsPerPage); + } +} diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBRawQueryWithValueFilterIT.java b/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBRawQueryWithValueFilterIT.java new file mode 100644 index 0000000000..5d26267b30 --- /dev/null +++ b/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBRawQueryWithValueFilterIT.java @@ -0,0 +1,679 @@ +/* + * 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.ConfigFactory; +import org.apache.iotdb.it.env.EnvFactory; +import org.apache.iotdb.itbase.category.ClusterIT; +import org.apache.iotdb.itbase.category.LocalStandaloneIT; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.experimental.categories.Category; + +@Category({LocalStandaloneIT.class, ClusterIT.class}) +public class IoTDBRawQueryWithValueFilterIT { + protected static boolean enableSeqSpaceCompaction; + protected static boolean enableUnseqSpaceCompaction; + protected static boolean enableCrossSpaceCompaction; + + @BeforeClass + public static void setUp() throws Exception { + enableSeqSpaceCompaction = ConfigFactory.getConfig().isEnableSeqSpaceCompaction(); + enableUnseqSpaceCompaction = ConfigFactory.getConfig().isEnableUnseqSpaceCompaction(); + enableCrossSpaceCompaction = ConfigFactory.getConfig().isEnableCrossSpaceCompaction(); + ConfigFactory.getConfig().setEnableSeqSpaceCompaction(false); + ConfigFactory.getConfig().setEnableUnseqSpaceCompaction(false); + ConfigFactory.getConfig().setEnableCrossSpaceCompaction(false); + EnvFactory.getEnv().initBeforeClass(); + AlignedWriteUtil.insertData(); + } + + @AfterClass + public static void tearDown() throws Exception { + EnvFactory.getEnv().cleanAfterClass(); + ConfigFactory.getConfig().setEnableSeqSpaceCompaction(enableSeqSpaceCompaction); + ConfigFactory.getConfig().setEnableUnseqSpaceCompaction(enableUnseqSpaceCompaction); + ConfigFactory.getConfig().setEnableCrossSpaceCompaction(enableCrossSpaceCompaction); + } + // + // @Test + // public void selectAllAlignedWithValueFilterTest1() { + // + // String[] retArray = + // new String[] { + // "1,1.0,1,1,true,aligned_test1", + // "3,30000.0,null,30000,true,aligned_unseq_test3", + // "4,4.0,4,null,true,aligned_test4", + // "5,5.0,5,null,true,aligned_test5", + // "6,6.0,6,6,true,null", + // "10,null,10,10,true,aligned_test10", + // "13,130000.0,130000,130000,true,aligned_unseq_test13", + // "21,null,null,21,true,null", + // "22,null,null,22,true,null", + // "24,null,null,24,true,null", + // "25,null,null,25,true,null", + // }; + // + // String[] columnNames = { + // "root.sg1.d1.s1", "root.sg1.d1.s2", "root.sg1.d1.s3", "root.sg1.d1.s4", "root.sg1.d1.s5" + // }; + // + // try (Connection connection = EnvFactory.getEnv().getConnection(); + // Statement statement = connection.createStatement()) { + // + // try (ResultSet resultSet = + // statement.executeQuery("select * from root.sg1.d1 where s4 = true")) { + // ResultSetMetaData resultSetMetaData = resultSet.getMetaData(); + // Map<String, Integer> map = new HashMap<>(); + // for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) { + // map.put(resultSetMetaData.getColumnName(i), i); + // } + // assertEquals(columnNames.length + 1, resultSetMetaData.getColumnCount()); + // int cnt = 0; + // while (resultSet.next()) { + // StringBuilder builder = new StringBuilder(); + // builder.append(resultSet.getString(1)); + // for (String columnName : columnNames) { + // int index = map.get(columnName); + // builder.append(",").append(resultSet.getString(index)); + // } + // assertEquals(retArray[cnt], builder.toString()); + // cnt++; + // } + // assertEquals(retArray.length, cnt); + // } + // + // } catch (SQLException e) { + // e.printStackTrace(); + // fail(e.getMessage()); + // } + // } + // + // @Test + // public void selectAllAlignedWithValueFilterTest2() { + // + // String[] retArray = + // new String[] { + // "12,12.0,12,12,null,null", + // "14,14.0,14,14,null,null", + // "15,15.0,15,15,null,null", + // "16,16.0,16,16,null,null", + // "17,17.0,17,17,null,null", + // "18,18.0,18,18,null,null", + // "19,19.0,19,19,null,null", + // "20,20.0,20,20,null,null", + // }; + // + // String[] columnNames = { + // "root.sg1.d1.s1", "root.sg1.d1.s2", "root.sg1.d1.s3", "root.sg1.d1.s4", "root.sg1.d1.s5" + // }; + // + // try (Connection connection = EnvFactory.getEnv().getConnection(); + // Statement statement = connection.createStatement()) { + // + // try (ResultSet resultSet = + // statement.executeQuery("select * from root.sg1.d1 where s1 > 11 and s2 <= 33")) { + // ResultSetMetaData resultSetMetaData = resultSet.getMetaData(); + // Map<String, Integer> map = new HashMap<>(); + // for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) { + // map.put(resultSetMetaData.getColumnName(i), i); + // } + // assertEquals(columnNames.length + 1, resultSetMetaData.getColumnCount()); + // int cnt = 0; + // while (resultSet.next()) { + // StringBuilder builder = new StringBuilder(); + // builder.append(resultSet.getString(1)); + // for (String columnName : columnNames) { + // int index = map.get(columnName); + // builder.append(",").append(resultSet.getString(index)); + // } + // assertEquals(retArray[cnt], builder.toString()); + // cnt++; + // } + // assertEquals(retArray.length, cnt); + // } + // + // } catch (SQLException e) { + // e.printStackTrace(); + // fail(e.getMessage()); + // } + // } + // + // @Test + // public void selectAllAlignedWithValueFilterTest3() { + // + // String[] retArray = + // new String[] { + // "1,1.0,1,1,true,aligned_test1", + // "2,2.0,2,2,null,aligned_test2", + // "3,30000.0,null,30000,true,aligned_unseq_test3", + // "4,4.0,4,null,true,aligned_test4", + // "5,5.0,5,null,true,aligned_test5", + // "6,6.0,6,6,true,null", + // "7,7.0,7,7,false,aligned_test7", + // "8,8.0,8,8,null,aligned_test8", + // "9,9.0,9,9,false,aligned_test9", + // "10,null,10,10,true,aligned_test10", + // "11,11.0,11,11,null,null", + // "12,12.0,12,12,null,null", + // "13,130000.0,130000,130000,true,aligned_unseq_test13", + // "14,14.0,14,14,null,null", + // "15,15.0,15,15,null,null", + // "16,16.0,16,16,null,null", + // "17,17.0,17,17,null,null", + // "18,18.0,18,18,null,null", + // "19,19.0,19,19,null,null", + // "20,20.0,20,20,null,null", + // "23,230000.0,null,230000,false,null", + // "31,null,31,null,null,aligned_test31", + // "32,null,32,null,null,aligned_test32", + // }; + // + // String[] columnNames = { + // "root.sg1.d1.s1", "root.sg1.d1.s2", "root.sg1.d1.s3", "root.sg1.d1.s4", "root.sg1.d1.s5" + // }; + // + // try (Connection connection = EnvFactory.getEnv().getConnection(); + // Statement statement = connection.createStatement()) { + // + // try (ResultSet resultSet = + // statement.executeQuery("select * from root.sg1.d1 where s1 >= 13 or s2 < 33")) { + // ResultSetMetaData resultSetMetaData = resultSet.getMetaData(); + // Map<String, Integer> map = new HashMap<>(); + // for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) { + // map.put(resultSetMetaData.getColumnName(i), i); + // } + // assertEquals(columnNames.length + 1, resultSetMetaData.getColumnCount()); + // int cnt = 0; + // while (resultSet.next()) { + // StringBuilder builder = new StringBuilder(); + // builder.append(resultSet.getString(1)); + // for (String columnName : columnNames) { + // int index = map.get(columnName); + // builder.append(",").append(resultSet.getString(index)); + // } + // assertEquals(retArray[cnt], builder.toString()); + // cnt++; + // } + // assertEquals(retArray.length, cnt); + // } + // + // } catch (SQLException e) { + // e.printStackTrace(); + // fail(e.getMessage()); + // } + // } + // + // @Test + // public void selectAllAlignedAndNonAlignedTest1() { + // + // String[] retArray = + // new String[] { + // "13,130000.0,130000,130000,true,aligned_unseq_test13,13.0,13,13,null,null", + // "17,17.0,17,17,null,null,17.0,17,17,null,null", + // "18,18.0,18,18,null,null,18.0,18,18,null,null", + // "19,19.0,19,19,null,null,19.0,19,19,null,null", + // "20,20.0,20,20,null,null,20.0,20,20,null,null", + // }; + // + // String[] columnNames = { + // "root.sg1.d1.s1", + // "root.sg1.d1.s2", + // "root.sg1.d1.s3", + // "root.sg1.d1.s4", + // "root.sg1.d1.s5", + // "root.sg1.d2.s1", + // "root.sg1.d2.s2", + // "root.sg1.d2.s3", + // "root.sg1.d2.s4", + // "root.sg1.d2.s5" + // }; + // + // try (Connection connection = EnvFactory.getEnv().getConnection(); + // Statement statement = connection.createStatement()) { + // + // try (ResultSet resultSet = + // statement.executeQuery( + // "select * from root.sg1.* where root.sg1.d1.s2 > 16 and root.sg1.d2.s3 <= 36")) { + // ResultSetMetaData resultSetMetaData = resultSet.getMetaData(); + // Map<String, Integer> map = new HashMap<>(); + // for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) { + // map.put(resultSetMetaData.getColumnName(i), i); + // } + // assertEquals(columnNames.length + 1, resultSetMetaData.getColumnCount()); + // int cnt = 0; + // while (resultSet.next()) { + // StringBuilder builder = new StringBuilder(); + // builder.append(resultSet.getString(1)); + // for (String columnName : columnNames) { + // int index = map.get(columnName); + // builder.append(",").append(resultSet.getString(index)); + // } + // assertEquals(retArray[cnt], builder.toString()); + // cnt++; + // } + // assertEquals(retArray.length, cnt); + // } + // + // } catch (SQLException e) { + // e.printStackTrace(); + // fail(e.getMessage()); + // } + // } + // + // @Test + // public void selectAllAlignedAndNonAlignedTest2() { + // + // String[] retArray = + // new String[] { + // "3,30000.0,null,30000,true,aligned_unseq_test3,3.0,null,3,false,non_aligned_test3", + // "7,7.0,7,7,false,aligned_test7,7.0,7,7,false,non_aligned_test7", + // "9,9.0,9,9,false,aligned_test9,9.0,9,9,false,non_aligned_test9", + // "13,130000.0,130000,130000,true,aligned_unseq_test13,13.0,13,13,null,null", + // "17,17.0,17,17,null,null,17.0,17,17,null,null", + // "18,18.0,18,18,null,null,18.0,18,18,null,null", + // "19,19.0,19,19,null,null,19.0,19,19,null,null", + // "20,20.0,20,20,null,null,20.0,20,20,null,null", + // "26,null,null,26,false,null,null,null,26,false,null", + // "27,null,null,27,false,null,null,null,27,false,null", + // "28,null,null,28,false,null,null,null,28,false,null", + // "29,null,null,29,false,null,null,null,29,false,null", + // "30,null,null,30,false,null,null,null,30,false,null", + // "31,null,31,null,null,aligned_test31,null,31,null,null,non_aligned_test31", + // "32,null,32,null,null,aligned_test32,null,32,null,null,non_aligned_test32", + // "33,null,33,null,null,aligned_test33,null,33,null,null,non_aligned_test33", + // "34,null,34,null,null,aligned_test34,null,34,null,null,non_aligned_test34", + // "35,null,35,null,null,aligned_test35,null,35,null,null,non_aligned_test35", + // "36,null,36,null,null,aligned_test36,null,36,null,null,non_aligned_test36", + // "37,null,37,null,null,aligned_test37,null,37,null,null,non_aligned_test37", + // "38,null,38,null,null,aligned_test38,null,38,null,null,non_aligned_test38", + // "39,null,39,null,null,aligned_test39,null,39,null,null,non_aligned_test39", + // "40,null,40,null,null,aligned_test40,null,40,null,null,non_aligned_test40", + // }; + // + // String[] columnNames = { + // "root.sg1.d1.s1", + // "root.sg1.d1.s2", + // "root.sg1.d1.s3", + // "root.sg1.d1.s4", + // "root.sg1.d1.s5", + // "root.sg1.d2.s1", + // "root.sg1.d2.s2", + // "root.sg1.d2.s3", + // "root.sg1.d2.s4", + // "root.sg1.d2.s5" + // }; + // + // try (Connection connection = EnvFactory.getEnv().getConnection(); + // Statement statement = connection.createStatement()) { + // + // try (ResultSet resultSet = + // statement.executeQuery( + // "select * from root.sg1.* where root.sg1.d1.s2 > 16 or root.sg1.d2.s4 = false")) { + // ResultSetMetaData resultSetMetaData = resultSet.getMetaData(); + // Map<String, Integer> map = new HashMap<>(); + // for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) { + // map.put(resultSetMetaData.getColumnName(i), i); + // } + // assertEquals(columnNames.length + 1, resultSetMetaData.getColumnCount()); + // int cnt = 0; + // while (resultSet.next()) { + // StringBuilder builder = new StringBuilder(); + // builder.append(resultSet.getString(1)); + // for (String columnName : columnNames) { + // int index = map.get(columnName); + // builder.append(",").append(resultSet.getString(index)); + // } + // assertEquals(retArray[cnt], builder.toString()); + // cnt++; + // } + // assertEquals(retArray.length, cnt); + // } + // + // } catch (SQLException e) { + // e.printStackTrace(); + // fail(e.getMessage()); + // } + // } + // + // @Test + // public void selectAllAlignedWithTimeAndValueFilterTest1() { + // + // String[] retArray = + // new String[] { + // "9,9.0,9,9,false,aligned_test9", + // "11,11.0,11,11,null,null", + // "12,12.0,12,12,null,null", + // "14,14.0,14,14,null,null", + // "15,15.0,15,15,null,null", + // "16,16.0,16,16,null,null", + // "17,17.0,17,17,null,null", + // "18,18.0,18,18,null,null", + // }; + // + // String[] columnNames = { + // "root.sg1.d1.s1", "root.sg1.d1.s2", "root.sg1.d1.s3", "root.sg1.d1.s4", "root.sg1.d1.s5" + // }; + // + // try (Connection connection = EnvFactory.getEnv().getConnection(); + // Statement statement = connection.createStatement()) { + // + // try (ResultSet resultSet = + // statement.executeQuery( + // "select * from root.sg1.d1 where time >= 9 and time <= 33 and s1 < 19")) { + // ResultSetMetaData resultSetMetaData = resultSet.getMetaData(); + // Map<String, Integer> map = new HashMap<>(); + // for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) { + // map.put(resultSetMetaData.getColumnName(i), i); + // } + // assertEquals(columnNames.length + 1, resultSetMetaData.getColumnCount()); + // int cnt = 0; + // while (resultSet.next()) { + // StringBuilder builder = new StringBuilder(); + // builder.append(resultSet.getString(1)); + // for (String columnName : columnNames) { + // int index = map.get(columnName); + // builder.append(",").append(resultSet.getString(index)); + // } + // assertEquals(retArray[cnt], builder.toString()); + // cnt++; + // } + // assertEquals(retArray.length, cnt); + // } + // + // } catch (SQLException e) { + // e.printStackTrace(); + // fail(e.getMessage()); + // } + // } + // + // @Test + // public void selectAllAlignedWithTimeAndValueFilterTest2() { + // + // String[] retArray = + // new String[] { + // "9,9.0,9,9,false,aligned_test9", + // "10,null,10,10,true,aligned_test10", + // "11,11.0,11,11,null,null", + // "12,12.0,12,12,null,null", + // "13,130000.0,130000,130000,true,aligned_unseq_test13", + // "14,14.0,14,14,null,null", + // "15,15.0,15,15,null,null", + // "16,16.0,16,16,null,null", + // "17,17.0,17,17,null,null", + // "18,18.0,18,18,null,null", + // "19,19.0,19,19,null,null", + // "20,20.0,20,20,null,null", + // "21,null,null,21,true,null", + // "22,null,null,22,true,null", + // "23,230000.0,null,230000,false,null", + // "24,null,null,24,true,null", + // "25,null,null,25,true,null", + // "26,null,null,26,false,null", + // "27,null,null,27,false,null", + // "28,null,null,28,false,null", + // "29,null,null,29,false,null", + // "30,null,null,30,false,null", + // "31,null,31,null,null,aligned_test31", + // "32,null,32,null,null,aligned_test32", + // "33,null,33,null,null,aligned_test33", + // "36,null,36,null,null,aligned_test36", + // "37,null,37,null,null,aligned_test37", + // }; + // + // String[] columnNames = { + // "root.sg1.d1.s1", "root.sg1.d1.s2", "root.sg1.d1.s3", "root.sg1.d1.s4", "root.sg1.d1.s5" + // }; + // + // try (Connection connection = EnvFactory.getEnv().getConnection(); + // Statement statement = connection.createStatement()) { + // + // try (ResultSet resultSet = + // statement.executeQuery( + // "select * from root.sg1.d1 where time >= 9 and time <= 33 or s5 = 'aligned_test36' + // or s5 = 'aligned_test37'")) { + // ResultSetMetaData resultSetMetaData = resultSet.getMetaData(); + // Map<String, Integer> map = new HashMap<>(); + // for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) { + // map.put(resultSetMetaData.getColumnName(i), i); + // } + // assertEquals(columnNames.length + 1, resultSetMetaData.getColumnCount()); + // int cnt = 0; + // while (resultSet.next()) { + // StringBuilder builder = new StringBuilder(); + // builder.append(resultSet.getString(1)); + // for (String columnName : columnNames) { + // int index = map.get(columnName); + // builder.append(",").append(resultSet.getString(index)); + // } + // assertEquals(retArray[cnt], builder.toString()); + // cnt++; + // } + // assertEquals(retArray.length, cnt); + // } + // + // } catch (SQLException e) { + // e.printStackTrace(); + // fail(e.getMessage()); + // } + // } + // + // @Test + // public void selectSomeAlignedWithValueFilterTest1() { + // + // String[] retArray = + // new String[] { + // "1,1.0,true,aligned_test1", + // "2,2.0,null,aligned_test2", + // "4,4.0,true,aligned_test4", + // "5,5.0,true,aligned_test5", + // "6,6.0,true,null", + // "7,7.0,false,aligned_test7", + // "8,8.0,null,aligned_test8", + // "9,9.0,false,aligned_test9", + // "11,11.0,null,null", + // "12,12.0,null,null", + // "14,14.0,null,null", + // "15,15.0,null,null", + // "16,16.0,null,null", + // "34,null,null,aligned_test34", + // }; + // + // String[] columnNames = {"root.sg1.d1.s1", "root.sg1.d1.s4", "root.sg1.d1.s5"}; + // + // try (Connection connection = EnvFactory.getEnv().getConnection(); + // Statement statement = connection.createStatement()) { + // + // try (ResultSet resultSet = + // statement.executeQuery( + // "select s1,s4,s5 from root.sg1.d1 where s1 < 17 or s5 = 'aligned_test34'")) { + // ResultSetMetaData resultSetMetaData = resultSet.getMetaData(); + // Map<String, Integer> map = new HashMap<>(); + // for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) { + // map.put(resultSetMetaData.getColumnName(i), i); + // } + // assertEquals(columnNames.length + 1, resultSetMetaData.getColumnCount()); + // int cnt = 0; + // while (resultSet.next()) { + // StringBuilder builder = new StringBuilder(); + // builder.append(resultSet.getString(1)); + // for (String columnName : columnNames) { + // int index = map.get(columnName); + // builder.append(",").append(resultSet.getString(index)); + // } + // assertEquals(retArray[cnt], builder.toString()); + // cnt++; + // } + // assertEquals(retArray.length, cnt); + // } + // + // } catch (SQLException e) { + // e.printStackTrace(); + // fail(e.getMessage()); + // } + // } + // + // @Test + // public void selectSomeAlignedWithValueFilterTest2() { + // + // String[] retArray = + // new String[] { + // "7,7.0,false", "9,9.0,false", + // }; + // + // String[] columnNames = {"root.sg1.d1.s1", "root.sg1.d1.s4"}; + // + // try (Connection connection = EnvFactory.getEnv().getConnection(); + // Statement statement = connection.createStatement()) { + // + // try (ResultSet resultSet = + // statement.executeQuery("select s1,s4 from root.sg1.d1 where s1 < 19 and s4 = false")) + // { + // ResultSetMetaData resultSetMetaData = resultSet.getMetaData(); + // Map<String, Integer> map = new HashMap<>(); + // for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) { + // map.put(resultSetMetaData.getColumnName(i), i); + // } + // assertEquals(columnNames.length + 1, resultSetMetaData.getColumnCount()); + // int cnt = 0; + // while (resultSet.next()) { + // StringBuilder builder = new StringBuilder(); + // builder.append(resultSet.getString(1)); + // for (String columnName : columnNames) { + // int index = map.get(columnName); + // builder.append(",").append(resultSet.getString(index)); + // } + // assertEquals(retArray[cnt], builder.toString()); + // cnt++; + // } + // assertEquals(retArray.length, cnt); + // } + // + // } catch (SQLException e) { + // e.printStackTrace(); + // fail(e.getMessage()); + // } + // } + // + // @Test + // public void selectSomeAlignedWithTimeAndValueFilterTest() { + // + // String[] retArray = + // new String[] { + // "23,230000.0,false,null", + // "26,null,false,null", + // "27,null,false,null", + // "28,null,false,null", + // "29,null,false,null", + // "30,null,false,null", + // }; + // + // String[] columnNames = {"root.sg1.d1.s1", "root.sg1.d1.s4", "root.sg1.d1.s5"}; + // + // try (Connection connection = EnvFactory.getEnv().getConnection(); + // Statement statement = connection.createStatement()) { + // + // try (ResultSet resultSet = + // statement.executeQuery( + // "select s1,s4,s5 from root.sg1.d1 where time >= 16 and time <= 34 and s4=false")) + // { + // ResultSetMetaData resultSetMetaData = resultSet.getMetaData(); + // Map<String, Integer> map = new HashMap<>(); + // for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) { + // map.put(resultSetMetaData.getColumnName(i), i); + // } + // assertEquals(columnNames.length + 1, resultSetMetaData.getColumnCount()); + // int cnt = 0; + // while (resultSet.next()) { + // StringBuilder builder = new StringBuilder(); + // builder.append(resultSet.getString(1)); + // for (String columnName : columnNames) { + // int index = map.get(columnName); + // builder.append(",").append(resultSet.getString(index)); + // } + // assertEquals(retArray[cnt], builder.toString()); + // cnt++; + // } + // assertEquals(retArray.length, cnt); + // } + // + // } catch (SQLException e) { + // e.printStackTrace(); + // fail(e.getMessage()); + // } + // } + // + // @Test + // public void selectSomeAlignedAndNonAlignedWithTimeAndValueFilterTest() { + // + // String[] retArray = + // new String[] { + // "18,null,null,18.0,null,null,18.0", + // "19,null,null,19.0,null,null,19.0", + // "20,null,null,20.0,null,null,20.0", + // "21,null,true,null,null,true,null", + // "22,null,true,null,null,true,null", + // "23,null,false,null,null,true,230000.0", + // "24,null,true,null,null,true,null", + // "25,null,true,null,null,true,null", + // }; + // + // String[] columnNames = { + // "root.sg1.d2.s5", + // "root.sg1.d1.s4", + // "root.sg1.d2.s1", + // "root.sg1.d1.s5", + // "root.sg1.d2.s4", + // "root.sg1.d1.s1" + // }; + // + // try (Connection connection = EnvFactory.getEnv().getConnection(); + // Statement statement = connection.createStatement()) { + // + // try (ResultSet resultSet = + // statement.executeQuery( + // "select d2.s5, d1.s4, d2.s1, d1.s5, d2.s4, d1.s1 from root.sg1 where time >= 16 + // and time <= 34 and (d1.s1 >= 18 or d2.s4 = true)")) { + // ResultSetMetaData resultSetMetaData = resultSet.getMetaData(); + // Map<String, Integer> map = new HashMap<>(); + // for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) { + // map.put(resultSetMetaData.getColumnName(i), i); + // } + // assertEquals(columnNames.length + 1, resultSetMetaData.getColumnCount()); + // int cnt = 0; + // while (resultSet.next()) { + // StringBuilder builder = new StringBuilder(); + // builder.append(resultSet.getString(1)); + // for (String columnName : columnNames) { + // int index = map.get(columnName); + // builder.append(",").append(resultSet.getString(index)); + // } + // assertEquals(retArray[cnt], builder.toString()); + // cnt++; + // } + // assertEquals(retArray.length, cnt); + // } + // + // } catch (SQLException e) { + // e.printStackTrace(); + // fail(e.getMessage()); + // } + // } +} diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBRawQueryWithoutValueFilter2IT.java b/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBRawQueryWithoutValueFilter2IT.java new file mode 100644 index 0000000000..a26ada2410 --- /dev/null +++ b/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBRawQueryWithoutValueFilter2IT.java @@ -0,0 +1,58 @@ +/* + * 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.ConfigFactory; +import org.apache.iotdb.it.env.EnvFactory; +import org.apache.iotdb.itbase.category.ClusterIT; +import org.apache.iotdb.itbase.category.LocalStandaloneIT; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.experimental.categories.Category; + +/** Let One chunk has more than one page. */ +@Category({LocalStandaloneIT.class, ClusterIT.class}) +public class IoTDBRawQueryWithoutValueFilter2IT extends IoTDBRawQueryWithoutValueFilterIT { + + private static int numOfPointsPerPage; + + @BeforeClass + public static void setUp() throws Exception { + enableSeqSpaceCompaction = ConfigFactory.getConfig().isEnableSeqSpaceCompaction(); + enableUnseqSpaceCompaction = ConfigFactory.getConfig().isEnableUnseqSpaceCompaction(); + enableCrossSpaceCompaction = ConfigFactory.getConfig().isEnableCrossSpaceCompaction(); + numOfPointsPerPage = ConfigFactory.getConfig().getMaxNumberOfPointsInPage(); + ConfigFactory.getConfig().setEnableSeqSpaceCompaction(false); + ConfigFactory.getConfig().setEnableUnseqSpaceCompaction(false); + ConfigFactory.getConfig().setEnableCrossSpaceCompaction(false); + ConfigFactory.getConfig().setMaxNumberOfPointsInPage(3); + EnvFactory.getEnv().initBeforeClass(); + AlignedWriteUtil.insertData(); + } + + @AfterClass + public static void tearDown() throws Exception { + EnvFactory.getEnv().cleanAfterClass(); + ConfigFactory.getConfig().setEnableSeqSpaceCompaction(enableSeqSpaceCompaction); + ConfigFactory.getConfig().setEnableUnseqSpaceCompaction(enableUnseqSpaceCompaction); + ConfigFactory.getConfig().setEnableCrossSpaceCompaction(enableCrossSpaceCompaction); + ConfigFactory.getConfig().setMaxNumberOfPointsInPage(numOfPointsPerPage); + } +} diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBRawQueryWithoutValueFilter3IT.java b/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBRawQueryWithoutValueFilter3IT.java new file mode 100644 index 0000000000..32459823b6 --- /dev/null +++ b/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBRawQueryWithoutValueFilter3IT.java @@ -0,0 +1,58 @@ +/* + * 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.ConfigFactory; +import org.apache.iotdb.it.env.EnvFactory; +import org.apache.iotdb.itbase.category.ClusterIT; +import org.apache.iotdb.itbase.category.LocalStandaloneIT; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.experimental.categories.Category; + +/** Let One chunk has more than one page. */ +@Category({LocalStandaloneIT.class, ClusterIT.class}) +public class IoTDBRawQueryWithoutValueFilter3IT extends IoTDBRawQueryWithoutValueFilterIT { + + private static int numOfPointsPerPage; + + @BeforeClass + public static void setUp() throws Exception { + enableSeqSpaceCompaction = ConfigFactory.getConfig().isEnableSeqSpaceCompaction(); + enableUnseqSpaceCompaction = ConfigFactory.getConfig().isEnableUnseqSpaceCompaction(); + enableCrossSpaceCompaction = ConfigFactory.getConfig().isEnableCrossSpaceCompaction(); + numOfPointsPerPage = ConfigFactory.getConfig().getMaxNumberOfPointsInPage(); + ConfigFactory.getConfig().setEnableSeqSpaceCompaction(false); + ConfigFactory.getConfig().setEnableUnseqSpaceCompaction(false); + ConfigFactory.getConfig().setEnableCrossSpaceCompaction(false); + ConfigFactory.getConfig().setMaxNumberOfPointsInPage(2); + EnvFactory.getEnv().initBeforeClass(); + AlignedWriteUtil.insertData(); + } + + @AfterClass + public static void tearDown() throws Exception { + EnvFactory.getEnv().cleanAfterClass(); + ConfigFactory.getConfig().setEnableSeqSpaceCompaction(enableSeqSpaceCompaction); + ConfigFactory.getConfig().setEnableUnseqSpaceCompaction(enableUnseqSpaceCompaction); + ConfigFactory.getConfig().setEnableCrossSpaceCompaction(enableCrossSpaceCompaction); + ConfigFactory.getConfig().setMaxNumberOfPointsInPage(numOfPointsPerPage); + } +} diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBRawQueryWithoutValueFilterIT.java b/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBRawQueryWithoutValueFilterIT.java new file mode 100644 index 0000000000..57474233dd --- /dev/null +++ b/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBRawQueryWithoutValueFilterIT.java @@ -0,0 +1,581 @@ +/* + * 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.ConfigFactory; +import org.apache.iotdb.it.env.EnvFactory; +import org.apache.iotdb.itbase.category.ClusterIT; +import org.apache.iotdb.itbase.category.LocalStandaloneIT; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.HashMap; +import java.util.Map; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +@Category({LocalStandaloneIT.class, ClusterIT.class}) +public class IoTDBRawQueryWithoutValueFilterIT { + + protected static boolean enableSeqSpaceCompaction; + protected static boolean enableUnseqSpaceCompaction; + protected static boolean enableCrossSpaceCompaction; + + @BeforeClass + public static void setUp() throws Exception { + enableSeqSpaceCompaction = ConfigFactory.getConfig().isEnableSeqSpaceCompaction(); + enableUnseqSpaceCompaction = ConfigFactory.getConfig().isEnableUnseqSpaceCompaction(); + enableCrossSpaceCompaction = ConfigFactory.getConfig().isEnableCrossSpaceCompaction(); + ConfigFactory.getConfig().setEnableSeqSpaceCompaction(false); + ConfigFactory.getConfig().setEnableUnseqSpaceCompaction(false); + ConfigFactory.getConfig().setEnableCrossSpaceCompaction(false); + EnvFactory.getEnv().initBeforeClass(); + AlignedWriteUtil.insertData(); + } + + @AfterClass + public static void tearDown() throws Exception { + EnvFactory.getEnv().cleanAfterClass(); + ConfigFactory.getConfig().setEnableSeqSpaceCompaction(enableSeqSpaceCompaction); + ConfigFactory.getConfig().setEnableUnseqSpaceCompaction(enableUnseqSpaceCompaction); + ConfigFactory.getConfig().setEnableCrossSpaceCompaction(enableCrossSpaceCompaction); + } + + @Test + public void selectAllAlignedWithoutValueFilterTest() { + + String[] retArray = + new String[] { + "1,1.0,1,1,true,aligned_test1", + "2,2.0,2,2,null,aligned_test2", + "3,30000.0,null,30000,true,aligned_unseq_test3", + "4,4.0,4,null,true,aligned_test4", + "5,5.0,5,null,true,aligned_test5", + "6,6.0,6,6,true,null", + "7,7.0,7,7,false,aligned_test7", + "8,8.0,8,8,null,aligned_test8", + "9,9.0,9,9,false,aligned_test9", + "10,null,10,10,true,aligned_test10", + "11,11.0,11,11,null,null", + "12,12.0,12,12,null,null", + "13,130000.0,130000,130000,true,aligned_unseq_test13", + "14,14.0,14,14,null,null", + "15,15.0,15,15,null,null", + "16,16.0,16,16,null,null", + "17,17.0,17,17,null,null", + "18,18.0,18,18,null,null", + "19,19.0,19,19,null,null", + "20,20.0,20,20,null,null", + "21,null,null,21,true,null", + "22,null,null,22,true,null", + "23,230000.0,null,230000,false,null", + "24,null,null,24,true,null", + "25,null,null,25,true,null", + "26,null,null,26,false,null", + "27,null,null,27,false,null", + "28,null,null,28,false,null", + "29,null,null,29,false,null", + "30,null,null,30,false,null", + "31,null,31,null,null,aligned_test31", + "32,null,32,null,null,aligned_test32", + "33,null,33,null,null,aligned_test33", + "34,null,34,null,null,aligned_test34", + "35,null,35,null,null,aligned_test35", + "36,null,36,null,null,aligned_test36", + "37,null,37,null,null,aligned_test37", + "38,null,38,null,null,aligned_test38", + "39,null,39,null,null,aligned_test39", + "40,null,40,null,null,aligned_test40", + }; + + String[] columnNames = { + "root.sg1.d1.s1", "root.sg1.d1.s2", "root.sg1.d1.s3", "root.sg1.d1.s4", "root.sg1.d1.s5" + }; + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + + try (ResultSet resultSet = statement.executeQuery("select * from root.sg1.d1")) { + ResultSetMetaData resultSetMetaData = resultSet.getMetaData(); + Map<String, Integer> map = new HashMap<>(); + for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) { + map.put(resultSetMetaData.getColumnName(i), i); + } + assertEquals(columnNames.length + 1, resultSetMetaData.getColumnCount()); + int cnt = 0; + while (resultSet.next()) { + StringBuilder builder = new StringBuilder(); + builder.append(resultSet.getString(1)); + for (String columnName : columnNames) { + int index = map.get(columnName); + builder.append(",").append(resultSet.getString(index)); + } + assertEquals(retArray[cnt], builder.toString()); + cnt++; + } + assertEquals(retArray.length, cnt); + } + + } catch (SQLException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } + + @Test + public void selectAllAlignedAndNonAlignedTest() { + + String[] retArray = + new String[] { + "1,1.0,1,1,true,aligned_test1,1.0,1,1,true,non_aligned_test1", + "2,2.0,2,2,null,aligned_test2,2.0,2,2,null,non_aligned_test2", + "3,30000.0,null,30000,true,aligned_unseq_test3,3.0,null,3,false,non_aligned_test3", + "4,4.0,4,null,true,aligned_test4,4.0,4,null,true,non_aligned_test4", + "5,5.0,5,null,true,aligned_test5,5.0,5,null,true,non_aligned_test5", + "6,6.0,6,6,true,null,6.0,6,6,true,null", + "7,7.0,7,7,false,aligned_test7,7.0,7,7,false,non_aligned_test7", + "8,8.0,8,8,null,aligned_test8,8.0,8,8,null,non_aligned_test8", + "9,9.0,9,9,false,aligned_test9,9.0,9,9,false,non_aligned_test9", + "10,null,10,10,true,aligned_test10,null,10,10,true,non_aligned_test10", + "11,11.0,11,11,null,null,11.0,11,11,null,null", + "12,12.0,12,12,null,null,12.0,12,12,null,null", + "13,130000.0,130000,130000,true,aligned_unseq_test13,13.0,13,13,null,null", + "14,14.0,14,14,null,null,14.0,14,14,null,null", + "15,15.0,15,15,null,null,15.0,15,15,null,null", + "16,16.0,16,16,null,null,16.0,16,16,null,null", + "17,17.0,17,17,null,null,17.0,17,17,null,null", + "18,18.0,18,18,null,null,18.0,18,18,null,null", + "19,19.0,19,19,null,null,19.0,19,19,null,null", + "20,20.0,20,20,null,null,20.0,20,20,null,null", + "21,null,null,21,true,null,null,null,21,true,null", + "22,null,null,22,true,null,null,null,22,true,null", + "23,230000.0,null,230000,false,null,null,null,23,true,null", + "24,null,null,24,true,null,null,null,24,true,null", + "25,null,null,25,true,null,null,null,25,true,null", + "26,null,null,26,false,null,null,null,26,false,null", + "27,null,null,27,false,null,null,null,27,false,null", + "28,null,null,28,false,null,null,null,28,false,null", + "29,null,null,29,false,null,null,null,29,false,null", + "30,null,null,30,false,null,null,null,30,false,null", + "31,null,31,null,null,aligned_test31,null,31,null,null,non_aligned_test31", + "32,null,32,null,null,aligned_test32,null,32,null,null,non_aligned_test32", + "33,null,33,null,null,aligned_test33,null,33,null,null,non_aligned_test33", + "34,null,34,null,null,aligned_test34,null,34,null,null,non_aligned_test34", + "35,null,35,null,null,aligned_test35,null,35,null,null,non_aligned_test35", + "36,null,36,null,null,aligned_test36,null,36,null,null,non_aligned_test36", + "37,null,37,null,null,aligned_test37,null,37,null,null,non_aligned_test37", + "38,null,38,null,null,aligned_test38,null,38,null,null,non_aligned_test38", + "39,null,39,null,null,aligned_test39,null,39,null,null,non_aligned_test39", + "40,null,40,null,null,aligned_test40,null,40,null,null,non_aligned_test40", + }; + + String[] columnNames = { + "root.sg1.d1.s1", + "root.sg1.d1.s2", + "root.sg1.d1.s3", + "root.sg1.d1.s4", + "root.sg1.d1.s5", + "root.sg1.d2.s1", + "root.sg1.d2.s2", + "root.sg1.d2.s3", + "root.sg1.d2.s4", + "root.sg1.d2.s5" + }; + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + + try (ResultSet resultSet = statement.executeQuery("select * from root.sg1.*")) { + ResultSetMetaData resultSetMetaData = resultSet.getMetaData(); + Map<String, Integer> map = new HashMap<>(); + for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) { + map.put(resultSetMetaData.getColumnName(i), i); + } + assertEquals(columnNames.length + 1, resultSetMetaData.getColumnCount()); + int cnt = 0; + while (resultSet.next()) { + StringBuilder builder = new StringBuilder(); + builder.append(resultSet.getString(1)); + for (String columnName : columnNames) { + int index = map.get(columnName); + builder.append(",").append(resultSet.getString(index)); + } + assertEquals(retArray[cnt], builder.toString()); + cnt++; + } + assertEquals(retArray.length, cnt); + } + + } catch (SQLException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } + + @Test + public void selectAllAlignedWithTimeFilterTest() { + + String[] retArray = + new String[] { + "9,9.0,9,9,false,aligned_test9", + "10,null,10,10,true,aligned_test10", + "11,11.0,11,11,null,null", + "12,12.0,12,12,null,null", + "13,130000.0,130000,130000,true,aligned_unseq_test13", + "14,14.0,14,14,null,null", + "15,15.0,15,15,null,null", + "16,16.0,16,16,null,null", + "17,17.0,17,17,null,null", + "18,18.0,18,18,null,null", + "19,19.0,19,19,null,null", + "20,20.0,20,20,null,null", + "21,null,null,21,true,null", + "22,null,null,22,true,null", + "23,230000.0,null,230000,false,null", + "24,null,null,24,true,null", + "25,null,null,25,true,null", + "26,null,null,26,false,null", + "27,null,null,27,false,null", + "28,null,null,28,false,null", + "29,null,null,29,false,null", + "30,null,null,30,false,null", + "31,null,31,null,null,aligned_test31", + "32,null,32,null,null,aligned_test32", + "33,null,33,null,null,aligned_test33", + }; + + String[] columnNames = { + "root.sg1.d1.s1", "root.sg1.d1.s2", "root.sg1.d1.s3", "root.sg1.d1.s4", "root.sg1.d1.s5" + }; + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + + try (ResultSet resultSet = + statement.executeQuery("select * from root.sg1.d1 where time >= 9 and time <= 33")) { + ResultSetMetaData resultSetMetaData = resultSet.getMetaData(); + Map<String, Integer> map = new HashMap<>(); + for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) { + map.put(resultSetMetaData.getColumnName(i), i); + } + assertEquals(columnNames.length + 1, resultSetMetaData.getColumnCount()); + int cnt = 0; + while (resultSet.next()) { + StringBuilder builder = new StringBuilder(); + builder.append(resultSet.getString(1)); + for (String columnName : columnNames) { + int index = map.get(columnName); + builder.append(",").append(resultSet.getString(index)); + } + assertEquals(retArray[cnt], builder.toString()); + cnt++; + } + assertEquals(retArray.length, cnt); + } + + } catch (SQLException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } + + @Test + public void selectSomeAlignedWithoutValueFilterTest1() { + + String[] retArray = + new String[] { + "1,1.0,true,aligned_test1", + "2,2.0,null,aligned_test2", + "3,30000.0,true,aligned_unseq_test3", + "4,4.0,true,aligned_test4", + "5,5.0,true,aligned_test5", + "6,6.0,true,null", + "7,7.0,false,aligned_test7", + "8,8.0,null,aligned_test8", + "9,9.0,false,aligned_test9", + "10,null,true,aligned_test10", + "11,11.0,null,null", + "12,12.0,null,null", + "13,130000.0,true,aligned_unseq_test13", + "14,14.0,null,null", + "15,15.0,null,null", + "16,16.0,null,null", + "17,17.0,null,null", + "18,18.0,null,null", + "19,19.0,null,null", + "20,20.0,null,null", + "21,null,true,null", + "22,null,true,null", + "23,230000.0,false,null", + "24,null,true,null", + "25,null,true,null", + "26,null,false,null", + "27,null,false,null", + "28,null,false,null", + "29,null,false,null", + "30,null,false,null", + "31,null,null,aligned_test31", + "32,null,null,aligned_test32", + "33,null,null,aligned_test33", + "34,null,null,aligned_test34", + "35,null,null,aligned_test35", + "36,null,null,aligned_test36", + "37,null,null,aligned_test37", + "38,null,null,aligned_test38", + "39,null,null,aligned_test39", + "40,null,null,aligned_test40", + }; + + String[] columnNames = {"root.sg1.d1.s1", "root.sg1.d1.s4", "root.sg1.d1.s5"}; + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + + try (ResultSet resultSet = statement.executeQuery("select s1,s4,s5 from root.sg1.d1")) { + ResultSetMetaData resultSetMetaData = resultSet.getMetaData(); + Map<String, Integer> map = new HashMap<>(); + for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) { + map.put(resultSetMetaData.getColumnName(i), i); + } + assertEquals(columnNames.length + 1, resultSetMetaData.getColumnCount()); + int cnt = 0; + while (resultSet.next()) { + StringBuilder builder = new StringBuilder(); + builder.append(resultSet.getString(1)); + for (String columnName : columnNames) { + int index = map.get(columnName); + builder.append(",").append(resultSet.getString(index)); + } + assertEquals(retArray[cnt], builder.toString()); + cnt++; + } + assertEquals(retArray.length, cnt); + } + + } catch (SQLException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } + + @Test + public void selectSomeAlignedWithoutValueFilterTest2() { + + String[] retArray = + new String[] { + "1,1.0,true", + "2,2.0,null", + "3,30000.0,true", + "4,4.0,true", + "5,5.0,true", + "6,6.0,true", + "7,7.0,false", + "8,8.0,null", + "9,9.0,false", + "10,null,true", + "11,11.0,null", + "12,12.0,null", + "13,130000.0,true", + "14,14.0,null", + "15,15.0,null", + "16,16.0,null", + "17,17.0,null", + "18,18.0,null", + "19,19.0,null", + "20,20.0,null", + "21,null,true", + "22,null,true", + "23,230000.0,false", + "24,null,true", + "25,null,true", + "26,null,false", + "27,null,false", + "28,null,false", + "29,null,false", + "30,null,false", + }; + + String[] columnNames = {"root.sg1.d1.s1", "root.sg1.d1.s4"}; + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + + try (ResultSet resultSet = statement.executeQuery("select s1,s4 from root.sg1.d1")) { + ResultSetMetaData resultSetMetaData = resultSet.getMetaData(); + Map<String, Integer> map = new HashMap<>(); + for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) { + map.put(resultSetMetaData.getColumnName(i), i); + } + assertEquals(columnNames.length + 1, resultSetMetaData.getColumnCount()); + int cnt = 0; + while (resultSet.next()) { + StringBuilder builder = new StringBuilder(); + builder.append(resultSet.getString(1)); + for (String columnName : columnNames) { + int index = map.get(columnName); + builder.append(",").append(resultSet.getString(index)); + } + assertEquals(retArray[cnt], builder.toString()); + cnt++; + } + assertEquals(retArray.length, cnt); + } + + } catch (SQLException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } + + @Test + public void selectSomeAlignedWithTimeFilterTest() { + + String[] retArray = + new String[] { + "16,16.0,null,null", + "17,17.0,null,null", + "18,18.0,null,null", + "19,19.0,null,null", + "20,20.0,null,null", + "21,null,true,null", + "22,null,true,null", + "23,230000.0,false,null", + "24,null,true,null", + "25,null,true,null", + "26,null,false,null", + "27,null,false,null", + "28,null,false,null", + "29,null,false,null", + "30,null,false,null", + "31,null,null,aligned_test31", + "32,null,null,aligned_test32", + "33,null,null,aligned_test33", + "34,null,null,aligned_test34", + }; + + String[] columnNames = {"root.sg1.d1.s1", "root.sg1.d1.s4", "root.sg1.d1.s5"}; + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + + try (ResultSet resultSet = + statement.executeQuery( + "select s1,s4,s5 from root.sg1.d1 where time >= 16 and time <= 34")) { + ResultSetMetaData resultSetMetaData = resultSet.getMetaData(); + Map<String, Integer> map = new HashMap<>(); + for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) { + map.put(resultSetMetaData.getColumnName(i), i); + } + assertEquals(columnNames.length + 1, resultSetMetaData.getColumnCount()); + int cnt = 0; + while (resultSet.next()) { + StringBuilder builder = new StringBuilder(); + builder.append(resultSet.getString(1)); + for (String columnName : columnNames) { + int index = map.get(columnName); + builder.append(",").append(resultSet.getString(index)); + } + assertEquals(retArray[cnt], builder.toString()); + cnt++; + } + assertEquals(retArray.length, cnt); + } + + } catch (SQLException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } + + @Test + public void selectSomeAlignedAndNonAlignedWithTimeFilterTest() { + + String[] retArray = + new String[] { + "16,null,null,16.0,null,null,16.0", + "17,null,null,17.0,null,null,17.0", + "18,null,null,18.0,null,null,18.0", + "19,null,null,19.0,null,null,19.0", + "20,null,null,20.0,null,null,20.0", + "21,null,true,null,null,true,null", + "22,null,true,null,null,true,null", + "23,null,false,null,null,true,230000.0", + "24,null,true,null,null,true,null", + "25,null,true,null,null,true,null", + "26,null,false,null,null,false,null", + "27,null,false,null,null,false,null", + "28,null,false,null,null,false,null", + "29,null,false,null,null,false,null", + "30,null,false,null,null,false,null", + "31,non_aligned_test31,null,null,aligned_test31,null,null", + "32,non_aligned_test32,null,null,aligned_test32,null,null", + "33,non_aligned_test33,null,null,aligned_test33,null,null", + "34,non_aligned_test34,null,null,aligned_test34,null,null", + }; + + String[] columnNames = { + "root.sg1.d2.s5", + "root.sg1.d1.s4", + "root.sg1.d2.s1", + "root.sg1.d1.s5", + "root.sg1.d2.s4", + "root.sg1.d1.s1" + }; + + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + + try (ResultSet resultSet = + statement.executeQuery( + "select d2.s5, d1.s4, d2.s1, d1.s5, d2.s4, d1.s1 from root.sg1 where time >= 16 and time <= 34")) { + ResultSetMetaData resultSetMetaData = resultSet.getMetaData(); + Map<String, Integer> map = new HashMap<>(); + for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) { + map.put(resultSetMetaData.getColumnName(i), i); + } + assertEquals(columnNames.length + 1, resultSetMetaData.getColumnCount()); + int cnt = 0; + while (resultSet.next()) { + StringBuilder builder = new StringBuilder(); + builder.append(resultSet.getString(1)); + for (String columnName : columnNames) { + int index = map.get(columnName); + builder.append(",").append(resultSet.getString(index)); + } + assertEquals(retArray[cnt], builder.toString()); + cnt++; + } + assertEquals(retArray.length, cnt); + } + + } catch (SQLException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } +} diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/env/StandaloneEnvConfig.java b/integration-test/src/test/java/org/apache/iotdb/db/it/env/StandaloneEnvConfig.java index 49d6500711..2e32fffe6c 100644 --- a/integration-test/src/test/java/org/apache/iotdb/db/it/env/StandaloneEnvConfig.java +++ b/integration-test/src/test/java/org/apache/iotdb/db/it/env/StandaloneEnvConfig.java @@ -25,41 +25,49 @@ import org.apache.iotdb.tsfile.common.conf.TSFileDescriptor; /** This class is used by ConfigFactory with using reflection. */ public class StandaloneEnvConfig implements BaseConfig { + @Override public BaseConfig setMaxNumberOfPointsInPage(int maxNumberOfPointsInPage) { TSFileDescriptor.getInstance().getConfig().setMaxNumberOfPointsInPage(maxNumberOfPointsInPage); return this; } + @Override public BaseConfig setPageSizeInByte(int pageSizeInByte) { TSFileDescriptor.getInstance().getConfig().setPageSizeInByte(pageSizeInByte); return this; } + @Override public BaseConfig setGroupSizeInByte(int groupSizeInByte) { TSFileDescriptor.getInstance().getConfig().setGroupSizeInByte(groupSizeInByte); return this; } + @Override public BaseConfig setMemtableSizeThreshold(long memtableSizeThreshold) { IoTDBDescriptor.getInstance().getConfig().setMemtableSizeThreshold(memtableSizeThreshold); return this; } + @Override public BaseConfig setDataRegionNum(int dataRegionNum) { IoTDBDescriptor.getInstance().getConfig().setDataRegionNum(dataRegionNum); return this; } + @Override public BaseConfig setPartitionInterval(long partitionInterval) { IoTDBDescriptor.getInstance().getConfig().setPartitionInterval(partitionInterval); return this; } + @Override public BaseConfig setCompressor(String compressor) { TSFileDescriptor.getInstance().getConfig().setCompressor(compressor); return this; } + @Override public BaseConfig setMaxQueryDeduplicatedPathNum(int maxQueryDeduplicatedPathNum) { IoTDBDescriptor.getInstance() .getConfig() @@ -67,6 +75,7 @@ public class StandaloneEnvConfig implements BaseConfig { return this; } + @Override public BaseConfig setRpcThriftCompressionEnable(boolean rpcThriftCompressionEnable) { IoTDBDescriptor.getInstance() .getConfig() @@ -74,6 +83,7 @@ public class StandaloneEnvConfig implements BaseConfig { return this; } + @Override public BaseConfig setRpcAdvancedCompressionEnable(boolean rpcAdvancedCompressionEnable) { IoTDBDescriptor.getInstance() .getConfig() @@ -81,11 +91,13 @@ public class StandaloneEnvConfig implements BaseConfig { return this; } + @Override public BaseConfig setEnablePartition(boolean enablePartition) { IoTDBDescriptor.getInstance().getConfig().setEnablePartition(enablePartition); return this; } + @Override public BaseConfig setUdfCollectorMemoryBudgetInMB(float udfCollectorMemoryBudgetInMB) { IoTDBDescriptor.getInstance() .getConfig() @@ -93,6 +105,7 @@ public class StandaloneEnvConfig implements BaseConfig { return this; } + @Override public BaseConfig setUdfTransformerMemoryBudgetInMB(float udfTransformerMemoryBudgetInMB) { IoTDBDescriptor.getInstance() .getConfig() @@ -100,6 +113,7 @@ public class StandaloneEnvConfig implements BaseConfig { return this; } + @Override public BaseConfig setUdfReaderMemoryBudgetInMB(float udfReaderMemoryBudgetInMB) { IoTDBDescriptor.getInstance() .getConfig() @@ -107,11 +121,13 @@ public class StandaloneEnvConfig implements BaseConfig { return this; } + @Override public BaseConfig setEnableSeqSpaceCompaction(boolean enableSeqSpaceCompaction) { IoTDBDescriptor.getInstance().getConfig().setEnableSeqSpaceCompaction(enableSeqSpaceCompaction); return this; } + @Override public BaseConfig setEnableUnseqSpaceCompaction(boolean enableUnseqSpaceCompaction) { IoTDBDescriptor.getInstance() .getConfig() @@ -119,6 +135,7 @@ public class StandaloneEnvConfig implements BaseConfig { return this; } + @Override public BaseConfig setEnableCrossSpaceCompaction(boolean enableCrossSpaceCompaction) { IoTDBDescriptor.getInstance() .getConfig() @@ -126,11 +143,13 @@ public class StandaloneEnvConfig implements BaseConfig { return this; } + @Override public BaseConfig setEnableIDTable(boolean isEnableIDTable) { IoTDBDescriptor.getInstance().getConfig().setEnableIDTable(isEnableIDTable); return this; } + @Override public BaseConfig setDeviceIDTransformationMethod(String deviceIDTransformationMethod) { IoTDBDescriptor.getInstance() .getConfig() @@ -138,8 +157,40 @@ public class StandaloneEnvConfig implements BaseConfig { return this; } + @Override public BaseConfig setAutoCreateSchemaEnabled(boolean enableAutoCreateSchema) { IoTDBDescriptor.getInstance().getConfig().setAutoCreateSchemaEnabled(enableAutoCreateSchema); return this; } + + @Override + public BaseConfig setEnableLastCache(boolean lastCacheEnable) { + IoTDBDescriptor.getInstance().getConfig().setEnableLastCache(lastCacheEnable); + return this; + } + + @Override + public boolean isLastCacheEnabled() { + return IoTDBDescriptor.getInstance().getConfig().isLastCacheEnabled(); + } + + @Override + public boolean isEnableSeqSpaceCompaction() { + return IoTDBDescriptor.getInstance().getConfig().isEnableSeqSpaceCompaction(); + } + + @Override + public boolean isEnableUnseqSpaceCompaction() { + return IoTDBDescriptor.getInstance().getConfig().isEnableUnseqSpaceCompaction(); + } + + @Override + public boolean isEnableCrossSpaceCompaction() { + return IoTDBDescriptor.getInstance().getConfig().isEnableCrossSpaceCompaction(); + } + + @Override + public int getMaxNumberOfPointsInPage() { + return TSFileDescriptor.getInstance().getConfig().getMaxNumberOfPointsInPage(); + } } diff --git a/server/src/main/java/org/apache/iotdb/db/query/reader/chunk/MemAlignedPageReader.java b/server/src/main/java/org/apache/iotdb/db/query/reader/chunk/MemAlignedPageReader.java index 092715404d..41f4d7c1fd 100644 --- a/server/src/main/java/org/apache/iotdb/db/query/reader/chunk/MemAlignedPageReader.java +++ b/server/src/main/java/org/apache/iotdb/db/query/reader/chunk/MemAlignedPageReader.java @@ -26,7 +26,7 @@ import org.apache.iotdb.tsfile.read.common.BatchDataFactory; import org.apache.iotdb.tsfile.read.common.block.TsBlock; import org.apache.iotdb.tsfile.read.common.block.TsBlockBuilder; import org.apache.iotdb.tsfile.read.common.block.column.Column; -import org.apache.iotdb.tsfile.read.common.block.column.TimeColumn; +import org.apache.iotdb.tsfile.read.common.block.column.ColumnBuilder; import org.apache.iotdb.tsfile.read.filter.basic.Filter; import org.apache.iotdb.tsfile.read.filter.operator.AndFilter; import org.apache.iotdb.tsfile.read.reader.IAlignedPageReader; @@ -91,42 +91,46 @@ public class MemAlignedPageReader implements IPageReader, IAlignedPageReader { boolean[] satisfyInfo = new boolean[tsBlock.getPositionCount()]; - // Time column and first value column - // if all the sub sensors' value are null in current time - // or current row is not satisfied with the filter, just discard it - // currently, if it's a value filter, it will only - // accept AlignedPath with only one sub sensor - TimeColumn timeColumn = tsBlock.getTimeColumn(); - Column valueColumn = tsBlock.getColumn(0); for (int row = 0; row < tsBlock.getPositionCount(); row++) { long time = tsBlock.getTimeByIndex(row); - Object value = tsBlock.getColumn(0).getObject(row); - boolean valueIsNull = tsBlock.getColumn(0).isNull(row); - if ((valueFilter == null || !valueIsNull && valueFilter.satisfy(time, value))) { - builder.getTimeColumnBuilder().write(timeColumn, row); - if (!valueIsNull) { - builder.getColumnBuilder(0).write(valueColumn, row); - } else { - builder.getColumnBuilder(0).appendNull(); - } + // ValueFilter in MPP will only contain time filter now. + if ((valueFilter == null || valueFilter.satisfy(time, null))) { satisfyInfo[row] = true; - builder.declarePosition(); } } + boolean[] hasValue = new boolean[tsBlock.getPositionCount()]; // other value column - for (int column = 1; column < tsBlock.getValueColumnCount(); column++) { - valueColumn = tsBlock.getColumn(column); + for (int column = 0; column < tsBlock.getValueColumnCount(); column++) { + Column valueColumn = tsBlock.getColumn(column); + for (int row = 0; row < tsBlock.getPositionCount(); row++) { + hasValue[row] = hasValue[row] || !valueColumn.isNull(row); + } + } + + // build time column + for (int row = 0; row < tsBlock.getPositionCount(); row++) { + if (satisfyInfo[row] && hasValue[row]) { + builder.getTimeColumnBuilder().writeLong(tsBlock.getTimeByIndex(row)); + builder.declarePosition(); + } + } + + // build value column + for (int column = 0; column < tsBlock.getValueColumnCount(); column++) { + Column valueColumn = tsBlock.getColumn(column); + ColumnBuilder valueBuilder = builder.getColumnBuilder(column); for (int row = 0; row < tsBlock.getPositionCount(); row++) { - if (satisfyInfo[row]) { - if (!tsBlock.getColumn(column).isNull(row)) { - builder.getColumnBuilder(column).write(valueColumn, row); + if (satisfyInfo[row] && hasValue[row]) { + if (!valueColumn.isNull(row)) { + valueBuilder.write(valueColumn, row); } else { - builder.getColumnBuilder(column).appendNull(); + valueBuilder.appendNull(); } } } } + return builder.build(); }
