Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class IoTDBAlignByDeviceTableViewIT {
new String[] {
"CREATE DATABASE " + DATABASE_NAME,
"USE " + DATABASE_NAME,
"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.**"
"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.**"
};

private static final String[] sqls =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ protected static void insertData() {
"create view weather(city STRING TAG, precipitation INT64 FIELD, temperature DOUBLE FIELD) as root.weather.**");

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

} catch (Exception e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
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;
Expand Down Expand Up @@ -317,6 +318,18 @@ public ReadOnlyMemChunk getReadOnlyMemChunkFromMemTable(
}
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;
Expand Down Expand Up @@ -514,6 +527,10 @@ public ReadOnlyMemChunk getReadOnlyMemChunkFromMemTable(
}
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);
Expand Down
Loading