Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-49534][CORE][3.5] No longer prepend sql/hiveand sql/hive-thriftserver when spark-hive_xxx.jar is not in the classpath #48046

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ List<String> buildClassPath(String appClassPath) throws IOException {

boolean prependClasses = !isEmpty(getenv("SPARK_PREPEND_CLASSES"));
boolean isTesting = "1".equals(getenv("SPARK_TESTING"));
boolean isTestingSql = "1".equals(getenv("SPARK_SQL_TESTING"));
String jarsDir = findJarsDir(getSparkHome(), getScalaVersion(), !isTesting && !isTestingSql);
if (prependClasses || isTesting) {
String scala = getScalaVersion();
List<String> projects = Arrays.asList(
Expand Down Expand Up @@ -170,7 +172,28 @@ List<String> buildClassPath(String appClassPath) throws IOException {
"NOTE: SPARK_PREPEND_CLASSES is set, placing locally compiled Spark classes ahead of " +
"assembly.");
}
boolean shouldPrePendSparkHive = isJarAvailable(jarsDir, "spark-hive_");
boolean shouldPrePendSparkHiveThriftServer =
shouldPrePendSparkHive && isJarAvailable(jarsDir, "spark-hive-thriftserver_");
for (String project : projects) {
// SPARK-49534: The assumption here is that if `spark-hive_xxx.jar` is not in the
// classpath, then the `-Phive` profile was not used during package, and therefore
// the Hive-related jars should also not be in the classpath. To avoid failure in
// loading the SPI in `DataSourceRegister` under `sql/hive`, no longer prepend `sql/hive`.
if (!shouldPrePendSparkHive && project.equals("sql/hive")) {
continue;
}
// SPARK-49534: Meanwhile, due to the strong dependency of `sql/hive-thriftserver`
// on `sql/hive`, the prepend for `sql/hive-thriftserver` will also be excluded
// if `spark-hive_xxx.jar` is not in the classpath. On the other hand, if
// `spark-hive-thriftserver_xxx.jar` is not in the classpath, then the
// `-Phive-thriftserver` profile was not used during package, and therefore,
// jars such as hive-cli and hive-beeline should also not be included in the classpath.
// To avoid the inelegant startup failures of tools such as spark-sql, in this scenario,
// `sql/hive-thriftserver` will no longer be prepended to the classpath.
if (!shouldPrePendSparkHiveThriftServer && project.equals("sql/hive-thriftserver")) {
continue;
}
addToClassPath(cp, String.format("%s/%s/target/scala-%s/classes", sparkHome, project,
scala));
}
Expand All @@ -191,8 +214,6 @@ List<String> buildClassPath(String appClassPath) throws IOException {
// Add Spark jars to the classpath. For the testing case, we rely on the test code to set and
// propagate the test classpath appropriately. For normal invocation, look for the jars
// directory under SPARK_HOME.
boolean isTestingSql = "1".equals(getenv("SPARK_SQL_TESTING"));
String jarsDir = findJarsDir(getSparkHome(), getScalaVersion(), !isTesting && !isTestingSql);
if (jarsDir != null) {
addToClassPath(cp, join(File.separator, jarsDir, "*"));
}
Expand Down Expand Up @@ -224,6 +245,24 @@ private void addToClassPath(Set<String> cp, String entries) {
}
}

/**
* Checks if a JAR file with a specific prefix is available in the given directory.
*
* @param jarsDir the directory to search for JAR files
* @param jarNamePrefix the prefix of the JAR file name to look for
* @return true if a JAR file with the specified prefix is found, false otherwise
*/
private boolean isJarAvailable(String jarsDir, String jarNamePrefix) {
if (jarsDir != null) {
for (File f : new File(jarsDir).listFiles()) {
if (f.getName().startsWith(jarNamePrefix)) {
return true;
}
}
}
return false;
}

String getScalaVersion() {
String scala = getenv("SPARK_SCALA_VERSION");
if (scala != null) {
Expand Down
Loading