Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[spark] use cachedRelation.output to build OutputMap in MergePaimonScalarSubqueriers #3148

Merged
merged 2 commits into from
Apr 2, 2024
Merged
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 @@ -36,7 +36,7 @@ object MergePaimonScalarSubqueriers extends MergePaimonScalarSubqueriersBase {
DataSourceV2ScanRelation(
cachedRelation,
cachedScan: PaimonScan,
cachedOutput,
_,
cachedPartitioning)) =>
checkIdenticalPlans(newRelation, cachedRelation).flatMap {
outputMap =>
Expand All @@ -46,7 +46,7 @@ object MergePaimonScalarSubqueriers extends MergePaimonScalarSubqueriersBase {
val mergedAttributes = mergedScan
.readSchema()
.map(f => AttributeReference(f.name, f.dataType, f.nullable, f.metadata)())
val cachedOutputNameMap = cachedOutput.map(a => a.name -> a).toMap
val cachedOutputNameMap = cachedRelation.output.map(a => a.name -> a).toMap
val mergedOutput =
mergedAttributes.map(a => cachedOutputNameMap.getOrElse(a.name, a))
val newV2ScanRelation = DataSourceV2ScanRelation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ object MergePaimonScalarSubqueriers extends MergePaimonScalarSubqueriersBase {
DataSourceV2ScanRelation(
cachedRelation,
cachedScan: PaimonScan,
cachedOutput,
_,
cachedPartitioning,
cacheOrdering)) =>
checkIdenticalPlans(newRelation, cachedRelation).flatMap {
Expand All @@ -57,7 +57,7 @@ object MergePaimonScalarSubqueriers extends MergePaimonScalarSubqueriersBase {
val mergedAttributes = mergedScan
.readSchema()
.map(f => AttributeReference(f.name, f.dataType, f.nullable, f.metadata)())
val cachedOutputNameMap = cachedOutput.map(a => a.name -> a).toMap
val cachedOutputNameMap = cachedRelation.output.map(a => a.name -> a).toMap
val mergedOutput =
mergedAttributes.map(a => cachedOutputNameMap.getOrElse(a.name, a))
val newV2ScanRelation = DataSourceV2ScanRelation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ object MergePaimonScalarSubqueriers extends MergePaimonScalarSubqueriersBase {
DataSourceV2ScanRelation(
cachedRelation,
cachedScan: PaimonScan,
cachedOutput,
_,
cachedPartitioning,
cacheOrdering)) =>
checkIdenticalPlans(newRelation, cachedRelation).flatMap {
Expand All @@ -57,7 +57,7 @@ object MergePaimonScalarSubqueriers extends MergePaimonScalarSubqueriersBase {
val mergedAttributes = mergedScan
.readSchema()
.map(f => AttributeReference(f.name, f.dataType, f.nullable, f.metadata)())
val cachedOutputNameMap = cachedOutput.map(a => a.name -> a).toMap
val cachedOutputNameMap = cachedRelation.output.map(a => a.name -> a).toMap
val mergedOutput =
mergedAttributes.map(a => cachedOutputNameMap.getOrElse(a.name, a))
val newV2ScanRelation = DataSourceV2ScanRelation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ trait MergePaimonScalarSubqueriersBase extends Rule[LogicalPlan] with PredicateH
val newPlan = removeReferences(planWithReferences, cache)
val subqueryCTEs = cache.filter(_.merged).map(_.plan.asInstanceOf[CTERelationDef])
if (subqueryCTEs.nonEmpty) {
WithCTE(newPlan, subqueryCTEs.toSeq)
WithCTE(newPlan, subqueryCTEs)
} else {
newPlan
}
Expand Down Expand Up @@ -130,12 +130,12 @@ trait MergePaimonScalarSubqueriersBase extends Rule[LogicalPlan] with PredicateH
} else {
header.attributes
}
cache(subqueryIndex) = Header(newHeaderAttributes, mergedPlan, true)
cache(subqueryIndex) = Header(newHeaderAttributes, mergedPlan, merged = true)
subqueryIndex -> headerIndex
})
})
.getOrElse {
cache += Header(Seq(output), plan, false)
cache += Header(Seq(output), plan, merged = false)
cache.length - 1 -> 0
}
}
Expand Down Expand Up @@ -292,7 +292,7 @@ trait MergePaimonScalarSubqueriersBase extends Rule[LogicalPlan] with PredicateH
plan)
}

protected def mapAttributes[T <: Expression](expr: T, outputMap: AttributeMap[Attribute]) = {
protected def mapAttributes[T <: Expression](expr: T, outputMap: AttributeMap[Attribute]): T = {
expr.transform { case a: Attribute => outputMap.getOrElse(a, a) }.asInstanceOf[T]
}

Expand Down
Loading