dtenedor commented on code in PR #60367:
URL: https://github.com/apache/spark/pull/60367#discussion_r4636791487
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/SubstituteParamsParser.scala:
##########
@@ -134,11 +164,16 @@ class SubstituteParamsParser extends Logging {
case Some(value) =>
// Substitute all occurrences of this parameter
locationList.foreach { location =>
- substitutions += Substitution(location, value)
+ substitutions += Substitution(location, namedReplacement(sqlText,
location, value))
Review Comment:
Thanks, fixed. `SubstituteParamsParser` now returns a
`ParameterSubstitution`, which records whether it parsed the statement with
optional references. `SparkSqlParser.parseInternal` passes that to a new
`AbstractParser.parse(command, withOptionalReferences)`, which then starts in
that mode, so every remaining `?` keeps the meaning the substitution gave it.
The existing `substitute` and `ParameterHandler.substituteParameters`
signatures delegate to the new methods unchanged. New `ParametersSuite` test:
your query returns (1, 2), and (NULL, 2) when `x` is unbound. It also checks
the legacy constants-only binding mode and `EXECUTE IMMEDIATE ... USING 1 AS x`.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/SemiStructuredExtract.scala:
##########
@@ -50,7 +51,11 @@ case object ExtractSemiStructuredFields extends
Rule[LogicalPlan] {
override def apply(plan: LogicalPlan): LogicalPlan =
plan.resolveExpressionsWithPruning(
_.containsPattern(SEMI_STRUCTURED_EXTRACT), ruleId) {
case SemiStructuredExtract(column, field) if column.resolved =>
- if (column.dataType.isInstanceOf[VariantType]) {
+ if (OptionalReferences.isNullReference(column)) {
Review Comment:
Thanks, fixed in both analyzers. When an extraction returns NULL because its
base is the NULL of a missing reference,
`OptionalReferences.extractedFromNullReference` now makes that NULL a null
reference with the reference's position. That covers
`ColumnResolutionHelper.resolveExtractValue` and `ExtractValueResolver`.
`ExtractSemiStructuredFields` and `SemiStructuredExtractResolver` look through
the alias that names the extraction (`holdsNullReference`). Golden case:
`SELECT CAST(arr?[0]:a AS STRING) AS a, CAST(missing?['k'].f:a AS STRING) AS b
FROM VALUES (1) AS t(id)` returns NULL, NULL. The cast is there because the
Thrift server variant of the golden file can't read a VARIANT column.
--
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]