Skip to content

Commit fc1c1fe

Browse files
committed
fix: preserve SeriesValue advance API
1 parent c456e67 commit fc1c1fe

1 file changed

Lines changed: 18 additions & 9 deletions

File tree

datafusion/functions-table/src/generate_series.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,17 @@ pub trait SeriesValue: fmt::Debug + Clone + Send + Sync + 'static {
7979
/// Check if we've reached the end of the series
8080
fn should_stop(&self, end: Self, step: &Self::StepType, include_end: bool) -> bool;
8181

82-
/// Advance to the next value in the series
82+
/// Advance to the next value in the series.
83+
fn advance(&mut self, step: &Self::StepType) -> Result<()>;
84+
85+
/// Advance to the next value, adjusting the end of the series if needed.
8386
///
84-
/// If advancing would overflow the value range, `end` is updated so that
85-
/// the series terminates after the current value (matching the behavior
86-
/// of PostgreSQL and DuckDB, which return the reachable values instead of
87-
/// erroring).
88-
fn advance(&mut self, end: &mut Self, step: &Self::StepType) -> Result<()>;
87+
/// The default implementation preserves the behavior of [`Self::advance`].
88+
/// Implementations can override this method when they need to handle an
89+
/// overflow by terminating the series after the current value.
90+
fn advance_with_end(&mut self, _end: &mut Self, step: &Self::StepType) -> Result<()> {
91+
self.advance(step)
92+
}
8993

9094
/// Create an Arrow array from a vector of values
9195
fn create_array(&self, values: Vec<Self::ValueType>) -> Result<ArrayRef>;
@@ -105,7 +109,12 @@ impl SeriesValue for i64 {
105109
reach_end_int64(*self, end, *step, include_end)
106110
}
107111

108-
fn advance(&mut self, end: &mut Self, step: &Self::StepType) -> Result<()> {
112+
fn advance(&mut self, step: &Self::StepType) -> Result<()> {
113+
*self += step;
114+
Ok(())
115+
}
116+
117+
fn advance_with_end(&mut self, end: &mut Self, step: &Self::StepType) -> Result<()> {
109118
if let Some(next) = self.checked_add(*step) {
110119
*self = next;
111120
} else {
@@ -171,7 +180,7 @@ impl SeriesValue for TimestampValue {
171180
}
172181
}
173182

174-
fn advance(&mut self, _end: &mut Self, step: &Self::StepType) -> Result<()> {
183+
fn advance(&mut self, step: &Self::StepType) -> Result<()> {
175184
let tz = self
176185
.parsed_tz
177186
.unwrap_or_else(|| Tz::from_str("+00:00").unwrap());
@@ -450,7 +459,7 @@ impl<T: SeriesValue> LazyBatchGenerator for GenericSeriesState<T> {
450459
}
451460

452461
let original_end = self.end.clone();
453-
self.current.advance(&mut self.end, &self.step)?;
462+
self.current.advance_with_end(&mut self.end, &self.step)?;
454463
if self
455464
.current
456465
.should_stop(self.end.clone(), &self.step, self.include_end)

0 commit comments

Comments
 (0)