uros-b commented on code in PR #56864:
URL: https://github.com/apache/spark/pull/56864#discussion_r3740617648
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/variant/variantExpressions.scala:
##########
@@ -1490,6 +1490,92 @@ object VariantArrayAppendExpressionBuilder extends
VariantArrayAppendExpressionB
// scalastyle:on line.size.limit
object TryVariantArrayAppendExpressionBuilder
extends VariantArrayAppendExpressionBuilderBase(false)
+case class VariantStripNulls(child: Expression, includeArrays: Expression)
+ extends RuntimeReplaceable
+ with ExpectsInputTypes
+ with BinaryLike[Expression]
+ with QueryErrorsBase {
+
+ override def left: Expression = child
+ override def right: Expression = includeArrays
+
+ override def inputTypes: Seq[AbstractDataType] = Seq(VariantType,
BooleanType)
+
+ override def checkInputDataTypes(): TypeCheckResult = {
+ val result = super.checkInputDataTypes()
+ if (result.isFailure) {
+ result
+ } else if (!includeArrays.foldable) {
+ DataTypeMismatch(
+ errorSubClass = "NON_FOLDABLE_INPUT",
+ messageParameters = Map(
+ "inputName" -> toSQLId("include_arrays"),
+ "inputType" -> toSQLType(includeArrays.dataType),
+ "inputExpr" -> toSQLExpr(includeArrays)))
+ } else {
+ TypeCheckResult.TypeCheckSuccess
+ }
+ }
+
+ override lazy val replacement: Expression = StaticInvoke(
+ VariantExpressionEvalUtils.getClass,
+ VariantType,
+ "stripNulls",
+ Seq(child, includeArrays),
+ inputTypes,
+ returnNullable = false)
+
+ override def prettyName: String = "variant_strip_nulls"
+
+ override protected def withNewChildrenInternal(
+ newLeft: Expression, newRight: Expression): VariantStripNulls =
+ copy(child = newLeft, includeArrays = newRight)
+}
+
+// scalastyle:off line.size.limit
+@ExpressionDescription(
+ usage = "_FUNC_(v[, include_arrays]) - Recursively removes object fields and
array elements " +
+ "whose value is a variant null, unless `include_arrays` is false, in which
case null array " +
+ "elements are kept. Returns NULL if any argument is NULL.",
+ arguments = """
+ Arguments:
+ * v - A variant value to mutate.
+ * include_arrays - An optional boolean (default true). Must be a
constant.
Review Comment:
Why default true? PostgreSQL 18 `json_strip_nulls` defaults to false
(https://www.postgresql.org/docs/devel/functions-json.html):
```
If strip_in_arrays is true (the default is false), null array elements are
also stripped.
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]