Skip to content

Commit 01aaef2

Browse files
committed
add UT
Signed-off-by: Weihao Li <[email protected]>
1 parent d166e0e commit 01aaef2

File tree

3 files changed

+114
-3
lines changed

3 files changed

+114
-3
lines changed

iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/relational/planner/PlanTester.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ public class PlanTester {
8383
public List<TDataNodeLocation> getDataNodeLocations(String table) {
8484
switch (table) {
8585
case "queries":
86+
case "current_queries":
87+
case "queries_costs_histogram":
8688
return ImmutableList.of(
8789
genDataNodeLocation(1, "192.0.1.1"), genDataNodeLocation(2, "192.0.1.2"));
8890
default:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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+
package org.apache.iotdb.db.queryengine.plan.relational.planner.informationschema;
20+
21+
import org.apache.iotdb.db.queryengine.plan.planner.plan.LogicalQueryPlan;
22+
import org.apache.iotdb.db.queryengine.plan.relational.planner.PlanTester;
23+
24+
import com.google.common.collect.ImmutableList;
25+
import org.junit.Test;
26+
27+
import java.util.Optional;
28+
29+
import static org.apache.iotdb.commons.schema.column.ColumnHeaderConstant.BIN;
30+
import static org.apache.iotdb.commons.schema.column.ColumnHeaderConstant.CLIENT_IP;
31+
import static org.apache.iotdb.commons.schema.column.ColumnHeaderConstant.COST_TIME;
32+
import static org.apache.iotdb.commons.schema.column.ColumnHeaderConstant.DATA_NODE_ID_TABLE_MODEL;
33+
import static org.apache.iotdb.commons.schema.column.ColumnHeaderConstant.END_TIME_TABLE_MODEL;
34+
import static org.apache.iotdb.commons.schema.column.ColumnHeaderConstant.NUMS;
35+
import static org.apache.iotdb.commons.schema.column.ColumnHeaderConstant.QUERY_ID_TABLE_MODEL;
36+
import static org.apache.iotdb.commons.schema.column.ColumnHeaderConstant.START_TIME_TABLE_MODEL;
37+
import static org.apache.iotdb.commons.schema.column.ColumnHeaderConstant.STATEMENT_TABLE_MODEL;
38+
import static org.apache.iotdb.commons.schema.column.ColumnHeaderConstant.STATE_TABLE_MODEL;
39+
import static org.apache.iotdb.commons.schema.column.ColumnHeaderConstant.USER_TABLE_MODEL;
40+
import static org.apache.iotdb.db.queryengine.plan.relational.planner.assertions.PlanAssert.assertPlan;
41+
import static org.apache.iotdb.db.queryengine.plan.relational.planner.assertions.PlanMatchPattern.collect;
42+
import static org.apache.iotdb.db.queryengine.plan.relational.planner.assertions.PlanMatchPattern.exchange;
43+
import static org.apache.iotdb.db.queryengine.plan.relational.planner.assertions.PlanMatchPattern.infoSchemaTableScan;
44+
import static org.apache.iotdb.db.queryengine.plan.relational.planner.assertions.PlanMatchPattern.output;
45+
46+
public class CurrentQueriesTest {
47+
private final PlanTester planTester = new PlanTester();
48+
49+
@Test
50+
public void testCurrentQueries() {
51+
LogicalQueryPlan logicalQueryPlan =
52+
planTester.createPlan("select * from information_schema.current_queries");
53+
assertPlan(
54+
logicalQueryPlan,
55+
output(
56+
infoSchemaTableScan(
57+
"information_schema.current_queries",
58+
Optional.empty(),
59+
ImmutableList.of(
60+
QUERY_ID_TABLE_MODEL,
61+
STATE_TABLE_MODEL,
62+
START_TIME_TABLE_MODEL,
63+
END_TIME_TABLE_MODEL,
64+
DATA_NODE_ID_TABLE_MODEL,
65+
COST_TIME,
66+
STATEMENT_TABLE_MODEL,
67+
USER_TABLE_MODEL,
68+
CLIENT_IP))));
69+
70+
// - Exchange
71+
// Output - Collect - Exchange
72+
assertPlan(planTester.getFragmentPlan(0), output(collect(exchange(), exchange())));
73+
// TableScan
74+
assertPlan(
75+
planTester.getFragmentPlan(1),
76+
infoSchemaTableScan("information_schema.current_queries", Optional.of(1)));
77+
// TableScan
78+
assertPlan(
79+
planTester.getFragmentPlan(2),
80+
infoSchemaTableScan("information_schema.current_queries", Optional.of(2)));
81+
}
82+
83+
@Test
84+
public void testQueriesCostsHistogram() {
85+
LogicalQueryPlan logicalQueryPlan =
86+
planTester.createPlan("select * from information_schema.queries_costs_histogram");
87+
assertPlan(
88+
logicalQueryPlan,
89+
output(
90+
infoSchemaTableScan(
91+
"information_schema.queries_costs_histogram",
92+
Optional.empty(),
93+
ImmutableList.of(BIN, NUMS))));
94+
95+
// - Exchange
96+
// Output - Collect - Exchange
97+
assertPlan(planTester.getFragmentPlan(0), output(collect(exchange(), exchange())));
98+
// TableScan
99+
assertPlan(
100+
planTester.getFragmentPlan(1),
101+
infoSchemaTableScan("information_schema.queries_costs_histogram", Optional.of(1)));
102+
// TableScan
103+
assertPlan(
104+
planTester.getFragmentPlan(2),
105+
infoSchemaTableScan("information_schema.queries_costs_histogram", Optional.of(2)));
106+
}
107+
}

iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/ShowQueriesTest.java renamed to iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/relational/planner/informationschema/ShowQueriesTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
package org.apache.iotdb.db.queryengine.plan.relational.analyzer;
19+
package org.apache.iotdb.db.queryengine.plan.relational.planner.informationschema;
2020

2121
import org.apache.iotdb.db.queryengine.plan.planner.plan.LogicalQueryPlan;
2222
import org.apache.iotdb.db.queryengine.plan.relational.planner.PlanTester;
@@ -32,7 +32,9 @@
3232
import static org.apache.iotdb.commons.schema.column.ColumnHeaderConstant.QUERY_ID_TABLE_MODEL;
3333
import static org.apache.iotdb.commons.schema.column.ColumnHeaderConstant.START_TIME_TABLE_MODEL;
3434
import static org.apache.iotdb.commons.schema.column.ColumnHeaderConstant.STATEMENT;
35+
import static org.apache.iotdb.commons.schema.column.ColumnHeaderConstant.STATEMENT_TABLE_MODEL;
3536
import static org.apache.iotdb.commons.schema.column.ColumnHeaderConstant.USER;
37+
import static org.apache.iotdb.commons.schema.column.ColumnHeaderConstant.USER_TABLE_MODEL;
3638
import static org.apache.iotdb.db.queryengine.plan.relational.planner.assertions.PlanAssert.assertPlan;
3739
import static org.apache.iotdb.db.queryengine.plan.relational.planner.assertions.PlanMatchPattern.collect;
3840
import static org.apache.iotdb.db.queryengine.plan.relational.planner.assertions.PlanMatchPattern.exchange;
@@ -61,8 +63,8 @@ public void testNormal() {
6163
START_TIME_TABLE_MODEL,
6264
DATA_NODE_ID_TABLE_MODEL,
6365
ELAPSED_TIME_TABLE_MODEL,
64-
STATEMENT.toLowerCase(Locale.ENGLISH),
65-
USER.toLowerCase(Locale.ENGLISH)))));
66+
STATEMENT_TABLE_MODEL,
67+
USER_TABLE_MODEL))));
6668

6769
// - Exchange
6870
// Output - Collect - Exchange

0 commit comments

Comments
 (0)