refactor: Improve SessionContext::parse_duration API#20816
refactor: Improve SessionContext::parse_duration API#20816kosiew merged 3 commits intoapache:mainfrom
SessionContext::parse_duration API#20816Conversation
230014c to
15c302a
Compare
kosiew
left a comment
There was a problem hiding this comment.
Thanks for working on this.
docs/source/library-user-guide/upgrading/52.0.0.md:54
The user-facing docs are still inconsistent for datafusion.runtime.list_files_cache_ttl. This upgrade guide continues to say the setting limits TTL “in seconds”, even though the parser accepts both minutes and seconds.
| @@ -1347,7 +1353,9 @@ impl SessionContext { | |||
There was a problem hiding this comment.
parse_duration is doing unchecked u64 arithmetic when combining minutes and seconds:
For large inputs such as SET datafusion.runtime.list_files_cache_ttl = '307445734561825861m', minutes * 60 overflows before Duration::from_secs is reached. In debug/test builds that panics instead of returning a planning error.
This means malformed user input can still crash the statement path rather than producing a DataFusion error.
This needs an overflow-checked path (checked_mul / checked_add) and a test that exercises the oversized value through SET.
Extract a small helper for the checked accumulation here so the parser logic stays readable and the overflow error can consistently include config_name.
There was a problem hiding this comment.
@kosiew Good point and addressed by the last commit. Thanks.
There was a problem hiding this comment.
a test that exercises the oversized value through SET.
I don't see this test.
Am I missing something?
There was a problem hiding this comment.
I have added test_parse_duration_with_overflow_check using SessionContext::parse_duration() for comprehensive coverage and SET Command is another use case to execute SessionContext::parse_duration() so i have also added SqlLogicalTests. Please check the last commit.
dee482e to
821274a
Compare
0b58c3b to
77dea07
Compare
77dea07 to
f2f7b59
Compare
f2f7b59 to
ad3518c
Compare
## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes apache#123` indicates that this PR will close issue apache#123. --> - Closes apache#20815. ## Rationale for this change This is follow-up PR for apache#20371. Similarly to `SessionContext::parse_capacity_limit` API, `SessionContext::parse_duration` API also needs to have following improvements: 1. Validation for empty or blank duration values: ``` SET datafusion.runtime.list_files_cache_ttl = ' ' Current: DataFusion error: Error during planning: Failed to parse number from duration ' ' New: DataFusion error: Error during planning: Duration should not be empty or blank for 'datafusion.runtime.list_files_cache_ttl' ``` 2. Exposing config name in error messages, 3. Comprehensive test coverage for invalid durations, 4. Updating `datafusion.runtime.list_files_cache_ttl` documentation for other allowed settings. ## What changes are included in this PR? Explained in the first section. ## Are these changes tested? Yes, being extended existing test cases. ## Are there any user-facing changes? Yes, config name has been added to error message when the validation is failed.
## Which issue does this PR close? - Closes #21354. ## Rationale for this change Currently, DataFusion supports 9 `datafusion.format.*` configs but their test coverage seem to be missed so this issue aims to add comprehensive test coverage for them. This is follow-up to recent `config framework` improvements: #20372 and #20816. ## What changes are included in this PR? New test coverage is being added for `datafusion.format.*` configs. ## Are these changes tested? Yes, new test coverage is being added for `datafusion.format.*` configs. ## Are there any user-facing changes? No
## Which issue does this PR close? - Closes apache#21354. ## Rationale for this change Currently, DataFusion supports 9 `datafusion.format.*` configs but their test coverage seem to be missed so this issue aims to add comprehensive test coverage for them. This is follow-up to recent `config framework` improvements: apache#20372 and apache#20816. ## What changes are included in this PR? New test coverage is being added for `datafusion.format.*` configs. ## Are these changes tested? Yes, new test coverage is being added for `datafusion.format.*` configs. ## Are there any user-facing changes? No
Which issue does this PR close?
SessionContext::parse_durationAPI #20815.Rationale for this change
This is follow-up PR for #20371.
Similarly to
SessionContext::parse_capacity_limitAPI,SessionContext::parse_durationAPI also needs to have following improvements:datafusion.runtime.list_files_cache_ttldocumentation for other allowed settings.What changes are included in this PR?
Explained in the first section.
Are these changes tested?
Yes, being extended existing test cases.
Are there any user-facing changes?
Yes, config name has been added to error message when the validation is failed.