Skip to content

Commit 58927a1

Browse files
authored
Fixed the potential failure for table view query with pattern beyond databases
1 parent b34e05e commit 58927a1

7 files changed

Lines changed: 39 additions & 5 deletions

File tree

integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBTableIT.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,7 @@ public void testConcurrentAutoCreateAndDropColumn() throws Exception {
764764
public void testTreeViewTable() throws Exception {
765765
try (final Connection connection = EnvFactory.getEnv().getConnection();
766766
final Statement statement = connection.createStatement()) {
767+
statement.execute("create database root.another");
767768
statement.execute("create database root.`重庆`.b");
768769
statement.execute("create timeSeries root.`重庆`.b.c.S1 int32");
769770
statement.execute("create timeSeries root.`重庆`.b.c.s2 string");
@@ -777,6 +778,15 @@ public void testTreeViewTable() throws Exception {
777778
final Statement statement = connection.createStatement()) {
778779
statement.execute("create database tree_view_db");
779780
statement.execute("use tree_view_db");
781+
782+
try {
783+
statement.execute("create view tree_table (tag1 tag, tag2 tag) as root.**");
784+
fail();
785+
} catch (final SQLException e) {
786+
assertEquals(
787+
"701: Cannot specify view pattern to match more than one tree database.",
788+
e.getMessage());
789+
}
780790
statement.execute("create view tree_table (tag1 tag, tag2 tag) as root.\"重庆\".**");
781791
statement.execute("drop view tree_table");
782792
}

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/ConfigManager.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import org.apache.iotdb.commons.pipe.connector.payload.airgap.AirGapPseudoTPipeTransferRequest;
5959
import org.apache.iotdb.commons.schema.SchemaConstant;
6060
import org.apache.iotdb.commons.schema.table.AlterOrDropTableOperationType;
61+
import org.apache.iotdb.commons.schema.table.TreeViewSchema;
6162
import org.apache.iotdb.commons.schema.table.TsTable;
6263
import org.apache.iotdb.commons.schema.table.TsTableInternalRPCUtil;
6364
import org.apache.iotdb.commons.schema.ttl.TTLCache;
@@ -2821,10 +2822,21 @@ public TSStatus createTable(final ByteBuffer tableInfo) {
28212822

28222823
@Override
28232824
public TSStatus createTableView(final TCreateTableViewReq req) {
2824-
TSStatus status = confirmLeader();
2825+
final TSStatus status = confirmLeader();
28252826
if (status.getCode() == TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
28262827
final Pair<String, TsTable> pair =
28272828
TsTableInternalRPCUtil.deserializeSingleTsTableWithDatabase(req.getTableInfo());
2829+
if (clusterSchemaManager
2830+
.getMatchedDatabaseSchemasByPrefix(
2831+
new PartialPath(
2832+
Arrays.copyOf(
2833+
TreeViewSchema.getPrefixPattern(pair.getRight()).getNodes(),
2834+
TreeViewSchema.getPrefixPattern(pair.getRight()).getNodeLength() - 1)))
2835+
.size()
2836+
> 1) {
2837+
return new TSStatus(TSStatusCode.SEMANTIC_ERROR.getStatusCode())
2838+
.setMessage("Cannot specify view pattern to match more than one tree database.");
2839+
}
28282840
return procedureManager.createTableView(pair.left, pair.right, req.isReplace());
28292841
} else {
28302842
return status;

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/ProcedureManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2036,7 +2036,7 @@ public TSStatus executeWithoutDuplicate(
20362036
final String queryId,
20372037
final ProcedureType thisType,
20382038
final Procedure<ConfigNodeProcedureEnv> procedure) {
2039-
long procedureId;
2039+
final long procedureId;
20402040
synchronized (this) {
20412041
final Pair<Long, Boolean> procedureIdDuplicatePair =
20422042
checkDuplicateTableTask(database, table, tableName, queryId, thisType);

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/schema/source/TableDeviceQuerySource.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.apache.iotdb.commons.exception.runtime.SchemaExecutionException;
2323
import org.apache.iotdb.commons.path.ExtendedPartialPath;
2424
import org.apache.iotdb.commons.path.PartialPath;
25+
import org.apache.iotdb.commons.path.PathPatternUtil;
2526
import org.apache.iotdb.commons.schema.column.ColumnHeader;
2627
import org.apache.iotdb.commons.schema.filter.SchemaFilter;
2728
import org.apache.iotdb.commons.schema.filter.impl.DeviceFilterUtil;
@@ -327,7 +328,13 @@ public long getMaxMemory(final ISchemaRegion schemaRegion) {
327328
final ISchemaRegionStatistics statistics = schemaRegion.getSchemaRegionStatistics();
328329
final String tableName = table.getTableName();
329330
final long devicesNumber = statistics.getTableDevicesNumber(tableName);
330-
return devicePatternList.stream().allMatch(path -> ((ExtendedPartialPath) path).isNormalPath())
331+
return !TreeViewSchema.isTreeViewTable(table)
332+
&& devicePatternList.stream()
333+
.allMatch(
334+
path ->
335+
((ExtendedPartialPath) path).isNormalPath()
336+
&& Arrays.stream(path.getNodes())
337+
.noneMatch(PathPatternUtil::hasWildcard))
331338
? Math.min(
332339
TSFileDescriptor.getInstance().getConfig().getMaxTsBlockSizeInBytes(),
333340
devicePatternList.stream()

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/cache/schema/dualkeycache/impl/DualKeyCacheImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public V get(final FK firstKey, final SK secondKey) {
7777
}
7878
}
7979

80+
@Override
8081
public <R> boolean batchApply(
8182
final Map<FK, Map<SK, R>> inputMap, final BiFunction<V, R, Boolean> mappingFunction) {
8283
for (final Map.Entry<FK, Map<SK, R>> fkMapEntry : inputMap.entrySet()) {

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/TableLogicalPlanner.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.apache.iotdb.commons.schema.table.TreeViewSchema;
2727
import org.apache.iotdb.commons.schema.table.TsTable;
2828
import org.apache.iotdb.commons.utils.TestOnly;
29+
import org.apache.iotdb.db.exception.sql.SemanticException;
2930
import org.apache.iotdb.db.queryengine.common.MPPQueryContext;
3031
import org.apache.iotdb.db.queryengine.common.QueryId;
3132
import org.apache.iotdb.db.queryengine.common.SessionInfo;
@@ -480,6 +481,10 @@ private void planTraverseDevice(final AbstractTraverseDevice statement, final An
480481

481482
analysis.setSchemaPartitionInfo(
482483
ClusterPartitionFetcher.getInstance().getSchemaPartition(tree));
484+
485+
if (analysis.getSchemaPartitionInfo().getSchemaPartitionMap().size() > 1) {
486+
throw new SemanticException("Tree device view with multiple databases is unsupported yet.");
487+
}
483488
} else {
484489
analysis.setSchemaPartitionInfo(
485490
statement.isIdDetermined()

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/optimizations/PushPredicateIntoTableScan.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,8 +583,7 @@ private void getDeviceEntriesWithDataPartitions(
583583
attributeColumns,
584584
queryContext);
585585
if (deviceEntriesMap.size() > 1) {
586-
throw new UnsupportedOperationException(
587-
"Tree device view with multiple databases is unsupported yet.");
586+
throw new SemanticException("Tree device view with multiple databases is unsupported yet.");
588587
}
589588
final String deviceDatabase =
590589
!deviceEntriesMap.isEmpty() ? deviceEntriesMap.keySet().iterator().next() : null;

0 commit comments

Comments
 (0)