Skip to content

Commit 672e72d

Browse files
authored
Fix the issue that querying exact device with some fuzzy filter may failed
1 parent 942e911 commit 672e72d

File tree

2 files changed

+77
-2
lines changed

2 files changed

+77
-2
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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.recent;
21+
22+
import org.apache.iotdb.it.env.EnvFactory;
23+
import org.apache.iotdb.it.framework.IoTDBTestRunner;
24+
import org.apache.iotdb.itbase.category.TableClusterIT;
25+
import org.apache.iotdb.itbase.category.TableLocalStandaloneIT;
26+
import org.apache.iotdb.rpc.IoTDBConnectionException;
27+
import org.apache.iotdb.rpc.StatementExecutionException;
28+
29+
import org.junit.AfterClass;
30+
import org.junit.BeforeClass;
31+
import org.junit.Test;
32+
import org.junit.experimental.categories.Category;
33+
import org.junit.runner.RunWith;
34+
35+
import static org.apache.iotdb.db.it.utils.TestUtils.prepareTableData;
36+
import static org.apache.iotdb.db.it.utils.TestUtils.tableResultSetEqualTest;
37+
38+
@RunWith(IoTDBTestRunner.class)
39+
@Category({TableLocalStandaloneIT.class, TableClusterIT.class})
40+
public class IoTDBQueryAttributeTableIT {
41+
protected static final String DATABASE_NAME = "test_db";
42+
protected static final String[] createSqls =
43+
new String[] {
44+
"CREATE DATABASE " + DATABASE_NAME,
45+
"USE " + DATABASE_NAME,
46+
"create table t1(device STRING TAG, a1 STRING ATTRIBUTE, s1 INT32 FIELD)",
47+
"insert into t1 (time, device, a1, s1) values (1, 'd1', 'ATTR1', 1)"
48+
};
49+
50+
@BeforeClass
51+
public static void setUp() throws Exception {
52+
EnvFactory.getEnv().initClusterEnvironment();
53+
prepareTableData(createSqls);
54+
}
55+
56+
@AfterClass
57+
public static void tearDown() throws Exception {
58+
EnvFactory.getEnv().cleanClusterEnvironment();
59+
}
60+
61+
@Test
62+
public void test1() throws IoTDBConnectionException, StatementExecutionException {
63+
String[] expectedHeader = new String[] {"time", "device", "a1", "s1"};
64+
String[] retArray = new String[] {"1970-01-01T00:00:00.001Z,d1,ATTR1,1,"};
65+
tableResultSetEqualTest(
66+
"select * from t1 where lower(a1) = 'attr1' and device = 'd1'",
67+
expectedHeader,
68+
retArray,
69+
DATABASE_NAME);
70+
}
71+
}

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/predicate/schema/ConvertSchemaPredicateToFilterVisitor.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,16 @@ protected SchemaFilter visitIsNotNullPredicate(
158158
final boolean isOrdered;
159159
if (node.getLeft() instanceof Literal) {
160160
value = ((StringLiteral) (node.getLeft())).getValue();
161-
checkArgument(isSymbolReference(node.getRight()));
161+
if (!isSymbolReference(node.getRight())) {
162+
return null;
163+
}
162164
columnName = ((SymbolReference) (node.getRight())).getName();
163165
isOrdered = false;
164166
} else if (node.getRight() instanceof Literal) {
165167
value = ((StringLiteral) (node.getRight())).getValue();
166-
checkArgument(isSymbolReference(node.getLeft()));
168+
if (!isSymbolReference(node.getLeft())) {
169+
return null;
170+
}
167171
columnName = ((SymbolReference) (node.getLeft())).getName();
168172
isOrdered = true;
169173
} else {

0 commit comments

Comments
 (0)