Skip to content

Commit 0996da2

Browse files
authored
Ignore mem chunks whose data type is not matched
1 parent 7ad757f commit 0996da2

File tree

4 files changed

+121
-2
lines changed

4 files changed

+121
-2
lines changed

integration-test/src/test/java/org/apache/iotdb/relational/it/query/view/old/alignbydevice/IoTDBAlignByDeviceTableViewIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class IoTDBAlignByDeviceTableViewIT {
4747
new String[] {
4848
"CREATE DATABASE " + DATABASE_NAME,
4949
"USE " + DATABASE_NAME,
50-
"create view vehicle(device_id STRING TAG, s0 INT32 FIELD, s1 INT64 FIELD, s2 FLOAT FIELD, s3 STRING FIELD, s4 BOOLEAN FIELD) as root.vehicle.**"
50+
"create view vehicle(device_id STRING TAG, s0 INT32 FIELD, s1 INT64 FIELD, s2 FLOAT FIELD, s3 TEXT FIELD, s4 BOOLEAN FIELD) as root.vehicle.**"
5151
};
5252

5353
private static final String[] sqls =

integration-test/src/test/java/org/apache/iotdb/relational/it/query/view/old/alignbydevice/IoTDBOrderByWithAlignByDeviceTableViewIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ protected static void insertData() {
190190
"create view weather(city STRING TAG, precipitation INT64 FIELD, temperature DOUBLE FIELD) as root.weather.**");
191191

192192
statement.execute(
193-
"create view optimize(plant_id STRING TAG, device_id STRING TAG, temperature DOUBLE FIELD, status BOOLEAN FIELD, hardware STRING FIELD) as root.ln.**");
193+
"create view optimize(plant_id STRING TAG, device_id STRING TAG, temperature DOUBLE FIELD, status BOOLEAN FIELD, hardware TEXT FIELD) as root.ln.**");
194194

