This is an automated email from the ASF dual-hosted git repository. shuwenwei pushed a commit to branch ignoreMemChunksWhoseDataTypeNotMatch in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit aaba14916ea4b15501f1efd75647545015bbf9f3 Author: shuwenwei <[email protected]> AuthorDate: Thu May 29 18:57:52 2025 +0800 ignore mem chunks whose data type is not matched --- ...oTDBTableViewQueryWithNotMatchedDataTypeIT.java | 102 +++++++++++++++++++++ .../schemaregion/utils/ResourceByPathUtils.java | 17 ++++ 2 files changed, 119 insertions(+) diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/view/recent/IoTDBTableViewQueryWithNotMatchedDataTypeIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/view/recent/IoTDBTableViewQueryWithNotMatchedDataTypeIT.java new file mode 100644 index 00000000000..1e342a13a4a --- /dev/null +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/view/recent/IoTDBTableViewQueryWithNotMatchedDataTypeIT.java @@ -0,0 +1,102 @@ +/* + * 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.relational.it.query.view.recent; + +import org.apache.iotdb.isession.ITableSession; +import org.apache.iotdb.isession.SessionDataSet; +import org.apache.iotdb.it.env.EnvFactory; +import org.apache.iotdb.itbase.category.TableClusterIT; +import org.apache.iotdb.itbase.category.TableLocalStandaloneIT; +import org.apache.iotdb.rpc.IoTDBConnectionException; +import org.apache.iotdb.rpc.StatementExecutionException; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import java.util.Arrays; +import java.util.Collection; + +import static org.apache.iotdb.db.it.utils.TestUtils.prepareData; +import static org.apache.iotdb.db.it.utils.TestUtils.prepareTableData; + +@RunWith(Parameterized.class) +@Category({TableLocalStandaloneIT.class, TableClusterIT.class}) +public class IoTDBTableViewQueryWithNotMatchedDataTypeIT { + + protected static final String DATABASE_NAME = "test"; + + private final boolean aligned; + + protected static final String[] createTreeAlignedDataSqls = + new String[] { + "CREATE ALIGNED TIMESERIES root.db.battery.b1(current FLOAT)", + "INSERT INTO root.db.battery.b1(time, current) aligned values (1, 1)", + }; + + protected static final String[] createTreeNonAlignedDataSqls = + new String[] { + "CREATE TIMESERIES root.db.battery.b1.current FLOAT", + "INSERT INTO root.db.battery.b1(time, current) values (1, 1)", + }; + + protected static String[] createTableSqls = { + "create database " + DATABASE_NAME, + "use " + DATABASE_NAME, + "CREATE VIEW view1 (battery TAG, current BLOB FIELD) as root.db.battery.**", + }; + + public IoTDBTableViewQueryWithNotMatchedDataTypeIT(boolean aligned) { + this.aligned = aligned; + } + + @Parameterized.Parameters(name = "aligned={0}") + public static Collection<Object[]> data() { + return Arrays.asList(new Object[][] {{true}, {false}}); + } + + @Before + public void setUp() throws Exception { + EnvFactory.getEnv().getConfig().getCommonConfig().setSortBufferSize(128 * 1024); + EnvFactory.getEnv().getConfig().getCommonConfig().setMaxTsBlockSizeInByte(4 * 1024); + EnvFactory.getEnv().initClusterEnvironment(); + prepareData(aligned ? createTreeAlignedDataSqls : createTreeNonAlignedDataSqls); + prepareTableData(createTableSqls); + } + + @After + public void tearDown() throws Exception { + EnvFactory.getEnv().cleanClusterEnvironment(); + } + + @Test + public void test() throws IoTDBConnectionException, StatementExecutionException { + try (ITableSession session = EnvFactory.getEnv().getTableSessionConnection()) { + session.executeNonQueryStatement("USE " + DATABASE_NAME); + SessionDataSet sessionDataSet = session.executeQueryStatement("select * from view1"); + Assert.assertFalse(sessionDataSet.hasNext()); + sessionDataSet.close(); + } + } +} diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/utils/ResourceByPathUtils.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/utils/ResourceByPathUtils.java index b0c4daa85c2..e5288adc76d 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/utils/ResourceByPathUtils.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/utils/ResourceByPathUtils.java @@ -66,6 +66,7 @@ import java.io.IOException; import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -317,6 +318,18 @@ class AlignedResourceByPathUtils extends ResourceByPathUtils { } AlignedWritableMemChunk alignedMemChunk = ((AlignedWritableMemChunkGroup) memTableMap.get(deviceID)).getAlignedMemChunk(); + + // check If data type matches + Map<String, TSDataType> dataTypeMap = new HashMap<>(alignedMemChunk.getSchemaList().size()); + for (IMeasurementSchema schema : alignedMemChunk.getSchemaList()) { + dataTypeMap.put(schema.getMeasurementName(), schema.getType()); + } + for (IMeasurementSchema schema : alignedFullPath.getSchemaList()) { + TSDataType dataTypeInMemChunk = dataTypeMap.get(schema.getMeasurementName()); + if (dataTypeInMemChunk != null && dataTypeInMemChunk != schema.getType()) { + return null; + } + } // only need to do this check for tree model if (context.isIgnoreAllNullRows()) { boolean containsMeasurement = false; @@ -514,6 +527,10 @@ class MeasurementResourceByPathUtils extends ResourceByPathUtils { } IWritableMemChunk memChunk = memTableMap.get(deviceID).getMemChunkMap().get(fullPath.getMeasurement()); + // check If data type matches + if (memChunk.getSchema().getType() != fullPath.getMeasurementSchema().getType()) { + return null; + } // prepare TVList for query. It should clone TVList if necessary. Map<TVList, Integer> tvListQueryMap = prepareTvListMapForQuery(context, memChunk, modsToMemtable == null, globalTimeFilter);
