|
| 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 | + |
| 20 | +package org.apache.iotdb.db.it.query; |
| 21 | + |
| 22 | +import org.apache.iotdb.db.queryengine.execution.operator.sink.IdentitySinkOperator; |
| 23 | +import org.apache.iotdb.db.queryengine.execution.operator.source.ExchangeOperator; |
| 24 | +import org.apache.iotdb.it.env.EnvFactory; |
| 25 | +import org.apache.iotdb.it.framework.IoTDBTestRunner; |
| 26 | +import org.apache.iotdb.itbase.category.LocalStandaloneIT; |
| 27 | +import org.apache.iotdb.itbase.env.BaseEnv; |
| 28 | + |
| 29 | +import org.junit.AfterClass; |
| 30 | +import org.junit.BeforeClass; |
| 31 | +import org.junit.Test; |
| 32 | +import org.junit.experimental.categories.Category; |
| 33 | +import org.junit.runner.RunWith; |
| 34 | + |
| 35 | +import java.sql.Connection; |
| 36 | +import java.sql.ResultSet; |
| 37 | +import java.sql.SQLException; |
| 38 | +import java.sql.Statement; |
| 39 | + |
| 40 | +import static org.junit.Assert.assertTrue; |
| 41 | +import static org.junit.Assert.fail; |
| 42 | + |
| 43 | +@RunWith(IoTDBTestRunner.class) |
| 44 | +@Category({LocalStandaloneIT.class}) |
| 45 | +public class IoTDBExplainAnalyzePrintIT { |
| 46 | + |
| 47 | + private static final String[] creationSqls = |
| 48 | + new String[] { |
| 49 | + "insert into root.test.device_0(s1, s2, s3, s4, s5, s6, s7, s8, s9, s10) values(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)", |
| 50 | + "insert into root.test.device_1(s11) values(11)", |
| 51 | + }; |
| 52 | + |
| 53 | + @BeforeClass |
| 54 | + public static void setUp() throws Exception { |
| 55 | + EnvFactory.getEnv().initClusterEnvironment(); |
| 56 | + prepareData(); |
| 57 | + } |
| 58 | + |
| 59 | + @AfterClass |
| 60 | + public static void tearDown() throws Exception { |
| 61 | + EnvFactory.getEnv().cleanClusterEnvironment(); |
| 62 | + } |
| 63 | + |
| 64 | + private static void prepareData() { |
| 65 | + try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TREE_SQL_DIALECT); |
| 66 | + Statement statement = connection.createStatement()) { |
| 67 | + for (String sql : creationSqls) { |
| 68 | + statement.execute(sql); |
| 69 | + } |
| 70 | + } catch (Exception e) { |
| 71 | + fail(e.getMessage()); |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + @Test |
| 76 | + public void testIdentitySinkOperatorWhenMergedInAnalyze() throws SQLException { |
| 77 | + try (Connection connection = EnvFactory.getEnv().getConnection(); |
| 78 | + Statement statement = connection.createStatement(); |
| 79 | + ResultSet resultSet = |
| 80 | + statement.executeQuery("explain analyze select * from root.test.device_0")) { |
| 81 | + boolean found = false; |
| 82 | + while (resultSet.next()) { |
| 83 | + if (resultSet.getString(1).contains(IdentitySinkOperator.DOWNSTREAM_PLAN_NODE_ID)) { |
| 84 | + found = true; |
| 85 | + break; |
| 86 | + } |
| 87 | + } |
| 88 | + assertTrue( |
| 89 | + "explain analyze output should contain DownStreamPlanNodeId in IdentitySinkOperator", |
| 90 | + found); |
| 91 | + } |
| 92 | + } |
| 93 | + |
| 94 | + @Test |
| 95 | + public void testExchangeOperatorWhenMergedInAnalyze() throws SQLException { |
| 96 | + try (Connection connection = EnvFactory.getEnv().getConnection(); |
| 97 | + Statement statement = connection.createStatement(); |
| 98 | + ResultSet resultSet = |
| 99 | + statement.executeQuery( |
| 100 | + "explain analyze select * from root.test.device_0, root.test.device_1")) { |
| 101 | + boolean found = false; |
| 102 | + while (resultSet.next()) { |
| 103 | + if (resultSet.getString(1).contains(ExchangeOperator.SIZE_IN_BYTES)) { |
| 104 | + found = true; |
| 105 | + break; |
| 106 | + } |
| 107 | + } |
| 108 | + assertTrue("explain analyze output should contain size_in_bytes", found); |
| 109 | + } |
| 110 | + } |
| 111 | +} |
0 commit comments