Skip to content

Commit

Permalink
HIVE-27972: Set 'tez' as default value in hive.execution.engine (#4973)…
Browse files Browse the repository at this point in the history
… (Laszlo Bodor reviewed by Simhadri Govindappa, Sourabh Badhya)
  • Loading branch information
abstractdog committed Jun 25, 2024
1 parent 5d3a26b commit a9afca6
Show file tree
Hide file tree
Showing 161 changed files with 1,202 additions and 512 deletions.
24 changes: 24 additions & 0 deletions cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,30 @@
<artifactId>hbase-common</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-exec</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-common</artifactId>
<version>${project.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tez</groupId>
<artifactId>tez-mapreduce</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tez</groupId>
<artifactId>tez-dag</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand Down
6 changes: 5 additions & 1 deletion cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ public int run(String[] args) throws Exception {
logInitDetailMessage = e.getMessage();
}

CliSessionState ss = new CliSessionState(new HiveConf(SessionState.class));
CliSessionState ss = new CliSessionState(getConf());
ss.in = System.in;
try {
ss.out =
Expand Down Expand Up @@ -815,6 +815,10 @@ public Map<String, String> getHiveVariable() {
}
}

protected HiveConf getConf() {
return new HiveConf(SessionState.class);
}

/**
* Execute the cli work
* @param ss CliSessionState of the CLI driver
Expand Down
36 changes: 26 additions & 10 deletions cli/src/test/org/apache/hadoop/hive/cli/TestCliDriverMethods.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@
import org.apache.hadoop.hive.common.io.SessionStream;
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.conf.HiveConf.ConfVars;
import org.apache.hadoop.hive.conf.HiveConfForTest;
import org.apache.hadoop.hive.metastore.api.FieldSchema;
import org.apache.hadoop.hive.metastore.api.Schema;
import org.apache.hadoop.hive.ql.IDriver;
import org.apache.hadoop.hive.ql.QueryState;
import org.apache.hadoop.hive.ql.processors.CommandProcessorException;
import org.apache.hadoop.hive.ql.processors.CommandProcessorResponse;
import org.junit.Test;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -130,7 +132,8 @@ public void testThatCliDriverDoesNotStripComments() throws Exception {
SessionStream err = new SessionStream(dataErr);
System.setErr(err);

CliSessionState ss = new CliSessionState(new HiveConf());
HiveConf hiveConf = getHiveConf();
CliSessionState ss = new CliSessionState(hiveConf);
ss.out = out;
ss.err = err;

Expand Down Expand Up @@ -226,7 +229,7 @@ public void testRun() throws Exception {
File historyFile = new File(historyDirectory + File.separator + ".hivehistory");
historyFile.delete();
}
HiveConf configuration = new HiveConf();
HiveConf configuration = getHiveConf();
configuration.setBoolVar(ConfVars.HIVE_SESSION_HISTORY_ENABLED, true);
PrintStream oldOut = System.out;
ByteArrayOutputStream dataOut = new ByteArrayOutputStream();
Expand All @@ -239,7 +242,7 @@ public void testRun() throws Exception {
String[] args = {};

try {
new FakeCliDriver().run(args);
new FakeCliDriver(configuration).run(args);
assertTrue(dataOut.toString(), dataOut.toString().contains("test message"));
assertTrue(dataErr.toString(), dataErr.toString().contains("Hive history file="));
assertTrue(dataErr.toString(), dataErr.toString().contains("File: fakeFile is not a file."));
Expand All @@ -260,7 +263,7 @@ public void testRun() throws Exception {
@Test
public void testQuit() throws Exception {

CliSessionState ss = new CliSessionState(new HiveConf());
CliSessionState ss = new CliSessionState(getHiveConf());
ss.err = new SessionStream(System.err);
ss.out = new SessionStream(System.out);

Expand Down Expand Up @@ -290,15 +293,15 @@ public void testQuit() throws Exception {

@Test
public void testProcessSelectDatabase() throws Exception {
CliSessionState sessinState = new CliSessionState(new HiveConf());
CliSessionState.start(sessinState);
CliSessionState sessionState = new CliSessionState(getHiveConf());
CliSessionState.start(sessionState);
ByteArrayOutputStream data = new ByteArrayOutputStream();
sessinState.err = new SessionStream(data);
sessinState.database = "database";
sessionState.err = new SessionStream(data);
sessionState.database = "database";
CliDriver driver = new CliDriver();

try {
driver.processSelectDatabase(sessinState);
driver.processSelectDatabase(sessionState);
fail("shuld be exit");
} catch (ExitException e) {
e.printStackTrace();
Expand All @@ -325,7 +328,7 @@ public void testprocessInitFiles() throws Exception {
FileUtils.write(homeFile, "-- init hive file for test ");
setEnv("HIVE_HOME", homeFile.getParentFile().getParentFile().getAbsolutePath());
setEnv("HIVE_CONF_DIR", homeFile.getParentFile().getAbsolutePath());
CliSessionState sessionState = new CliSessionState(new HiveConf());
CliSessionState sessionState = new CliSessionState(getHiveConf());

ByteArrayOutputStream data = new ByteArrayOutputStream();

Expand Down Expand Up @@ -418,11 +421,20 @@ private static void setEnv(String key, String value) throws Exception {

private static class FakeCliDriver extends CliDriver {

private HiveConf conf;

public FakeCliDriver(HiveConf configuration) {
this.conf = configuration;
}

@Override
protected void setupConsoleReader() throws IOException {
reader = new FakeConsoleReader();
}

protected HiveConf getConf() {
return conf;
}
}

private static class FakeConsoleReader extends ConsoleReader {
Expand Down Expand Up @@ -514,4 +526,8 @@ public int getStatus() {
return status;
}
}

private HiveConf getHiveConf() {
return new HiveConfForTest(this.getClass());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import static org.junit.Assert.assertEquals;

import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.conf.HiveConfForTest;
import org.apache.hadoop.hive.metastore.Warehouse;
import org.apache.hadoop.hive.ql.session.SessionState;
import org.junit.Test;
Expand All @@ -33,8 +33,8 @@ public class TestCliSessionState {
* test default db name
*/
@Test
public void testgetDbName() throws Exception {
SessionState.start(new HiveConf());
public void testGetDbName() throws Exception {
SessionState.start(new HiveConfForTest(getClass()));
assertEquals(Warehouse.DEFAULT_DATABASE_NAME,
SessionState.get().getCurrentDatabase());
}
Expand Down
7 changes: 3 additions & 4 deletions common/src/java/org/apache/hadoop/hive/conf/HiveConf.java
Original file line number Diff line number Diff line change
Expand Up @@ -4582,10 +4582,9 @@ public static enum ConfVars {
HIVE_DECODE_PARTITION_NAME("hive.decode.partition.name", false,
"Whether to show the unquoted partition names in query results."),

HIVE_EXECUTION_ENGINE("hive.execution.engine", "mr", new StringSet(true, "mr", "tez"),
"Chooses execution engine. Options are: mr (Map reduce, default), tez. While MR\n" +
"remains the default engine for historical reasons, it is itself a historical engine\n" +
"and is deprecated in Hive 2 line. It may be removed without further warning."),
HIVE_EXECUTION_ENGINE("hive.execution.engine", "tez", new StringSet(true, "tez", "mr"),
"Chooses execution engine. Options are: 'tez' (Tez, default), 'mr' (MapReduce, deprecated). "+
"MR is a historical engine and is deprecated in Hive 2 line. It may be removed without further warning."),

HIVE_EXECUTION_MODE("hive.execution.mode", "container", new StringSet("container", "llap"),
"Chooses whether query fragments will run in container or in llap"),
Expand Down
98 changes: 98 additions & 0 deletions common/src/test/org/apache/hadoop/hive/conf/HiveConfForTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.hadoop.hive.conf;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import org.apache.hadoop.conf.Configuration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.Joiner;

/**
* This class is mostly used in unit test environment to prevent polluting the
* original HiveConf, and also to provide a way to set some default values for execution.
*/
public class HiveConfForTest extends HiveConf {
private static final Logger LOG = LoggerFactory.getLogger(HiveConfForTest.class.getName());
private String testDataDir;
private Map<String, String> overlay = new HashMap<>();

public HiveConfForTest(Class<?> cls) {
super(cls);
init(cls);
}

public HiveConfForTest(Configuration configuration, Class<?> cls) {
super(configuration, cls);
init(cls);
}

private void init(Class<?> cls) {
initDataDir(cls);
LOG.info("Using test data dir (class: {}): {}", cls.getName(), testDataDir);
// HIVE_USER_INSTALL_DIR is required in DagUtils, let's set one
setValue(HiveConf.ConfVars.HIVE_USER_INSTALL_DIR.varname, testDataDir);
// to avoid the overhead of starting a tez session when creating a new SessionState
// many unit tests don't need actual tez execution, and this can save a lot of time
setValue(HiveConf.ConfVars.HIVE_CLI_TEZ_INITIALIZE_SESSION.varname, "false");
// to avoid the overhead of using a real yarn cluster for unit tests.
setValue("tez.local.mode", "true");
// to avoid the overhead of starting an RPC server of the local DAGAppMaster
setValue("tez.local.mode.without.network", "true");
// tests might assume this is set
setValue("hive.in.tez.test", "true");
// to prevent polluting the git tree with local tez cache folders (like tez-local-cache136810858646778831)
setValue("tez.local.cache.root.folder", System.getProperty("build.dir"));
// prevent RecoveryService from starting, which is not needed in unit tests
setValue("tez.dag.recovery.enabled", "false");
}

public void setValue(String name, String value) {
overlay.put(name, value);
super.set(name, value);
}

/**
* Get a unique directory for storing test data, which is based on the class name of the caller unit test
* and build.dir environment variable (which is set by the surefire plugin, look for root pom.xml).
* @param cls
* @return
*/
private void initDataDir(Class<?> cls) {
testDataDir = new File(
String.format("%s/%s-%d", System.getProperty("build.dir"), cls.getCanonicalName(), System.currentTimeMillis()))
.getPath();
}

public String getTestDataDir() {
return testDataDir;
}

/**
* Get all overlay options as a query string.
* This can be used in jdbc connection related tests where we want to pass
* only the specific values which were set in this class.
*/
public String getOverlayOptionsAsQueryString() {
return Joiner.on(";").withKeyValueSeparator("=").join(overlay);
}
}
6 changes: 0 additions & 6 deletions data/conf/iceberg/llap/hive-site.xml
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,6 @@
<description>Use column stats to annotate stats for physical optimization phase</description>
</property>

<property>
<name>hive.execution.engine</name>
<value>tez</value>
<description>Whether to use MR or Tez</description>
</property>

<property>
<name>tez.am.node-blacklisting.enabled</name>
<value>false</value>
Expand Down
6 changes: 0 additions & 6 deletions data/conf/iceberg/tez/hive-site.xml
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,6 @@
<description>Use column stats to annotate stats for physical optimization phase</description>
</property>

<property>
<name>hive.execution.engine</name>
<value>tez</value>
<description>Whether to use MR or Tez</description>
</property>

<property>
<name>tez.am.node-blacklisting.enabled</name>
<value>false</value>
Expand Down
6 changes: 0 additions & 6 deletions data/conf/llap/hive-site.xml
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,6 @@
<description>The default storatge that stores temporary hive statistics. Currently, fs type is supported</description>
</property>

<property>
<name>hive.execution.engine</name>
<value>tez</value>
<description>Whether to use MR or Tez</description>
</property>

<property>
<name>tez.am.node-blacklisting.enabled</name>
<value>false</value>
Expand Down
Loading

0 comments on commit a9afca6

Please sign in to comment.