Skip to content

[SPARK-52020][TEST] Build hive-test-udfs.jar from source #50790

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion dev/test-jars.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ sql/connect/common/src/test/resources/artifact-tests/smallJar.jar
sql/core/src/test/resources/SPARK-33084.jar
sql/core/src/test/resources/artifact-tests/udf_noA.jar
sql/hive-thriftserver/src/test/resources/TestUDTF.jar
sql/hive/src/test/noclasspath/hive-test-udfs.jar
sql/hive/src/test/resources/SPARK-21101-1.0.jar
sql/hive/src/test/resources/TestUDTF.jar
sql/hive/src/test/resources/data/files/TestSerDe.jar
Expand Down
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@
-Djdk.reflect.useDirectMethodHandle=false
-Dio.netty.tryReflectionSetAccessible=true
--enable-native-access=ALL-UNNAMED
-Dmvn.executable=${maven.multiModuleProjectDirectory}/build/mvn
</extraJavaTestArgs>
<mariadb.java.client.version>2.7.12</mariadb.java.client.version>
<mysql.connector.version>9.2.0</mysql.connector.version>
Expand Down Expand Up @@ -2621,6 +2622,12 @@
<artifactId>javax.servlet-api</artifactId>
<version>${javaxservlet.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-invoker</artifactId>
<version>3.3.0</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
4 changes: 4 additions & 0 deletions sql/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,10 @@
<artifactId>bcpkix-jdk18on</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-invoker</artifactId>
</dependency>
</dependencies>
<build>
<outputDirectory>target/scala-${scala.binary.version}/classes</outputDirectory>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package org.apache.spark.sql.test

import java.io.File
import java.io.{File, InputStream}
import java.net.URI
import java.nio.file.Files
import java.util.{Locale, UUID}
Expand All @@ -28,9 +28,11 @@ import scala.language.implicitConversions
import scala.util.control.NonFatal

import org.apache.hadoop.fs.Path
import org.apache.maven.shared.invoker.{DefaultInvocationRequest, DefaultInvoker}
import org.scalactic.source.Position
import org.scalatest.{BeforeAndAfterAll, Suite, Tag}
import org.scalatest.concurrent.Eventually
import org.scalatest.matchers.should.Matchers._

import org.apache.spark.SparkFunSuite
import org.apache.spark.sql.{AnalysisException, Row}
Expand Down Expand Up @@ -535,4 +537,16 @@ private[sql] object SQLTestUtils {
None
}
}

private val invoker = new DefaultInvoker()
invoker.setMavenExecutable(new File(System.getProperty("mvn.executable", "mvn")))

final def invokeMaven(pomFile: File): Unit = {
val request = new DefaultInvocationRequest()
.setPomFile(pomFile)
.addArgs(Seq("clean", "package", "-DskipTests").toList.asJava)
.setInputStream(InputStream.nullInputStream())
invoker.execute(request).getExitCode should equal (0)
}

}
4 changes: 4 additions & 0 deletions sql/hive/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@
<artifactId>scalacheck_${scala.binary.version}</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-invoker</artifactId>
Copy link
Member

@pan3793 pan3793 May 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems too overkill to use Maven here, how about calling javac directly? https://github.com/apache/hive/blob/branch-4.0/common/src/java/org/apache/hive/common/util/HiveTestUtils.java#L94

Some additional backgrounds: there were some complains that Spark use two building tools, Maven and SBT, which introduces additional complex to align those behaviors, there is a chance that one of the building tools might be dropped someday.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is necessary to build jar and not only compile Java class. Calling javac directly would require all the dependencies and without Maven it would be necessary to load them.

Using maven invoker here only impacts how test jar is built. It works both with Spark Maven and SBT builds and does not require usage of one over the other to build Spark.

</dependency>
</dependencies>
<profiles>
<profile>
Expand Down
Binary file removed sql/hive/src/test/noclasspath/hive-test-udfs.jar
Binary file not shown.
88 changes: 88 additions & 0 deletions sql/hive/src/test/noclasspath/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.apache.spark</groupId>
<artifactId>hive-test-udfs</artifactId>
<version>4.1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Spark Hive Test UDFS</name>
<licenses>
<license>
<name>Apache-2.0</name>
<url>https://www.apache.org/licenses/LICENSE-2.0.html</url>
<distribution>repo</distribution>
</license>
</licenses>
<organization>
<name>Apache Software Foundation</name>
<url>https://www.apache.org</url>
</organization>

<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<hadoop.version>3.4.1</hadoop.version>
<hive.version>2.3.10</hive.version>
</properties>

<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<outputDirectory>${project.basedir}</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-exec</artifactId>
<version>${hive.version}</version>
<classifier>core</classifier>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-serde</artifactId>
<version>${hive.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-storage-api</artifactId>
<version>2.4.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>${hadoop.version}</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.3</version>
</dependency>
</dependencies>

</project>
Loading