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

Bump Spark 3.5.5 #6939

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,35 @@ package org.apache.kyuubi.spark.connector.hive

import java.lang.{Boolean => JBoolean, Long => JLong}

import scala.util.Try

import org.apache.hadoop.fs.{FileStatus, Path}
import org.apache.hadoop.hive.ql.plan.{FileSinkDesc, TableDesc}
import org.apache.spark.SPARK_VERSION
import org.apache.spark.internal.Logging
import org.apache.spark.sql.SparkSession
import org.apache.spark.sql.catalyst.InternalRow
import org.apache.spark.sql.catalyst.catalog.{CatalogTable, CatalogTablePartition}
import org.apache.spark.sql.connector.catalog.TableChange
import org.apache.spark.sql.connector.catalog.TableChange.{AddColumn, After, ColumnPosition, DeleteColumn, First, RenameColumn, UpdateColumnComment, UpdateColumnNullability, UpdateColumnPosition, UpdateColumnType}
import org.apache.spark.sql.connector.catalog.TableChange._
import org.apache.spark.sql.execution.command.CommandUtils
import org.apache.spark.sql.execution.command.CommandUtils.{calculateMultipleLocationSizes, calculateSingleLocationSize}
import org.apache.spark.sql.execution.datasources.{PartitionDirectory, PartitionedFile}
import org.apache.spark.sql.hive.execution.HiveFileFormat
import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.types.{ArrayType, MapType, StructField, StructType}

import org.apache.kyuubi.spark.connector.common.SparkUtils.SPARK_RUNTIME_VERSION
import org.apache.kyuubi.util.reflect.{DynClasses, DynConstructors, DynMethods}
import org.apache.kyuubi.util.reflect.ReflectUtils.invokeAs

