|
| 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 | +} |
0 commit comments