Skip to content

Commit 8befbe6

Browse files
xiedeyantuCopilot
andcommitted
update
Co-authored-by: Copilot <copilot@github.com>
1 parent 3e0c792 commit 8befbe6

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

datafusion/functions-table/src/generate_series.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,12 @@ impl<T: SeriesValue> LazyBatchGenerator for GenericSeriesState<T> {
395395
.should_stop(self.end.clone(), &self.step, self.include_end)
396396
{
397397
buf.push(self.current.to_value_type());
398-
self.current.advance(&self.step)?;
398+
// Advance to the next value. If advancing overflows (e.g. current
399+
// is i64::MAX and step is 1), the series is exhausted – stop here
400+
// rather than returning an error, matching PostgreSQL/DuckDB behavior.
401+
if self.current.advance(&self.step).is_err() {
402+
break;
403+
}
399404
}
400405

401406
if buf.is_empty() {

datafusion/sqllogictest/test_files/table_functions.slt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,13 @@ SELECT * FROM generate_series(1, 2, 3, 4)
183183
statement error DataFusion error: Error during planning: Argument \#1 must be an INTEGER, TIMESTAMP, DATE or NULL, got Utf8
184184
SELECT * FROM generate_series('foo', 'bar')
185185

186-
# Regression test: generate_series with a step that would advance past i64::MAX must
187-
# return an execution error rather than panicking (overflow in integer iterator).
188-
statement error DataFusion error: Execution error: generate_series: integer overflow while advancing series
186+
# Regression test: generate_series with a step that would overflow i64 after the last
187+
# included value must return the reachable values rather than an error, matching
188+
# PostgreSQL/DuckDB behavior.
189+
query I
189190
SELECT * FROM generate_series(9223372036854775806, 9223372036854775807, 2)
191+
----
192+
9223372036854775806
190193

191194
# UDF and UDTF `generate_series` can be used simultaneously
192195
query ? rowsort

0 commit comments

Comments
 (0)