object HiveConnectorUtils extends Logging {

// SPARK-43186
def getHiveFileFormat(fileSinkConf: FileSinkDesc): HiveFileFormat = {
if (SPARK_RUNTIME_VERSION >= "3.5") {
def getHiveFileFormat(fileSinkConf: FileSinkDesc): HiveFileFormat =
Try { // SPARK-43186: 3.5.0
DynConstructors.builder()
.impl(classOf[HiveFileFormat], classOf[FileSinkDesc])
.build[HiveFileFormat]()
.newInstance(fileSinkConf)
} else if (SPARK_RUNTIME_VERSION >= "3.3") {
}.recover { case _: Exception =>
val shimFileSinkDescClz = DynClasses.builder()
.impl("org.apache.spark.sql.hive.HiveShim$ShimFileSinkDesc")
.build()
Expand All @@ -67,34 +66,26 @@ object HiveConnectorUtils extends Logging {
.impl(classOf[HiveFileFormat], shimFileSinkDescClz)
.build[HiveFileFormat]()
.newInstance(shimFileSinkDesc)
} else {
throw unsupportedSparkVersion()
}
}
}.get

// SPARK-41970
def partitionedFilePath(file: PartitionedFile): String = {
if (SPARK_RUNTIME_VERSION >= "3.4") {
def partitionedFilePath(file: PartitionedFile): String =
Try { // SPARK-41970: 3.4.0
invokeAs[String](file, "urlEncodedPath")
} else if (SPARK_RUNTIME_VERSION >= "3.3") {
}.recover { case _: Exception =>
invokeAs[String](file, "filePath")
} else {
throw unsupportedSparkVersion()
}
}
}.get

def splitFiles(
sparkSession: SparkSession,
file: AnyRef,
filePath: Path,
isSplitable: Boolean,
maxSplitBytes: Long,
partitionValues: InternalRow): Seq[PartitionedFile] = {

if (SPARK_RUNTIME_VERSION >= "4.0") { // SPARK-42821
isSplitable: JBoolean,
maxSplitBytes: JLong,
partitionValues: InternalRow): Seq[PartitionedFile] =
Try { // SPARK-42821: 4.0.0-preview2
val fileStatusWithMetadataClz = DynClasses.builder()
.impl("org.apache.spark.sql.execution.datasources.FileStatusWithMetadata")
.build()
.buildChecked()
DynMethods
.builder("splitFiles")
.impl(
Expand All @@ -103,35 +94,58 @@ object HiveConnectorUtils extends Logging {
classOf[Boolean],
classOf[Long],
classOf[InternalRow])
.build()
.invoke[Seq[PartitionedFile]](
.buildChecked()
.invokeChecked[Seq[PartitionedFile]](
null,
file,
isSplitable.asInstanceOf[JBoolean],
maxSplitBytes.asInstanceOf[JLong],
isSplitable,
maxSplitBytes,
partitionValues)
} else if (SPARK_RUNTIME_VERSION >= "3.5") { // SPARK-43039
}.recover { case _: Exception => // SPARK-51185: Spark 3.5.5
val fileStatusWithMetadataClz = DynClasses.builder()
.impl("org.apache.spark.sql.execution.datasources.FileStatusWithMetadata")
.build()
.buildChecked()
DynMethods
.builder("splitFiles")
.impl(
"org.apache.spark.sql.execution.PartitionedFileUtil",
classOf[SparkSession],
fileStatusWithMetadataClz,
classOf[Path],
classOf[Boolean],
classOf[Long],
classOf[InternalRow])
.build()
.invoke[Seq[PartitionedFile]](
.buildChecked()
.invokeChecked[Seq[PartitionedFile]](
null,
sparkSession,
file,
filePath,
isSplitable,
maxSplitBytes,
partitionValues)
}.recover { case _: Exception => // SPARK-43039: 3.5.0
val fileStatusWithMetadataClz = DynClasses.builder()
.impl("org.apache.spark.sql.execution.datasources.FileStatusWithMetadata")
.buildChecked()
DynMethods
.builder("splitFiles")
.impl(
"org.apache.spark.sql.execution.PartitionedFileUtil",
classOf[SparkSession],
fileStatusWithMetadataClz,
classOf[Boolean],
classOf[Long],
classOf[InternalRow])
.buildChecked()
.invokeChecked[Seq[PartitionedFile]](
null,
sparkSession,
file,
isSplitable.asInstanceOf[JBoolean],
maxSplitBytes.asInstanceOf[JLong],
isSplitable,
maxSplitBytes,
partitionValues)
} else if (SPARK_RUNTIME_VERSION >= "3.3") {
}.recover { case _: Exception =>
DynMethods
.builder("splitFiles")
.impl(
Expand All @@ -142,55 +156,41 @@ object HiveConnectorUtils extends Logging {
classOf[Boolean],
classOf[Long],
classOf[InternalRow])
.build()
.invoke[Seq[PartitionedFile]](
.buildChecked()
.invokeChecked[Seq[PartitionedFile]](
null,
sparkSession,
file,
filePath,
isSplitable.asInstanceOf[JBoolean],
maxSplitBytes.asInstanceOf[JLong],
isSplitable,
maxSplitBytes,
partitionValues)
} else {
throw unsupportedSparkVersion()
}
}
}.get

def createPartitionDirectory(values: InternalRow, files: Seq[FileStatus]): PartitionDirectory = {
if (SPARK_RUNTIME_VERSION >= "3.5") {
def createPartitionDirectory(values: InternalRow, files: Seq[FileStatus]): PartitionDirectory =
Try { // SPARK-43039: 3.5.0
new DynMethods.Builder("apply")
.impl(classOf[PartitionDirectory], classOf[InternalRow], classOf[Array[FileStatus]])
.buildChecked()
.asStatic()
.invoke[PartitionDirectory](values, files.toArray)
} else if (SPARK_RUNTIME_VERSION >= "3.3") {
}.recover { case _: Exception =>
new DynMethods.Builder("apply")
.impl(classOf[PartitionDirectory], classOf[InternalRow], classOf[Seq[FileStatus]])
.buildChecked()
.asStatic()
.invoke[PartitionDirectory](values, files)
} else {
throw unsupportedSparkVersion()
}
}
}.get

def getPartitionFilePath(file: AnyRef): Path = {
if (SPARK_RUNTIME_VERSION >= "3.5") {
def getPartitionFilePath(file: AnyRef): Path =
Try { // SPARK-43039: 3.5.0
new DynMethods.Builder("getPath")
.impl("org.apache.spark.sql.execution.datasources.FileStatusWithMetadata")
.build()
.invoke[Path](file)
} else if (SPARK_RUNTIME_VERSION >= "3.3") {
}.recover { case _: Exception =>
file.asInstanceOf[FileStatus].getPath
} else {
throw unsupportedSparkVersion()
}
}

private def unsupportedSparkVersion(): KyuubiHiveConnectorException = {
KyuubiHiveConnectorException(s"Spark version $SPARK_VERSION " +
"is not supported by Kyuubi spark hive connector.")
}
}.get

def calculateTotalSize(
spark: SparkSession,
Expand Down
17 changes: 15 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@
DO NOT forget to change the following properties when change the minor version of Spark:
`delta.version`, `delta.artifact`, `maven.plugin.scalatest.exclude.tags`
-->
<spark.version>3.5.4</spark.version>
<spark.version>3.5.5</spark.version>
<spark.binary.version>3.5</spark.binary.version>
<spark.archive.scala.suffix></spark.archive.scala.suffix>
<spark.archive.name>spark-${spark.version}-bin-hadoop3${spark.archive.scala.suffix}.tgz</spark.archive.name>
Expand Down Expand Up @@ -1287,6 +1287,18 @@
<name>Maven Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
</repository>

<repository>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>staging</id>
<name>Spark 3.5.5 Staging Repository</name>
<url>https://repository.apache.org/content/repositories/orgapachespark-1476/</url>
</repository>
</repositories>

<pluginRepositories>
Expand Down Expand Up @@ -2044,11 +2056,12 @@
<module>extensions/spark/kyuubi-spark-connector-hive</module>
</modules>
<properties>
<spark.version>3.5.4</spark.version>
<spark.version>3.5.5</spark.version>
<spark.binary.version>3.5</spark.binary.version>
<delta.version>3.3.0</delta.version>
<delta.artifact>delta-spark_${scala.binary.version}</delta.artifact>
<maven.plugin.scalatest.exclude.tags>org.scalatest.tags.Slow</maven.plugin.scalatest.exclude.tags>
<spark.archive.mirror>https://dist.apache.org/repos/dist/dev/spark/v3.5.5-rc1-bin</spark.archive.mirror>
</properties>
</profile>

Expand Down
Loading