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

[GLUTEN-4039][VL] Support array insert function for spark 3.4+ #7123

Merged
merged 1 commit into from
Sep 6, 2024
Merged
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 @@ -1365,4 +1365,30 @@ abstract class ScalarFunctionsValidateSuite extends FunctionsValidateSuite {
checkGlutenOperatorMatch[ProjectExecTransformer]
}
}

testWithSpecifiedSparkVersion("array insert", Some("3.4")) {
withTempPath {
path =>
Seq[Seq[Integer]](Seq(1, null, 5, 4), Seq(5, -1, 8, 9, -7, 2), Seq.empty, null)
.toDF("value")
.write
.parquet(path.getCanonicalPath)

spark.read.parquet(path.getCanonicalPath).createOrReplaceTempView("array_tbl")

Seq("true", "false").foreach {
legacyNegativeIndex =>
withSQLConf("spark.sql.legacy.negativeIndexInArrayInsert" -> legacyNegativeIndex) {
runQueryAndCompare("""
|select
| array_insert(value, 1, 0), array_insert(value, 10, 0),
| array_insert(value, -1, 0), array_insert(value, -10, 0)
|from array_tbl
|""".stripMargin) {
checkGlutenOperatorMatch[ProjectExecTransformer]
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,14 @@ object ExpressionConverter extends SQLConfHelper with Logging {
replaceWithExpressionTransformer0(a.function, attributeSeq, expressionsMap),
a
)
case arrayInsert if arrayInsert.getClass.getSimpleName.equals("ArrayInsert") =>
// Since spark 3.4.0
val children = SparkShimLoader.getSparkShims.extractExpressionArrayInsert(arrayInsert)
GenericExpressionTransformer(
substraitExprName,
children.map(replaceWithExpressionTransformer0(_, attributeSeq, expressionsMap)),
arrayInsert
)
case s: Shuffle =>
GenericExpressionTransformer(
substraitExprName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ object ExpressionNames {
final val SHUFFLE = "shuffle"
final val ZIP_WITH = "zip_with"
final val FLATTEN = "flatten"
final val ARRAY_INSERT = "array_insert"

// Map functions
final val CREATE_MAP = "map"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,8 @@ trait SparkShims {
DecimalType(math.min(integralLeastNumDigits + newScale, 38), newScale)
}
}

def extractExpressionArrayInsert(arrayInsert: Expression): Seq[Expression] = {
throw new UnsupportedOperationException("ArrayInsert not supported.")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ class Spark34Shims extends SparkShims {
Sig[TimestampAdd](ExpressionNames.TIMESTAMP_ADD),
Sig[RoundFloor](ExpressionNames.FLOOR),
Sig[RoundCeil](ExpressionNames.CEIL),
Sig[Mask](ExpressionNames.MASK)
Sig[Mask](ExpressionNames.MASK),
Sig[ArrayInsert](ExpressionNames.ARRAY_INSERT)
)
}

Expand Down Expand Up @@ -492,4 +493,9 @@ class Spark34Shims extends SparkShims {
RebaseSpec(LegacyBehaviorPolicy.CORRECTED)
)
}

override def extractExpressionArrayInsert(arrayInsert: Expression): Seq[Expression] = {
val expr = arrayInsert.asInstanceOf[ArrayInsert]
Seq(expr.srcArrayExpr, expr.posExpr, expr.itemExpr, Literal(expr.legacyNegativeIndex))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ class Spark35Shims extends SparkShims {
Sig[Mask](ExpressionNames.MASK),
Sig[TimestampAdd](ExpressionNames.TIMESTAMP_ADD),
Sig[RoundFloor](ExpressionNames.FLOOR),
Sig[RoundCeil](ExpressionNames.CEIL)
Sig[RoundCeil](ExpressionNames.CEIL),
Sig[ArrayInsert](ExpressionNames.ARRAY_INSERT)
)
}

Expand Down Expand Up @@ -517,4 +518,9 @@ class Spark35Shims extends SparkShims {
RebaseSpec(LegacyBehaviorPolicy.CORRECTED)
)
}

override def extractExpressionArrayInsert(arrayInsert: Expression): Seq[Expression] = {
val expr = arrayInsert.asInstanceOf[ArrayInsert]
Seq(expr.srcArrayExpr, expr.posExpr, expr.itemExpr, Literal(expr.legacyNegativeIndex))
}
}
Loading