bojana-db commented on code in PR #56864:
URL: https://github.com/apache/spark/pull/56864#discussion_r3748987498
##########
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:
`variant_strip_nulls` mirrors BigQuery's
[JSON_STRIP_NULLS](https://docs.cloud.google.com/bigquery/docs/reference/standard-sql/json_functions#json_strip_nulls),
where `include_arrays` defaults to `TRUE`, so name and default both match
BigQuery. PostgreSQL's `strip_in_arrays=false` is a backward-compat default
(arrays were untouched before PG 18), not an analytics preference. BigQuery
frames the function as data compaction ( ["JSON_STRIP_NULLS compresses the data
by removing JSON nulls ... helpful for reducing data size during
exports"](https://cloud.google.com/blog/products/data-analytics/announcing-new-sql-functions-for-json-in-bigquery)
) which makes sense fot DW/analytics workload and for that use case you
generally want array nulls stripped too.
--
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]