Skip to content

Conversation

@amaliujia
Copy link
Contributor

What changes were proposed in this pull request?

This code proposes to introduce a new object named SqlApiConfHelper to contain shared code between SqlApiConf and SqlConf.

Why are the changes needed?

As of now, SqlConf will access some of the variables of SqlApiConf while SqlApiConf also try to initialize SqlConf upon initialization. This PR is to avoid potential circular dependency between SqlConf and SqlApiConf. The shared variables or access to the shared variables are moved to the new SqlApiConfHelper. So either SqlApiConf and SqlConf wants to initialize the other side, they will only initialize the same third object.

Does this PR introduce any user-facing change?

NO

How was this patch tested?

Existing UT

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

NO

@github-actions github-actions bot added the SQL label Jan 5, 2024
@amaliujia
Copy link
Contributor Author

@cloud-fan @hvanhovell

private[sql] def setConfGetter(getter: () => SqlApiConf): Unit = {
confGetter.set(getter)
}
private val confGetter = SqlApiConfHelper.getConfGetter
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need this val? def get: SqlApiConf = SqlApiConfHelper.getConfGetter.get()()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right. Consolidated.

new AtomicReference[() => SqlApiConf](() => DefaultSqlApiConf)
}

def getConfGetter: AtomicReference[() => SqlApiConf] = confGetter
Copy link
Member

@zsxwing zsxwing Jan 5, 2024

Choose a reason for hiding this comment

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

If this line is called in a JVM before any code touches object SQLConf, are we going to return DefaultSqlApiConf which is wrong?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hvanhovell Do you know if the scenario mentioned here could happen?

Copy link
Contributor

Choose a reason for hiding this comment

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

@zsxwing good point! How about this: We make SqlApiConf the only place to deal with the active conf problem. It should use reflection to get the active SQLConf and set it as the getter. SQLConf should only access this new SqlApiConfHelper for config names.

Copy link
Contributor

Choose a reason for hiding this comment

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

@zsxwing I don't think it is an issue. An end user should never touch this object unless they know what they are doing. That is a limitation of this approach, we should document this, and we can add a liniting rule if we must.

Just to make sure that we are on the same page. In a normal situation, the initialisation is as follows:

  • User touches the SQLConf object. This loads and initialises the SQLConf object. The loading of the SQLConf object triggers the initialisation of the SqlApiConfHelper because it needs to set the setter, and it needs to load the shared keys.
  • User touces the SqlApiConf object. This tries to load the SQLConf object as part of its initialisation (see previous bullet), if it is on the classpath the getter will be updated to return the SQLConf.


import java.util.concurrent.atomic.AtomicReference

private[sql] object SqlApiConfHelper {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add some documentation explaining why this is needed? And how this code should never be used by an end-user.

Copy link
Member

Choose a reason for hiding this comment

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

+1 to document the rules to use SqlApiConfHelper.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor

@hvanhovell hvanhovell left a comment

Choose a reason for hiding this comment

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

LGTM

@hvanhovell
Copy link
Contributor

Merging to master/3.5

@hvanhovell hvanhovell closed this in 03fc5e2 Jan 9, 2024
hvanhovell pushed a commit that referenced this pull request Jan 9, 2024
… SqlApiConfHelper

### What changes were proposed in this pull request?

This code proposes to introduce a new object named `SqlApiConfHelper` to contain shared code between `SqlApiConf` and `SqlConf`.

### Why are the changes needed?

As of now, SqlConf will access some of the variables of SqlApiConf while SqlApiConf also try to initialize SqlConf upon initialization.  This PR is to avoid potential circular dependency between SqlConf and SqlApiConf. The shared variables or access to the shared variables are moved to the new `SqlApiConfHelper`. So either SqlApiConf and SqlConf wants to initialize the other side, they will only initialize the same third object.

### Does this PR introduce _any_ user-facing change?

NO

### How was this patch tested?

Existing UT

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

NO

Closes #44602 from amaliujia/refactor_sql_api.

Authored-by: Rui Wang <[email protected]>
Signed-off-by: Herman van Hovell <[email protected]>
(cherry picked from commit 03fc5e2)
Signed-off-by: Herman van Hovell <[email protected]>
turboFei added a commit to turboFei/spark that referenced this pull request Nov 6, 2025
…qlApiConf to SqlApiConfHelper (apache#655)

[SPARK-46600][SQL] Move shared code between SqlConf and SqlApiConf to SqlApiConfHelper

This code proposes to introduce a new object named `SqlApiConfHelper` to contain shared code between `SqlApiConf` and `SqlConf`.

As of now, SqlConf will access some of the variables of SqlApiConf while SqlApiConf also try to initialize SqlConf upon initialization.  This PR is to avoid potential circular dependency between SqlConf and SqlApiConf. The shared variables or access to the shared variables are moved to the new `SqlApiConfHelper`. So either SqlApiConf and SqlConf wants to initialize the other side, they will only initialize the same third object.

NO

Existing UT

NO

Closes apache#44602 from amaliujia/refactor_sql_api.

Authored-by: Rui Wang <[email protected]>

(cherry picked from commit 03fc5e2)

Signed-off-by: Herman van Hovell <[email protected]>
Co-authored-by: Rui Wang <[email protected]>
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.

4 participants