Skip to content

Commit 0d4f96c

Browse files
committed
add upgrade guide
1 parent 3c9802d commit 0d4f96c

File tree

2 files changed

+103
-1142
lines changed

2 files changed

+103
-1142
lines changed

docs/source/library-user-guide/upgrading.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,109 @@ Instead of silently succeeding.
355355

356356
The remove API no longer requires a mutable instance
357357

358+
### `SimplifyInfo` trait removed, `SimplifyContext` now uses builder-style API
359+
360+
The `SimplifyInfo` trait has been removed and replaced with the concrete `SimplifyContext` struct. This simplifies the expression simplification API and removes the need for trait objects.
361+
362+
**Who is affected:**
363+
364+
- Users who implemented custom `SimplifyInfo` implementations
365+
- Users who implemented `ScalarUDFImpl::simplify()` for custom scalar functions
366+
- Users who directly use `SimplifyContext` or `ExprSimplifier`
367+
368+
**Breaking changes:**
369+
370+
1. The `SimplifyInfo` trait has been removed entirely
371+
2. `SimplifyContext` no longer takes `&ExecutionProps` - it now uses a builder-style API with direct fields
372+
3. `ScalarUDFImpl::simplify()` now takes `&SimplifyContext` instead of `&dyn SimplifyInfo`
373+
4. Time-dependent function simplification (e.g., `now()`) is now optional - if `query_execution_start_time` is `None`, these functions won't be simplified
374+
375+
**Migration guide:**
376+
377+
If you implemented a custom `SimplifyInfo`:
378+
379+
**Before:**
380+
381+
```rust,ignore
382+
impl SimplifyInfo for MySimplifyInfo {
383+
fn is_boolean_type(&self, expr: &Expr) -> Result<bool> { ... }
384+
fn nullable(&self, expr: &Expr) -> Result<bool> { ... }
385+
fn execution_props(&self) -> &ExecutionProps { ... }
386+
fn get_data_type(&self, expr: &Expr) -> Result<DataType> { ... }
387+
}
388+
```
389+
390+
**After:**
391+
392+
Use `SimplifyContext` directly with the builder-style API:
393+
394+
```rust,ignore
395+
let context = SimplifyContext::default()
396+
.with_schema(schema)
397+
.with_config_options(config_options)
398+
.with_query_execution_start_time(Some(Utc::now())); // or use .with_current_time()
399+
```
400+
401+
If you implemented `ScalarUDFImpl::simplify()`:
402+
403+
**Before:**
404+
405+
```rust,ignore
406+
fn simplify(
407+
&self,
408+
args: Vec<Expr>,
409+
info: &dyn SimplifyInfo,
410+
) -> Result<ExprSimplifyResult> {
411+
let now_ts = info.execution_props().query_execution_start_time;
412+
// ...
413+
}
414+
```
415+
416+
**After:**
417+
418+
```rust,ignore
419+
fn simplify(
420+
&self,
421+
args: Vec<Expr>,
422+
info: &SimplifyContext,
423+
) -> Result<ExprSimplifyResult> {
424+
// query_execution_start_time is now Option<DateTime<Utc>>
425+
// Return Original if time is not set (simplification skipped)
426+
let Some(now_ts) = info.query_execution_start_time() else {
427+
return Ok(ExprSimplifyResult::Original(args));
428+
};
429+
// ...
430+
}
431+
```
432+
433+
If you created `SimplifyContext` from `ExecutionProps`:
434+
435+
**Before:**
436+
437+
```rust,ignore
438+
let props = ExecutionProps::new();
439+
let context = SimplifyContext::new(&props).with_schema(schema);
440+
```
441+
442+
**After:**
443+
444+
```rust,ignore
445+
let context = SimplifyContext::default()
446+
.with_schema(schema)
447+
.with_config_options(config_options)
448+
.with_current_time(); // Sets query_execution_start_time to Utc::now()
449+
```
450+
451+
**Available `SimplifyContext` methods:**
452+
453+
- `with_schema(DFSchemaRef)` - Set the schema for type resolution
454+
- `with_config_options(Arc<ConfigOptions>)` - Set configuration options
455+
- `with_query_execution_start_time(Option<DateTime<Utc>>)` - Set query start time for time-dependent simplification
456+
- `with_current_time()` - Convenience method to set query start time to `Utc::now()`
457+
- `schema()` - Get the schema
458+
- `query_execution_start_time()` - Get the query start time (returns `Option<DateTime<Utc>>`)
459+
- `config_options()` - Get the configuration options
460+
358461
### FFI crate updates
359462

360463
Many of the structs in the `datafusion-ffi` crate have been updated to allow easier

0 commit comments

Comments
 (0)