diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/view/old/IoTDBFilterTableViewIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/view/old/IoTDBFilterTableViewIT.java index 1f6bacf097177..9f8d2633534aa 100644 --- a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/view/old/IoTDBFilterTableViewIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/view/old/IoTDBFilterTableViewIT.java @@ -226,6 +226,22 @@ public void testCompareWithNull() { "select s1 from sg1 where s1 = null", new String[] {"s1"}, new String[] {}, DATABASE_NAME); } + @Test + public void testCountDevicesWithFunctionOnTag() { + // The tag position in the device path depends on the depth of the view's path prefix: + // root.sg1.** has two levels and root.vehicle.testNaN.** has three. + tableResultSetEqualTest( + "count devices from sg1 where upper(device) = 'D1'", + new String[] {"count(devices)"}, + new String[] {"1,"}, + DATABASE_NAME); + tableResultSetEqualTest( + "count devices from testNaN where upper(device) = 'D1'", + new String[] {"count(devices)"}, + new String[] {"1,"}, + DATABASE_NAME); + } + @Test public void testCalculateWithNull() { tableResultSetEqualTest( diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/schema/source/DevicePredicateHandler.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/schema/source/DevicePredicateHandler.java index db7d0a2b374bf..bacb29bbc3a8b 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/schema/source/DevicePredicateHandler.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/schema/source/DevicePredicateHandler.java @@ -22,9 +22,9 @@ import org.apache.iotdb.calc.transformation.dag.column.ColumnTransformer; import org.apache.iotdb.calc.transformation.dag.column.leaf.LeafColumnTransformer; import org.apache.iotdb.commons.exception.MetadataException; +import org.apache.iotdb.commons.schema.table.TreeViewSchema; import org.apache.iotdb.commons.schema.table.TsTable; import org.apache.iotdb.commons.schema.table.column.TsTableColumnSchema; -import org.apache.iotdb.commons.utils.PathUtils; import org.apache.iotdb.db.schemaengine.schemaregion.read.resp.info.IDeviceSchemaInfo; import org.apache.iotdb.db.schemaengine.table.DataNodeTreeViewSchemaUtils; @@ -73,9 +73,9 @@ protected DevicePredicateHandler( .map(TsTableColumnSchema::getDataType) .collect(Collectors.toList()); this.tagIndex = - PathUtils.isTableModelDatabase(database) - ? 3 - : DataNodeTreeViewSchemaUtils.getPatternNodes(table).length; + TreeViewSchema.isTreeViewTable(table) + ? DataNodeTreeViewSchemaUtils.getPatternNodes(table).length + : 3; } public void addBatch(final IDeviceSchemaInfo deviceSchemaInfo) {