Skip to content
Closed
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 @@ -992,7 +992,7 @@ class Analyzer(override val catalogManager: CatalogManager) extends RuleExecutor
if (metaCols.isEmpty) {
node
} else {
val newNode = addMetadataCol(node, metaCols.map(_.exprId).toSet)
val newNode = node.mapChildren(addMetadataCol(_, metaCols.map(_.exprId).toSet))
// We should not change the output schema of the plan. We should project away the extra
// metadata columns if necessary.
if (newNode.sameOutput(node)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import org.apache.spark.sql.catalyst.encoders.ExpressionEncoder
import org.apache.spark.sql.catalyst.expressions._
import org.apache.spark.sql.catalyst.expressions.aggregate.{AggregateExpression, Count, Sum}
import org.apache.spark.sql.catalyst.parser.CatalystSqlParser.parsePlan
import org.apache.spark.sql.catalyst.plans.{Cross, Inner}
import org.apache.spark.sql.catalyst.plans.{Cross, FullOuter, Inner, UsingJoin}
import org.apache.spark.sql.catalyst.plans.logical._
import org.apache.spark.sql.catalyst.plans.physical.{HashPartitioning, Partitioning, RangePartitioning, RoundRobinPartitioning}
import org.apache.spark.sql.catalyst.util._
Expand Down Expand Up @@ -1387,4 +1387,21 @@ class AnalysisSuite extends AnalysisTest with Matchers {
assert(!cg.rightOrder.flatMap(_.references).exists(cg.left.output.contains))
}
}

test("SPARK-40149: add metadata column with no extra project") {
val t1 = LocalRelation($"key".int, $"value".string).as("t1")
val t2 = LocalRelation($"key".int, $"value".string).as("t2")
val query =
Project(Seq($"t1.key", $"t2.key"),
Join(t1, t2, UsingJoin(FullOuter, Seq("key")), None, JoinHint.NONE))
checkAnalysis(
query,
Project(Seq($"t1.key", $"t2.key"),
Project(Seq(coalesce($"t1.key", $"t2.key").as("key"),
$"t1.value", $"t2.value", $"t1.key", $"t2.key"),
Join(t1, t2, FullOuter, Some($"t1.key" === $"t2.key"), JoinHint.NONE)
)
).analyze
)
}
}