Skip to content

Commit fc6ae83

Browse files
committed
HIVE-29360: Add tests for EXPLAIN FORMATTED CBO on TPC-DS queries
1 parent 26ea12b commit fc6ae83

File tree

103 files changed

+310198
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+310198
-1
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.hadoop.hive.cli;
19+
20+
import org.apache.hadoop.hive.cli.control.CliAdapter;
21+
import org.apache.hadoop.hive.cli.control.CliConfigs;
22+
import org.junit.ClassRule;
23+
import org.junit.Rule;
24+
import org.junit.Test;
25+
import org.junit.rules.TestRule;
26+
import org.junit.runner.RunWith;
27+
import org.junit.runners.Parameterized;
28+
import org.junit.runners.Parameterized.Parameters;
29+
30+
import java.io.File;
31+
import java.util.List;
32+
33+
@RunWith(Parameterized.class)
34+
public class TestExplainCBOFormattedCliDriver {
35+
36+
static CliAdapter adapter = new CliConfigs.TPCDSFormattedCBOConfig().getCliAdapter();
37+
38+
@Parameters(name = "{0}")
39+
public static List<Object[]> getParameters() throws Exception {
40+
return adapter.getParameters();
41+
}
42+
43+
@ClassRule
44+
public static TestRule cliClassRule = adapter.buildClassRule();
45+
46+
@Rule
47+
public TestRule cliTestRule = adapter.buildTestRule();
48+
49+
private final String name;
50+
private final File qfile;
51+
52+
public TestExplainCBOFormattedCliDriver(String name, File qfile) {
53+
this.name = name;
54+
this.qfile = qfile;
55+
}
56+
57+
@Test
58+
public void testCliDriver() throws Exception {
59+
adapter.runTest(name, qfile);
60+
}
61+
62+
}

itests/util/src/main/java/org/apache/hadoop/hive/cli/control/CliConfigs.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.apache.hadoop.hive.conf.HiveConf;
2727
import org.apache.hadoop.hive.ql.QTestMiniClusters;
2828
import org.apache.hadoop.hive.ql.QTestMiniClusters.MiniClusterType;
29+
import org.apache.hadoop.hive.ql.hooks.ExplainFormattedCBOHook;
2930
import org.apache.hadoop.hive.ql.parse.CoreParseNegative;
3031

3132
public class CliConfigs {
@@ -355,6 +356,25 @@ public TPCDSCteCliConfig() {
355356
}
356357
}
357358

359+
public static class TPCDSFormattedCBOConfig extends AbstractCliConfig {
360+
public TPCDSFormattedCBOConfig() {
361+
super(CorePerfCliDriver.class);
362+
setQueryDir("ql/src/test/queries/clientpositive/perf");
363+
setLogDir("itests/qtest/target/qfile-results/clientpositive/perf/tpcds30tb/json");
364+
setResultsDir("ql/src/test/results/clientpositive/perf/tpcds30tb/json");
365+
setHiveConfDir("data/conf/perf/tpcds30tb/tez");
366+
Map<HiveConf.ConfVars, String> conf = new HashMap<>();
367+
conf.put(HiveConf.ConfVars.HIVE_EXPLAIN_FORMATTED_INDENT, "true");
368+
conf.put(HiveConf.ConfVars.SEMANTIC_ANALYZER_HOOK, ExplainFormattedCBOHook.class.getCanonicalName());
369+
setCustomConfigValueMap(conf);
370+
setClusterType(MiniClusterType.LLAP_LOCAL);
371+
setMetastoreType("postgres.tpcds");
372+
for (int i = 1; i < 100; i++) {
373+
includeQuery("query" + i + ".q");
374+
}
375+
}
376+
}
377+
358378
public static class NegativeLlapLocalCliConfig extends AbstractCliConfig {
359379
public NegativeLlapLocalCliConfig() {
360380
super(CoreNegativeCliDriver.class);

itests/util/src/main/java/org/apache/hadoop/hive/cli/control/CorePerfCliDriver.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ public void beforeClass() throws Exception {
5252

5353
qt = new QTestUtil(QTestArguments.QTestArgumentsBuilder.instance().withOutDir(cliConfig.getResultsDir())
5454
.withLogDir(cliConfig.getLogDir()).withClusterType(miniMR).withConfDir(hiveConfDir).withInitScript(initScript)
55-
.withCleanupScript(cleanupScript).withLlapIo(false).build());
55+
.withCleanupScript(cleanupScript).withLlapIo(false)
56+
.withCustomConfigValueMap(cliConfig.getCustomConfigValueMap())
57+
.build());
5658
}
5759

5860
@Override
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.hadoop.hive.ql.hooks;
19+
20+
import org.apache.hadoop.hive.ql.optimizer.calcite.translator.ASTBuilder;
21+
import org.apache.hadoop.hive.ql.parse.ASTNode;
22+
import org.apache.hadoop.hive.ql.parse.AbstractSemanticAnalyzerHook;
23+
import org.apache.hadoop.hive.ql.parse.HiveParser;
24+
import org.apache.hadoop.hive.ql.parse.HiveSemanticAnalyzerHookContext;
25+
26+
/**
27+
* An analyzer hook for transforming plain EXPLAIN statements to EXPLAIN FORMATTED CBO.
28+
*/
29+
public class ExplainFormattedCBOHook extends AbstractSemanticAnalyzerHook {
30+
@Override
31+
public ASTNode preAnalyze(HiveSemanticAnalyzerHookContext context, ASTNode ast) {
32+
if (ast.getType() == HiveParser.TOK_EXPLAIN) {
33+
ast.addChild(ASTBuilder.createAST(HiveParser.KW_FORMATTED, "formatted"));
34+
ast.addChild(ASTBuilder.createAST(HiveParser.KW_CBO, "cbo"));
35+
}
36+
return ast;
37+
}
38+
}

0 commit comments

Comments
 (0)