Skip to content

[SPARK-48344][SQL] Add Frames and Scopes to support Exception Handlers and Local Variables#49006

Closed
miland-db wants to merge 38 commits intoapache:masterfrom
miland-db:milan-dankovic_data/refactor-execution-3
Closed

[SPARK-48344][SQL] Add Frames and Scopes to support Exception Handlers and Local Variables#49006
miland-db wants to merge 38 commits intoapache:masterfrom
miland-db:milan-dankovic_data/refactor-execution-3

Conversation

@miland-db
Copy link
Contributor

@miland-db miland-db commented Nov 28, 2024

What changes were proposed in this pull request?

This PR is third in series of refactoring and introducing SQL Scripting Execution Framework:

  • Introducing SqlScriptingExecutionContext, object to keep current state of script execution.
  • Introducing Frames and Scopes to support Local Variables and Error Handlers resolution.
  • Decoupled SqlScriptingIterator from SqlScriptExecution.
  • Enabling execution of SQL Scripting using sql() API.
  • Updated SqlScriptingExecutionNodeSuite so tests remain independent of concept of Frames and Scopes.

First PR
Second PR

Why are the changes needed?

This changes are needed to enable introduction of Error Handling mechanism and Local Variables.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

Existing tests that were updated to support new concepts introduced in this PR.

Was this patch authored or co-authored using generative AI tooling?

No.

@miland-db miland-db marked this pull request as draft November 28, 2024 14:53
@github-actions github-actions bot added the SQL label Nov 28, 2024
# Conflicts:
#	sql/core/src/main/scala/org/apache/spark/sql/scripting/SqlScriptingExecution.scala
#	sql/core/src/main/scala/org/apache/spark/sql/scripting/SqlScriptingExecutionNode.scala
#	sql/core/src/main/scala/org/apache/spark/sql/scripting/SqlScriptingInterpreter.scala
#	sql/core/src/test/scala/org/apache/spark/sql/scripting/SqlScriptingExecutionNodeSuite.scala
#	sql/core/src/test/scala/org/apache/spark/sql/scripting/SqlScriptingExecutionSuite.scala
#	sql/core/src/test/scala/org/apache/spark/sql/scripting/SqlScriptingInterpreterSuite.scala
@miland-db miland-db marked this pull request as ready for review December 3, 2024 14:18
@miland-db
Copy link
Contributor Author

@miland-db miland-db changed the title [DRAFT][SPARK-48344][SQL] Add Frames and Scopes to support Exception Handlers and Local Variables [SPARK-48344][SQL] Add Frames and Scopes to support Exception Handlers and Local Variables Dec 3, 2024
Copy link
Contributor

@davidm-db davidm-db left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comments, LGTM otherwise

@davidm-db
Copy link
Contributor

@MaxGekk @cloud-fan Can someone please review this PR when you have some time? It's been waiting for a couple of days for a review.

# Conflicts:
#	sql/core/src/main/scala/org/apache/spark/sql/scripting/SqlScriptingInterpreter.scala
@miland-db miland-db requested a review from MaxGekk December 11, 2024 13:10
@miland-db miland-db requested a review from MaxGekk December 11, 2024 18:00
Copy link
Member

@MaxGekk MaxGekk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Waiting for CI.

@MaxGekk
Copy link
Member

MaxGekk commented Dec 12, 2024

+1, LGTM. All GAs (job link) passed. Merging to master.
Thank you, @miland-db and @davidm-db @dusantism-db @dejankrak-db for review.

@MaxGekk MaxGekk closed this in b5d195a Dec 12, 2024
collection: Seq[CompoundPlanStatement],
label: Option[String]) extends Command with CompoundPlanStatement {
label: Option[String],
isScope: Boolean) extends Command with CompoundPlanStatement {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add parameter doc for this new parameter.

}

def enterScope(label: String): Unit = {
scopes.addOne(new SqlScriptingExecutionScope(label))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is addOne the same as append?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is the same. It will be updated in the follow-up PRs.


// Remove all scopes until the one with the given label.
while (scopes.nonEmpty && scopes.last.label != label) {
scopes.remove(scopes.length - 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it the same as scopes.dropRight(1)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, semantically it is doing the same thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove is modifying ListBuffer scopes, and dropRight returns new ListBuffer instance. I would keep remove for performance reasons.

* @param label
* Label set by user to CompoundBody or None otherwise.
* @param isScope
* Flag that indicates whether Compound Body is scope or not.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't tell anything... what does is scope mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will provide more detailed explanation in the follow-up PR.

// This check makes this operation idempotent.
if (isScope && scopeStatus == ScopeStatus.NOT_ENTERED) {
scopeStatus = ScopeStatus.INSIDE
context.enterScope(label.get)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only labeled statement has scope?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, only labeled statements can actually be scope, but not all labeled statements are scope. Only CompoundBody can be scope.

*/
class SqlScriptingExecutionContext {
// List of frames that are currently active.
val frames: ListBuffer[SqlScriptingExecutionFrame] = ListBuffer.empty
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to confirm: as of today, we can only have at most one frame, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants