Skip to content

Commit 5b5ef92

Browse files
rustyconoverclaude
andcommitted
sum_all_columns: accept DECIMAL input (promote to float64)
Round-3 review surfaced that DECIMAL inputs were being silently dropped along with strings/timestamps/lists. DECIMAL is a numeric type by the SQL standard — users routinely expect a sum of decimals to be summable. Now treat decimals the same as float: promote to float64 in the output schema. Imprecise (a more rigorous fix would widen the decimal type to absorb overflow), but appropriate for a test fixture. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent fd37864 commit 5b5ef92

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

‎vgi/_test_fixtures/table_in_out.py‎

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -456,11 +456,14 @@ def cardinality(cls, params: BindParams[SumAllColumnsFunctionArguments]) -> Tabl
456456
def on_bind(cls, params: BindParams[SumAllColumnsFunctionArguments]) -> BindResponse:
457457
"""Produce the output schema with only numeric columns.
458458
459-
Raises ValueError if the input has zero numeric (integer or float)
460-
columns. The function has nothing to sum in that case and would
461-
otherwise produce an empty output schema, which crashes downstream
462-
operators with an internal assertion. Reject loudly at bind time
463-
instead so the user sees a clear "no numeric columns" error.
459+
Numeric here means integer, floating-point, or fixed-precision
460+
decimal. DECIMAL inputs are promoted to float64 in the output
461+
(matching the float path) — DuckDB users routinely expect a sum
462+
of DECIMAL values to be summable, so silently dropping them would
463+
be surprising. Non-numeric inputs (strings, lists, timestamps,
464+
booleans) are filtered out; if NO numeric columns remain we raise
465+
ValueError at bind time rather than producing an empty output
466+
schema (which would crash downstream with an internal assertion).
464467
"""
465468
assert params.bind_call.input_schema is not None
466469
output_fields: dict[str, pa.DataType] = {}
@@ -470,6 +473,12 @@ def on_bind(cls, params: BindParams[SumAllColumnsFunctionArguments]) -> BindResp
470473
out_type = pa.int64()
471474
elif pa.types.is_floating(field.type):
472475
out_type = pa.float64()
476+
elif pa.types.is_decimal(field.type):
477+
# Promote DECIMAL to float64 for the summed output.
478+
# (A more precise implementation would widen the decimal
479+
# type to absorb sum overflow, but for a test fixture
480+
# this is sufficient.)
481+
out_type = pa.float64()
473482
else:
474483
continue
475484
output_fields[field.name] = out_type
@@ -479,8 +488,8 @@ def on_bind(cls, params: BindParams[SumAllColumnsFunctionArguments]) -> BindResp
479488
f"{f.name}: {f.type}" for f in params.bind_call.input_schema
480489
)
481490
raise ValueError(
482-
"sum_all_columns requires at least one numeric (integer or "
483-
"float) input column, got [" + input_summary + "]"
491+
"sum_all_columns requires at least one numeric (integer, "
492+
"floating-point, or decimal) input column, got [" + input_summary + "]"
484493
)
485494

486495
return BindResponse(output_schema=schema(output_fields))

0 commit comments

Comments
 (0)