-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-46600][SQL] Move shared code between SqlConf and SqlApiConf to SqlApiConfHelper #44602
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
Conversation
sql/api/src/main/scala/org/apache/spark/sql/internal/SqlApiConfHelper.scala
Outdated
Show resolved
Hide resolved
| private[sql] def setConfGetter(getter: () => SqlApiConf): Unit = { | ||
| confGetter.set(getter) | ||
| } | ||
| private val confGetter = SqlApiConfHelper.getConfGetter |
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.
do we need this val? def get: SqlApiConf = SqlApiConfHelper.getConfGetter.get()()
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.
Right. Consolidated.
| new AtomicReference[() => SqlApiConf](() => DefaultSqlApiConf) | ||
| } | ||
|
|
||
| def getConfGetter: AtomicReference[() => SqlApiConf] = confGetter |
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.
If this line is called in a JVM before any code touches object SQLConf, are we going to return DefaultSqlApiConf which is wrong?
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.
@hvanhovell Do you know if the scenario mentioned here could happen?
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.
@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.
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.
@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
SQLConfobject. This loads and initialises theSQLConfobject. The loading of theSQLConfobject triggers the initialisation of theSqlApiConfHelperbecause it needs to set the setter, and it needs to load the shared keys. - User touces the
SqlApiConfobject. This tries to load theSQLConfobject as part of its initialisation (see previous bullet), if it is on the classpath the getter will be updated to return theSQLConf.
0d989b0 to
e4997bf
Compare
|
|
||
| import java.util.concurrent.atomic.AtomicReference | ||
|
|
||
| private[sql] object SqlApiConfHelper { |
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.
Can you add some documentation explaining why this is needed? And how this code should never be used by an end-user.
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.
+1 to document the rules to use SqlApiConfHelper.
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.
done
hvanhovell
left a comment
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.
LGTM
|
Merging to master/3.5 |
… 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]>
…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]>
What changes were proposed in this pull request?
This code proposes to introduce a new object named
SqlApiConfHelperto contain shared code betweenSqlApiConfandSqlConf.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