diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBDeviceIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBDeviceIT.java index 95fb1a0fede1..e1687ff6b269 100644 --- a/integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBDeviceIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBDeviceIT.java @@ -67,13 +67,13 @@ public void testDevice() throws SQLException { statement.execute( "create table table0(region_id STRING ID, plant_id STRING ID, device_id STRING ID, model STRING ATTRIBUTE, temperature FLOAT MEASUREMENT, humidity DOUBLE MEASUREMENT)"); statement.execute( - "insert into table0(region_id, plant_id, device_id, model, temperature, humidity) values('1', '5', '3', 'A', 37.6, 111.1)"); + "insert into table0(region_id, plant_id, device_id, model, temperature, humidity) values('1', '木兰', '3', 'A', 37.6, 111.1)"); // Test plain show / count TestUtils.assertResultSetEqual( statement.executeQuery("show devices from table0"), "region_id,plant_id,device_id,model,", - Collections.singleton("1,5,3,A,")); + Collections.singleton("1,木兰,3,A,")); TestUtils.assertResultSetEqual( statement.executeQuery("count devices from table0"), "count(devices),", @@ -93,11 +93,11 @@ public void testDevice() throws SQLException { statement.executeQuery( "show devices from table0 where region_id between '0' and '2' and model = 'A'"), "region_id,plant_id,device_id,model,", - Collections.singleton("1,5,3,A,")); + Collections.singleton("1,木兰,3,A,")); // Test OR TestUtils.assertResultSetEqual( statement.executeQuery( - "count devices from table0 where region_id = '1' or plant_id like '%'"), + "count devices from table0 where region_id = '1' or plant_id like '%木兰'"), "count(devices),", Collections.singleton("1,")); // Test complicated query @@ -105,7 +105,7 @@ public void testDevice() throws SQLException { statement.executeQuery( "show devices from table0 where region_id < plant_id offset 0 limit 1"), "region_id,plant_id,device_id,model,", - Collections.singleton("1,5,3,A,")); + Collections.singleton("1,木兰,3,A,")); TestUtils.assertResultSetEqual( statement.executeQuery("show devices from table0 where region_id < plant_id limit 0"), "region_id,plant_id,device_id,model,", @@ -116,25 +116,25 @@ public void testDevice() throws SQLException { Collections.singleton("1,")); TestUtils.assertResultSetEqual( statement.executeQuery( - "count devices from table0 where substring(region_id, cast((cast(plant_id as int32) - 4) as int32), 1) < plant_id"), + "count devices from table0 where substring(region_id, cast((cast(device_id as int32) - 2) as int32), 1) < plant_id"), "count(devices),", Collections.singleton("1,")); // Test get from cache statement.executeQuery( - "select * from table0 where region_id = '1' and plant_id in ('3', '5') and device_id = '3'"); + "select * from table0 where region_id = '1' and plant_id in ('木兰', '5') and device_id = '3'"); TestUtils.assertResultSetEqual( statement.executeQuery( - "show devices from table0 where region_id = '1' and plant_id in ('3', '5') and device_id = '3' offset 0 limit ALL"), + "show devices from table0 where region_id = '1' and plant_id in ('3', '木兰') and device_id = '3' offset 0 limit ALL"), "region_id,plant_id,device_id,model,", - Collections.singleton("1,5,3,A,")); + Collections.singleton("1,木兰,3,A,")); TestUtils.assertResultSetEqual( statement.executeQuery( - "show devices from table0 where region_id = '1' and plant_id in ('3', '5') and device_id = '3' offset 100000000000 limit 100000000000"), + "show devices from table0 where region_id = '1' and plant_id in ('木兰', '5') and device_id = '3' offset 100000000000 limit 100000000000"), "region_id,plant_id,device_id,model,", Collections.emptySet()); TestUtils.assertResultSetEqual( statement.executeQuery( - "count devices from table0 where region_id = '1' and plant_id in ('3', '5') and device_id = '3'"), + "count devices from table0 where region_id = '1' and plant_id in ('3', '木兰') and device_id = '3'"), "count(devices),", Collections.singleton("1,")); // Test filter @@ -145,9 +145,9 @@ public void testDevice() throws SQLException { // Test cache with complicated filter TestUtils.assertResultSetEqual( statement.executeQuery( - "show devices from table0 where region_id = '1' and plant_id in ('3', '5') and device_id = '3' and device_id between region_id and plant_id"), + "show devices from table0 where region_id = '1' and plant_id in ('木兰', '5') and device_id = '3' and device_id between region_id and plant_id"), "region_id,plant_id,device_id,model,", - Collections.singleton("1,5,3,A,")); + Collections.singleton("1,木兰,3,A,")); try { statement.executeQuery("show devices from table2"); @@ -232,16 +232,16 @@ public void testDevice() throws SQLException { statement.executeQuery( "show devices from table0 where substring(region_id, 1, 1) in ('1', '2') and 1 + 1 = 2"), "region_id,plant_id,device_id,model,", - Collections.singleton("1,5,3,null,")); + Collections.singleton("1,木兰,3,null,")); // Test common result column statement.execute( - "update table0 set model = substring(device_id, 1, 1) where cast(region_id as int32) + cast(plant_id as int32) = 6 and region_id = '1'"); + "update table0 set model = substring(device_id, 1, 1) where cast(region_id as int32) + cast(device_id as int32) = 4 and region_id = '1'"); TestUtils.assertResultSetEqual( statement.executeQuery( "show devices from table0 where substring(region_id, 1, 1) in ('1', '2') and 1 + 1 = 2"), "region_id,plant_id,device_id,model,", - Collections.singleton("1,5,3,3,")); + Collections.singleton("1,木兰,3,3,")); // Test limit / offset from multi regions statement.execute( @@ -252,12 +252,12 @@ public void testDevice() throws SQLException { // TODO: Reopen if (false) { // Test delete devices - statement.execute("delete devices from table0 where region_id = '1' and plant_id = '5'"); + statement.execute("delete devices from table0 where region_id = '1' and plant_id = '木兰'"); TestUtils.assertResultSetSize(statement.executeQuery("show devices from table0"), 1); // Test successfully invalidate cache statement.execute( - "insert into table0(region_id, plant_id, device_id, model, temperature, humidity) values('1', '5', '3', 'A', 37.6, 111.1)"); + "insert into table0(region_id, plant_id, device_id, model, temperature, humidity) values('1', '木兰', '3', 'A', 37.6, 111.1)"); TestUtils.assertResultSetSize(statement.executeQuery("show devices from table0"), 2); // Test successfully delete data diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionTableDeviceTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionTableDeviceTest.java index 5d95850c5cbb..84307a421175 100644 --- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionTableDeviceTest.java +++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionTableDeviceTest.java @@ -147,6 +147,8 @@ public void testDeviceQuery() throws Exception { attributeMap.put("cycle", "daily"); SchemaRegionTestUtil.createTableDevice( schemaRegion, tableName, new String[] {"shandong", "p_1", "d_1"}, attributeMap); + SchemaRegionTestUtil.createTableDevice( + schemaRegion, tableName, new String[] {"广州", "p_2", "d_2"}, attributeMap); List deviceSchemaInfoList = SchemaRegionTestUtil.getTableDevice( @@ -184,8 +186,17 @@ public void testDeviceQuery() throws Exception { Arrays.asList( new IdFilter(new InFilter(new HashSet<>(Arrays.asList("d_0", "d_1"))), 2), new IdFilter(new LikeFilter("__1", Optional.empty()), 2))); - Assert.assertEquals(2, deviceSchemaInfoList.size()); + + // Test CN characters + deviceSchemaInfoList = + SchemaRegionTestUtil.getTableDevice( + schemaRegion, + tableName, + 3, + Collections.singletonList( + new IdFilter(new NotFilter(new LikeFilter("广州%", Optional.empty())), 0))); + Assert.assertEquals(3, deviceSchemaInfoList.size()); } @Test diff --git a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/filter/impl/StringValueFilterVisitor.java b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/filter/impl/StringValueFilterVisitor.java index e95bb3cdb196..8a70ea956c1d 100644 --- a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/filter/impl/StringValueFilterVisitor.java +++ b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/filter/impl/StringValueFilterVisitor.java @@ -28,6 +28,8 @@ import org.apache.iotdb.commons.schema.filter.impl.values.LikeFilter; import org.apache.iotdb.commons.schema.filter.impl.values.PreciseFilter; +import org.apache.tsfile.common.conf.TSFileConfig; + import java.util.Objects; public class StringValueFilterVisitor extends SchemaFilterVisitor { @@ -78,7 +80,8 @@ public Boolean visitLikeFilter(final LikeFilter filter, final String context) { if (Objects.isNull(context)) { return null; } - return filter.getPattern().getMatcher().match(context.getBytes(), 0, context.length()); + final byte[] bytes = context.getBytes(TSFileConfig.STRING_CHARSET); + return filter.getPattern().getMatcher().match(bytes, 0, bytes.length); } @Override diff --git a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/filter/impl/values/LikeFilter.java b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/filter/impl/values/LikeFilter.java index b810c91fd80a..d0d59c0c3e93 100644 --- a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/filter/impl/values/LikeFilter.java +++ b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/filter/impl/values/LikeFilter.java @@ -35,7 +35,7 @@ public class LikeFilter extends SchemaFilter { private final LikePattern pattern; - public LikeFilter(final String regex, Optional escape) { + public LikeFilter(final String regex, final Optional escape) { this.pattern = LikePattern.compile(regex, escape); }