195195
} catch (Exception e) {
196196
e.printStackTrace();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.iotdb.relational.it.query.view.recent;
21+
22+
import org.apache.iotdb.isession.ITableSession;
23+
import org.apache.iotdb.isession.SessionDataSet;
24+
import org.apache.iotdb.it.env.EnvFactory;
25+
import org.apache.iotdb.itbase.category.TableClusterIT;
26+
import org.apache.iotdb.itbase.category.TableLocalStandaloneIT;
27+
import org.apache.iotdb.rpc.IoTDBConnectionException;
28+
import org.apache.iotdb.rpc.StatementExecutionException;
29+
30+
import org.junit.After;
31+
import org.junit.Assert;
32+
import org.junit.Before;
33+
import org.junit.Test;
34+
import org.junit.experimental.categories.Category;
35+
import org.junit.runner.RunWith;
36+
import org.junit.runners.Parameterized;
37+
38+
import java.util.Arrays;
39+
import java.util.Collection;
40+
41+
import static org.apache.iotdb.db.it.utils.TestUtils.prepareData;
42+
import static org.apache.iotdb.db.it.utils.TestUtils.prepareTableData;
43+
44+
@RunWith(Parameterized.class)
45+
@Category({TableLocalStandaloneIT.class, TableClusterIT.class})
46+
public class IoTDBTableViewQueryWithNotMatchedDataTypeIT {
47+
48+
protected static final String DATABASE_NAME = "test";
49+
50+
private final boolean aligned;
51+
52+
protected static final String[] createTreeAlignedDataSqls =
53+
new String[] {
54+
"CREATE ALIGNED TIMESERIES root.db.battery.b1(current FLOAT)",
55+
"INSERT INTO root.db.battery.b1(time, current) aligned values (1, 1)",
56+
};
57+
58+
protected static final String[] createTreeNonAlignedDataSqls =
59+
new String[] {
60+
"CREATE TIMESERIES root.db.battery.b1.current FLOAT",
61+
"INSERT INTO root.db.battery.b1(time, current) values (1, 1)",
62+
};
63+
64+
protected static String[] createTableSqls = {
65+
"create database " + DATABASE_NAME,
66+
"use " + DATABASE_NAME,
67+
"CREATE VIEW view1 (battery TAG, current BLOB FIELD) as root.db.battery.**",
68+
};
69+
70+
public IoTDBTableViewQueryWithNotMatchedDataTypeIT(boolean aligned) {
71+
this.aligned = aligned;
72+
}
73+
74+
@Parameterized.Parameters(name = "aligned={0}")
75+
public static Collection<Object[]> data() {
76+
return Arrays.asList(new Object[][] {{true}, {false}});
77+
}
78+
79+
@Before
80+
public void setUp() throws Exception {
81+
EnvFactory.getEnv().getConfig().getCommonConfig().setSortBufferSize(128 * 1024);
82+
EnvFactory.getEnv().getConfig().getCommonConfig().setMaxTsBlockSizeInByte(4 * 1024);
83+
EnvFactory.getEnv().initClusterEnvironment();
84+
prepareData(aligned ? createTreeAlignedDataSqls : createTreeNonAlignedDataSqls);
85+
prepareTableData(createTableSqls);
86+
}
87+
88+
@After
89+
public void tearDown() throws Exception {
90+
EnvFactory.getEnv().cleanClusterEnvironment();
91+
}
92+
93+
@Test
94+
public void test() throws IoTDBConnectionException, StatementExecutionException {
95+
try (ITableSession session = EnvFactory.getEnv().getTableSessionConnection()) {
96+
session.executeNonQueryStatement("USE " + DATABASE_NAME);
97+
SessionDataSet sessionDataSet = session.executeQueryStatement("select * from view1");
98+
Assert.assertFalse(sessionDataSet.hasNext());
99+
sessionDataSet.close();
100+
}
101+
}
102+
}

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/utils/ResourceByPathUtils.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
import java.io.Serializable;
6767
import java.util.ArrayList;
6868
import java.util.Collections;
69+
import java.util.HashMap;
6970
import java.util.LinkedHashMap;
7071
import java.util.List;
7172
import java.util.Map;
@@ -317,6 +318,18 @@ public ReadOnlyMemChunk getReadOnlyMemChunkFromMemTable(
317318
}
318319
AlignedWritableMemChunk alignedMemChunk =
319320
((AlignedWritableMemChunkGroup) memTableMap.get(deviceID)).getAlignedMemChunk();
321+
322+
// check If data type matches
323+
Map<String, TSDataType> dataTypeMap = new HashMap<>(alignedMemChunk.getSchemaList().size());
324+
for (IMeasurementSchema schema : alignedMemChunk.getSchemaList()) {
325+
dataTypeMap.put(schema.getMeasurementName(), schema.getType());
326+
}
327+
for (IMeasurementSchema schema : alignedFullPath.getSchemaList()) {
328+
TSDataType dataTypeInMemChunk = dataTypeMap.get(schema.getMeasurementName());
329+
if (dataTypeInMemChunk != null && dataTypeInMemChunk != schema.getType()) {
330+
return null;
331+
}
332+
}
320333
// only need to do this check for tree model
321334
if (context.isIgnoreAllNullRows()) {
322335
boolean containsMeasurement = false;
@@ -514,6 +527,10 @@ public ReadOnlyMemChunk getReadOnlyMemChunkFromMemTable(
514527
}
515528
IWritableMemChunk memChunk =
516529
memTableMap.get(deviceID).getMemChunkMap().get(fullPath.getMeasurement());
530+
// check If data type matches
531+
if (memChunk.getSchema().getType() != fullPath.getMeasurementSchema().getType()) {
532+
return null;
533+
}
517534
// prepare TVList for query. It should clone TVList if necessary.
518535
Map<TVList, Integer> tvListQueryMap =
519536
prepareTvListMapForQuery(context, memChunk, modsToMemtable == null, globalTimeFilter);

0 commit comments

Comments
 (0)