You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add SessionConfig reference to ScalarFunctionArgs #13519
Well, small issue. ScalarFunctionArgs is in datafusion-expr which can't use SessionConfig directly since it's in datafusion-execution which depends on datafusion-expr which would cause a circular dependency. We can use ConfigOptions there which would give us access to all config except the opaque extensions in SessionConfig which I think is acceptable.
Started delving into this trying to find a good way to impl. Trying to add config_options: ConfigOptions to ScalarFunctionExpr Having lots of fun with eq and hash with SessionConfig and f64 atm.
We could but it wouldn't solve the issue. The issue is PhysicalExpr requires implementations to impl Eq and Hash or to have implementations for DynEq and DynHash. That is fine until something like SessionConfig which doesn't is introduced. I am looking at updating the either the 'config_namespace' macro or add explicit implementations for 'ScalarFunctionExpr' to try and impl either of the above and use f64.to_bits() and f64::from_bits(..) to handle the problematic f64's in the config. I think it's possible
I mistyped above - I meant we couldn't use SessionContext, not SessionConfig. Sorry about the confusion. ... or not. I need more caffeine today. PR uses ConfigOptions.
This is pretty heavy dependency.
SessionConfig contains a LOT of information no scalar function should depend on and very little that has legitimate usage.
I would prefer not adding SessionConfig to ScalarFunctionArgs. Rather, we could add a stripped down config object dedicated to scalar functions. If time zone is all we need, we should add the time zone directly to ScalarFunctionArgs (like proposed in #16573).
If we just want specific fields, we could perhaps reuse the existing ExecutionProps
Are AliasGenerator and VarProviders relevant to function implementors?
The subset of ConfigOptions that functions might want to access is not clear to me
It's not clear to me either. We know about session time zone. Session start time may be relevant.
Do we need to know all of them from the start, or just anticipate we gonna evolve set of what's accessible as the need arises?
By avoiding full SessionConfig / ConfigOptions, I would like to retain the state where it's very easy to invoke a function, either from a test, a benchmark, or any other execution context.
Exposing sub-configs such SqlParserOptions, ExplainOptions, or OptimizerOptions to UDFs looks like breaking abstractions, or invitation to break abstractions.
I think my next attempt at solving this was to take the same approach that async-udf took - which is to move the invocation of the udf into an ExecutionPlan. That approach provides the full config_options.
Exposing sub-configs such SqlParserOptions, ExplainOptions, or OptimizerOptions to UDFs looks like breaking abstractions, or invitation to break abstractions.
In light of a push to reduce breaking changes like #16622 (and #16078, #16541, #13648) we could try to be more judicious about growing the public API. IF we don't need to expose full SessionConfig / ConfigOptions in ScalarFunctionArgs let's maybe not expose them.
In light of a push to reduce breaking changes like #16622 (and #16078, #16541, #13648) we could try to be more judicious about growing the public API. IF we don't need to expose full SessionConfig / ConfigOptions in ScalarFunctionArgs let's maybe not expose them.
My counter argument is that having to add new fields to ExecutionProps basically increases the public API over time. ConfigOptions is already public so it is my opinion that exposing just the ConfigOptions is less API surface area. I can see how there are alternate opinions to this
Here is what passing in the entire ConfigOptions looks like (it is pretty straightforward actually): #16661
BTW i solved my problem by adding the needed fields into the UDF struct during it construction and then I don't need any more info at simplify() & invoke() time. When doing so, I had this observation -- #16677
Activity
Omega359 commentedon Nov 21, 2024
Well, small issue.
ScalarFunctionArgsis indatafusion-exprwhich can't useSessionConfigdirectly since it's indatafusion-executionwhich depends ondatafusion-exprwhich would cause a circular dependency. We can useConfigOptionsthere which would give us access to all config except the opaque extensions inSessionConfigwhich I think is acceptable.niebayes commentedon Nov 21, 2024
Great work!
Omega359 commentedon Nov 21, 2024
Started delving into this trying to find a good way to impl. Trying to add
config_options: ConfigOptionstoScalarFunctionExprHaving lots of fun with eq and hash with SessionConfig and f64 atm.alamb commentedon Nov 21, 2024
I wonder if we can use this trait: https://docs.rs/datafusion/latest/datafusion/catalog/trait.Session.html
Omega359 commentedon Nov 21, 2024
We could but it wouldn't solve the issue. The issue is PhysicalExpr requires implementations to impl Eq and Hash or to have implementations for DynEq and DynHash. That is fine until something like SessionConfig which doesn't is introduced. I am looking at updating the either the 'config_namespace' macro or add explicit implementations for 'ScalarFunctionExpr' to try and impl either of the above and use f64.to_bits() and f64::from_bits(..) to handle the problematic f64's in the config. I think it's possible
jayzhan211 commentedon Nov 22, 2024
It makes sense to me to move
SessionConfigto common or common-runtime crateOmega359 commentedon Nov 22, 2024
take
alamb commentedon Nov 22, 2024
I agree
Omega359 commentedon Nov 22, 2024
I mistyped above - I meant we couldn't use SessionContext, not SessionConfig. Sorry about the confusion.... or not. I need more caffeine today. PR uses ConfigOptions.jayzhan211 commentedon Dec 8, 2024
I guess we can also add
nullableinfo toScalarFunctionArgs#11923alamb commentedon Dec 8, 2024
It might already be present in
ScalarFunctionArgs::data_type🤔 :datafusion/datafusion/expr/src/udf.rs
Line 336 in f2de2c4
jayzhan211 commentedon Dec 9, 2024
Not really,
DataTypehas no nullable info, we have to sendnullabletoScalarFunctionArgsdatafusion/datafusion/physical-expr/src/scalar_function.rs
Lines 148 to 153 in 6c9355d
alamb commentedon Dec 9, 2024
Ah I was thinking about the nullable info that is part of embedded
Fields -- but that only affects Lists/Maps, etcfindepi commentedon Jun 26, 2025
This is pretty heavy dependency.
SessionConfig contains a LOT of information no scalar function should depend on and very little that has legitimate usage.
I would prefer not adding SessionConfig to ScalarFunctionArgs. Rather, we could add a stripped down config object dedicated to scalar functions. If time zone is all we need, we should add the time zone directly to
ScalarFunctionArgs(like proposed in #16573).alamb commentedon Jun 26, 2025
https://docs.rs/datafusion/latest/datafusion/execution/config/struct.SessionConfig.html is mostly a wrapper around the ConfigOptions
If we just want specific fields, we could perhaps reuse the existing ExecutionProps
I think the challenge is that
ConfigOptionsthat functions might want to access is not clear to meThat doesn't mean we couldn't copy a subset of the fields into ScalarFunctionArgs, it just seems unecessary to try and pick that subset 🤔
findepi commentedon Jun 26, 2025
Are AliasGenerator and VarProviders relevant to function implementors?
It's not clear to me either. We know about session time zone. Session start time may be relevant.
Do we need to know all of them from the start, or just anticipate we gonna evolve set of what's accessible as the need arises?
By avoiding full SessionConfig / ConfigOptions, I would like to retain the state where it's very easy to invoke a function, either from a test, a benchmark, or any other execution context.
Exposing sub-configs such SqlParserOptions, ExplainOptions, or OptimizerOptions to UDFs looks like breaking abstractions, or invitation to break abstractions.
Omega359 commentedon Jun 26, 2025
I think my next attempt at solving this was to take the same approach that async-udf took - which is to move the invocation of the udf into an ExecutionPlan. That approach provides the full config_options.
findepi commentedon Jul 1, 2025
In light of a push to reduce breaking changes like #16622 (and #16078, #16541, #13648) we could try to be more judicious about growing the public API. IF we don't need to expose full SessionConfig / ConfigOptions in ScalarFunctionArgs let's maybe not expose them.
alamb commentedon Jul 2, 2025
My counter argument is that having to add new fields to ExecutionProps basically increases the public API over time.
ConfigOptionsis already public so it is my opinion that exposing just theConfigOptionsis less API surface area. I can see how there are alternate opinions to thisHere is what passing in the entire ConfigOptions looks like (it is pretty straightforward actually): #16661
findepi commentedon Jul 4, 2025
BTW i solved my problem by adding the needed fields into the UDF struct during it construction and then I don't need any more info at simplify() & invoke() time. When doing so, I had this observation -- #16677
alamb commentedon Aug 5, 2025
Closed in #16970