ganeshashree commented on code in PR #58450:
URL: https://github.com/apache/spark/pull/58450#discussion_r3930734559
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/jsonExpressions.scala:
##########
@@ -1651,6 +1651,129 @@ object JsonArray {
}
}
+// Built-in forms for the plain SQL/JSON constructor and path-function calls
that `AstBuilder`
+// routes through function resolution. Each rebuilds its expression with the
standard clause
+// defaults when unshadowed.
+
+@ExpressionDescription(
+ usage = "_FUNC_([expr[, ...]]) - Returns a JSON array string with NULL
elements dropped.",
+ arguments = """
+ Arguments:
+ * expr - the elements to place in the array.
+ """,
+ examples = """
+ Examples:
+ > SELECT _FUNC_(1, 'x', true);
+ [1,"x",true]
+ > SELECT _FUNC_(1, NULL, 3);
+ [1,3]
+ > SELECT _FUNC_();
+ []
+ """,
+ since = "4.4.0",
+ group = "json_funcs")
+object JsonArrayExpressionBuilder extends ExpressionBuilder {
+ override def build(funcName: String, expressions: Seq[Expression]):
Expression = {
+ // A routed call carries no lexical FORMAT JSON, so every element is a
plain value (quoted).
+ // Splicing a nested constructor is only reachable via `JSON_ARRAY(...)`
syntax (which freezes
+ // the decision lexically); doing so through a routed call is left as a
follow-up.
+ val flags = expressions.map(_ => false)
+ JsonArray(expressions, flags, flags, JsonConstructorNullBehavior.Absent,
StringType)
+ }
+}
+
+/**
+ * Shared builder for the plain `JSON_VALUE` / `JSON_QUERY` / `JSON_EXISTS`
forms. The path must
+ * be a foldable string expression; the parser-only SQL/JSON syntax supplies a
string literal,
+ * while ordinary function-call syntax can reach this builder with any
constant string expression.
+ */
+abstract class JsonPathExpressionBuilder extends ExpressionBuilder {
+ protected def buildWithPath(jsonExpr: Expression, path: String): Expression
+
+ override final def build(funcName: String, expressions: Seq[Expression]):
Expression = {
+ if (expressions.length != 2) {
+ throw QueryCompilationErrors.wrongNumArgsError(funcName, Seq(2),
expressions.length)
+ }
+ val pathExpr = expressions(1)
+ pathExpr.dataType match {
+ case _: StringType if pathExpr.foldable =>
+ val pathValue = pathExpr.eval()
Review Comment:
Agreed. It mirrors `Extract.createExpr` and only affects
foldable-but-throwing path expressions, so leaving it for now. Captured in the
"Follow-ups" section.
--
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]