-
Notifications
You must be signed in to change notification settings - Fork 28.7k
[SPARK-52813][CONNECT] Allow DAGs in Spark Connect #51516
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
base: master
Are you sure you want to change the base?
Conversation
getSubqueryExpression.getSubqueryType match { | ||
case proto.SubqueryExpression.SubqueryType.SUBQUERY_TYPE_SCALAR => | ||
UnresolvedScalarSubqueryPlanId(planId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove the Unresolved*PlanId expressions.
case other => | ||
throw InvalidInputErrors.sqlCommandExpectsSqlOrWithRelations(other) | ||
// Only allow a SQL relation or a SQL relation nested in a WithRelations relation. | ||
if (!relation.hasSql && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check is a bit arbitrary. Do we really care?
} | ||
val df = Dataset.ofRows(session, transformRelation(relation), tracker) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Capture the parse time here, use the transformRelation time as a proxy. Long term we may want to look at the use of QueryPlanTracker in general.
val plan = if (relation.getCommon.hasPlanId) { | ||
getCachedRelation(relation.getCommon.getPlanId) | ||
} else { | ||
transformRelation(relation) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am being paranoid here. I hope this does not happen...
@@ -2881,79 +2890,6 @@ class SparkConnectPlanner( | |||
} | |||
} | |||
|
|||
private def isValidSQLWithRefs(query: proto.WithRelations): Boolean = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of this code is replaced by CTEs...
transformSqlWithRefs(getWithRelations) | ||
// Register the plans in the relation cache, so they can be resolved while | ||
// transforming the root relation into a LogicalPlan. | ||
val namedReferences = mutable.Buffer.empty[(String, proto.Relation)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we throw if there are duplicate names?
throw InvalidInputErrors.invalidWithRelationReference() | ||
} | ||
if (common.hasPlanId) { | ||
relationCache.put(common.getPlanId, ref) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we throw if the id is already registered to a different relation?
What changes were proposed in this pull request?
This PR adds support to turn connect plans into DAGs. Currently we inline the structure of a reused query fragment during serialization. This can cause massive bloat, increase plan size. This hurts over the wire performance, and it hurts planning performance.
In order to allow DAGs we add reference relation type. This reference relation contains an plan_id that points to a plan defined in an parent/root WithRelations node.
I have created an optimization rule for scala that leverages this functionality by DAGifing a plan before sending it over the wire.
Why are the changes needed?
This changes in this PR can decrease plan size significantly. This benefits over the wire performance, and it allows for faster planning.
Does this PR introduce any user-facing change?
No.
How was this patch tested?
I have added unit tests for the PlanOptimization in PlanOptimizationSuite.
I have added an end to end test to ClientDatasetSuite.
I still need to add a self contained server side test
Was this patch authored or co-authored using generative AI tooling?
No.