Skip to content

Commit 9de85cd

Browse files
rustyconoverclaude
andcommitted
fix: scalar overloads that differ only in column count are not ambiguous
Scalar overload matching counted ConstParams only, and type scoring filled a column the call did not supply with None, which matched any type. f(a) and f(a, b) both matched a one-column call and raised 'Ambiguous function call'. The call's column count must now fit the overload's column Params (or reach its fixed count when it has column varargs). Legacy scalars without column Params are unaffected. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 9ffdbe7 commit 9de85cd

2 files changed

Lines changed: 131 additions & 0 deletions

File tree

‎tests/test_worker.py‎

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,3 +1645,123 @@ def test_bytes_flow_through_init_request(self) -> None:
16451645
# And reconstruction off the InitRequest works the same way.
16461646
payload = _OpaquePayload.deserialize_from_bytes(init_request.bind_opaque_data)
16471647
assert payload == _OpaquePayload(schema_id=42, label="hi")
1648+
1649+
1650+
class TestScalarColumnCountOverloading:
1651+
"""Scalar overloads that differ only in their number of column arguments."""
1652+
1653+
def _candidates(self) -> list[type]:
1654+
class OneCol(ScalarFunction):
1655+
class Meta:
1656+
name = "decode"
1657+
1658+
@classmethod
1659+
def compute(
1660+
cls,
1661+
code: Annotated[pa.StringArray, Param(doc="Code")],
1662+
) -> Annotated[pa.StringArray, Returns()]:
1663+
return code
1664+
1665+
class TwoCol(ScalarFunction):
1666+
class Meta:
1667+
name = "decode"
1668+
1669+
@classmethod
1670+
def compute(
1671+
cls,
1672+
code: Annotated[pa.StringArray, Param(doc="Code")],
1673+
year: Annotated[pa.Int64Array, Param(doc="Year")],
1674+
) -> Annotated[pa.StringArray, Returns()]:
1675+
return code
1676+
1677+
return [OneCol, TwoCol]
1678+
1679+
def test_one_column_picks_one_column_overload(self) -> None:
1680+
"""f(a) with f(a) and f(a, b) declared is not ambiguous."""
1681+
one, two = self._candidates()
1682+
result = Worker._match_function_arguments(
1683+
function_name="decode",
1684+
arguments=Arguments(positional=()),
1685+
input_schema=pa.schema([("code", pa.string())]),
1686+
candidates=[one, two],
1687+
)
1688+
assert result is one
1689+
1690+
def test_two_columns_pick_two_column_overload(self) -> None:
1691+
"""f(a, b) picks the two-column overload."""
1692+
one, two = self._candidates()
1693+
result = Worker._match_function_arguments(
1694+
function_name="decode",
1695+
arguments=Arguments(positional=()),
1696+
input_schema=pa.schema([("code", pa.string()), ("year", pa.int64())]),
1697+
candidates=[one, two],
1698+
)
1699+
assert result is two
1700+
1701+
def test_three_columns_match_neither(self) -> None:
1702+
"""Extra columns rule out overloads without column varargs."""
1703+
one, two = self._candidates()
1704+
with pytest.raises(ValueError, match="No matching function"):
1705+
Worker._match_function_arguments(
1706+
function_name="decode",
1707+
arguments=Arguments(positional=()),
1708+
input_schema=pa.schema([("a", pa.string()), ("b", pa.int64()), ("c", pa.int64())]),
1709+
candidates=[one, two],
1710+
)
1711+
1712+
def test_same_shape_is_still_ambiguous(self) -> None:
1713+
"""Two overloads with identical column shapes still tie."""
1714+
one, _ = self._candidates()
1715+
1716+
class OneColAgain(ScalarFunction):
1717+
class Meta:
1718+
name = "decode"
1719+
1720+
@classmethod
1721+
def compute(
1722+
cls,
1723+
code: Annotated[pa.StringArray, Param(doc="Code")],
1724+
) -> Annotated[pa.StringArray, Returns()]:
1725+
return code
1726+
1727+
with pytest.raises(ValueError, match="Ambiguous function call"):
1728+
Worker._match_function_arguments(
1729+
function_name="decode",
1730+
arguments=Arguments(positional=()),
1731+
input_schema=pa.schema([("code", pa.string())]),
1732+
candidates=[one, OneColAgain],
1733+
)
1734+
1735+
def test_column_varargs_accepts_more_columns(self) -> None:
1736+
"""A column-varargs overload still takes N or more columns next to a fixed one."""
1737+
1738+
class Fixed(ScalarFunction):
1739+
class Meta:
1740+
name = "cat"
1741+
1742+
@classmethod
1743+
def compute(
1744+
cls,
1745+
a: Annotated[pa.StringArray, Param(doc="a")],
1746+
) -> Annotated[pa.StringArray, Returns()]:
1747+
return a
1748+
1749+
class Var(ScalarFunction):
1750+
class Meta:
1751+
name = "cat"
1752+
1753+
@classmethod
1754+
def compute(
1755+
cls,
1756+
a: Annotated[pa.StringArray, Param(doc="a")],
1757+
rest: Annotated[list[pa.StringArray], Param(doc="rest", varargs=True)],
1758+
) -> Annotated[pa.StringArray, Returns()]:
1759+
return a
1760+
1761+
three = pa.schema([("a", pa.string()), ("b", pa.string()), ("c", pa.string())])
1762+
assert (
1763+
Worker._match_function_arguments(
1764+
function_name="cat", arguments=Arguments(positional=()), input_schema=three, candidates=[Fixed, Var]
1765+
)
1766+
is Var
1767+
)

‎vgi/worker.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2485,6 +2485,17 @@ def _filter_by_argument_types(
24852485
delta, matched = Worker._score_types(const_specs, const_types)
24862486
score += delta
24872487

2488+
# The call's column count must fit the overload's column Params. A
2489+
# missing column used to score as a wildcard (type None), so
2490+
# f(a) and f(a, b) both matched a one-column call and the call was
2491+
# reported as ambiguous. Legacy scalars (no column Params) are exempt.
2492+
if matched and input_schema is not None and col_specs:
2493+
fixed_cols = sum(1 for s in col_specs if not s.is_varargs)
2494+
col_varargs = any(s.is_varargs for s in col_specs)
2495+
n_cols = len(input_schema)
2496+
if n_cols < fixed_cols or (n_cols > fixed_cols and not col_varargs):
2497+
matched = False
2498+
24882499
# Score column Param types against input_schema
24892500
if matched and input_schema is not None:
24902501
col_types: list[pa.DataType | None] = []

0 commit comments

Comments
 (0)