Skip to content

Commit 6d6d5b1

Browse files
committed
copilot comments
1 parent 2841855 commit 6d6d5b1

File tree

7 files changed

+25
-14
lines changed

7 files changed

+25
-14
lines changed

integration-test/src/test/java/org/apache/iotdb/relational/it/query/recent/IoTExplainAnalyzeIT.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,11 @@ private static ToLongFunction<String> extractNumber(String regex) {
240240
Pattern pattern = Pattern.compile(regex);
241241
Matcher matcher = pattern.matcher(line);
242242
if (matcher.find()) {
243-
return Long.parseLong(matcher.group(1));
243+
try {
244+
return Long.parseLong(matcher.group(1));
245+
} catch (NumberFormatException e) {
246+
return 0;
247+
}
244248
}
245249
return 0;
246250
};

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/common/MPPQueryContext.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.apache.iotdb.db.queryengine.statistics.QueryPlanStatistics;
4141
import org.apache.iotdb.db.utils.cte.CteDataStore;
4242

43+
import com.google.common.collect.ImmutableList;
4344
import org.apache.tsfile.read.filter.basic.Filter;
4445
import org.apache.tsfile.utils.Pair;
4546

@@ -127,7 +128,7 @@ public class MPPQueryContext implements IAuditEntity {
127128
private boolean subquery = false;
128129

129130
// Tables in the subquery
130-
private final Map<Query, List<Identifier>> subQueryTables = new HashMap<>();
131+
private final Map<NodeRef<Query>, List<Identifier>> subQueryTables = new HashMap<>();
131132

132133
public MPPQueryContext(QueryId queryId) {
133134
this.queryId = queryId;
@@ -513,8 +514,12 @@ public void setCteQueries(Map<NodeRef<Table>, Query> cteQueries) {
513514
this.cteQueries = cteQueries;
514515
}
515516

516-
public Map<Query, List<Identifier>> getSubQueryTables() {
517-
return subQueryTables;
517+
public void addSubQueryTables(Query query, List<Identifier> tables) {
518+
subQueryTables.put(NodeRef.of(query), tables);
519+
}
520+
521+
public List<Identifier> getTables(Query query) {
522+
return subQueryTables.getOrDefault(NodeRef.of(query), ImmutableList.of());
518523
}
519524

520525
public void addCteExplainResult(Table table, Pair<Integer, List<String>> cteExplainResult) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1722,7 +1722,7 @@ private Type analyzeSubquery(SubqueryExpression node, StackableAstVisitorContext
17221722
statementAnalyzerFactory.apply(node, ctx.getContext().getCorrelationSupport());
17231723
Scope subqueryScope = Scope.builder().withParent(ctx.getContext().getScope()).build();
17241724
Scope queryScope = analyzer.analyze(node.getQuery(), subqueryScope);
1725-
context.getSubQueryTables().put(node.getQuery(), queryScope.getTables());
1725+
context.addSubQueryTables(node.getQuery(), queryScope.getTables());
17261726

17271727
ImmutableList.Builder<RowType.Field> fields = ImmutableList.builder();
17281728
for (int i = 0; i < queryScope.getRelationType().getAllFieldCount(); i++) {

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.google.common.collect.ImmutableMap;
3333

3434
import java.util.ArrayList;
35+
import java.util.Collections;
3536
import java.util.HashMap;
3637
import java.util.List;
3738
import java.util.Map;
@@ -82,12 +83,16 @@ public void addTable(Table table) {
8283
tables.add(new Identifier(table.getName().getSuffix()));
8384
}
8485

86+
public void addTables(List<Identifier> tables) {
87+
this.tables.addAll(tables);
88+
}
89+
8590
public Scope copy() {
8691
return builder().like(this).build();
8792
}
8893

8994
public List<Identifier> getTables() {
90-
return tables;
95+
return Collections.unmodifiableList(tables);
9196
}
9297

9398
public Scope withRelationType(RelationType relationType) {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,7 @@ private Scope analyzeWith(Query node, Optional<Scope> scope) {
947947
}
948948

949949
withScopeBuilder.withNamedQuery(name, withQuery);
950-
queryContext.getSubQueryTables().put(withQuery.getQuery(), queryScope.getTables());
950+
queryContext.addSubQueryTables(withQuery.getQuery(), queryScope.getTables());
951951
}
952952
}
953953
Scope withScope = withScopeBuilder.build();
@@ -3635,8 +3635,8 @@ protected Scope visitJoin(Join node, Optional<Scope> scope) {
36353635
Scope right = process(node.getRight(), rightScope);
36363636

36373637
if (scope.isPresent()) {
3638-
leftScope.ifPresent(l -> scope.get().getTables().addAll(l.getTables()));
3639-
rightScope.ifPresent(l -> scope.get().getTables().addAll(l.getTables()));
3638+
leftScope.ifPresent(l -> scope.get().addTables(l.getTables()));
3639+
rightScope.ifPresent(l -> scope.get().addTables(l.getTables()));
36403640
}
36413641

36423642
if (criteria instanceof JoinUsing) {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@ public CteDataStore fetchCteQueryResult(
107107
try {
108108
Query q = query;
109109
if (with != null) {
110-
List<Identifier> tables =
111-
context.getSubQueryTables().getOrDefault(query, ImmutableList.of());
110+
List<Identifier> tables = context.getTables(query);
112111
List<WithQuery> withQueries =
113112
with.getQueries().stream()
114113
.filter(

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
import org.apache.iotdb.db.queryengine.plan.relational.sql.parser.SqlParser;
4949
import org.apache.iotdb.rpc.TSStatusCode;
5050

51-
import com.google.common.collect.ImmutableList;
5251
import org.apache.tsfile.block.column.Column;
5352
import org.apache.tsfile.enums.TSDataType;
5453
import org.apache.tsfile.read.common.block.TsBlock;
@@ -113,8 +112,7 @@ public Optional<Literal> fetchUncorrelatedSubqueryResultForPredicate(
113112
Query query = subqueryExpression.getQuery();
114113
Query q = query;
115114
if (with != null) {
116-
List<Identifier> tables =
117-
context.getSubQueryTables().getOrDefault(query, ImmutableList.of());
115+
List<Identifier> tables = context.getTables(query);
118116
List<WithQuery> withQueries =
119117
with.getQueries().stream()
120118
.filter(

0 commit comments

Comments
 (0)