Skip to content

fix(#11944): SQL functions declare the arity they enforce - #12461

Merged
robfrank merged 1 commit into
mainfrom
fix/11944-sql-functions-declared-arity
Nov 17, 2026
Merged

robfrank merged 1 commit into
mainfrom
fix/11944-sql-functions-declared-arity

Conversation

@robfrank

@robfrank robfrank commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #11944.

About 46 SQL functions inherited the default arity of SQLFunctionAbstract (0..MAX) and then counted their arguments inside execute(). The parse-time gate (FunctionCall -> checkArity) therefore let a wrong count through, and the caller got an IllegalArgumentException, an InvalidArgumentException or a CommandSQLParsingException(getSyntax()) instead of the uniform CommandSemanticException "expects N arguments" from #11589. Each affected function now declares getMinArgs()/getMaxArgs() and calls checkArity(params) instead of its own count check, and a census in SqlParserRobustnessTest reports any function that rejects a count inside its declared range, whatever exception it throws.

Behavior change (release note): some of these functions used to ignore extra arguments without saying so. They now reject them with CommandSemanticException ("expects N arguments but got M"), for example duration(5, 'hour', 3).

Test plan

  • SqlParserRobustnessTest$RegistryFunctionArity:
    • issue11944FunctionsDeclareTheArityTheyEnforce (54 functions, min-1 and max+1 through SQL)
    • dequantizeInt8RejectsTwoArgumentsAsAnArityError (2 args, and 0 / 4 args read "1 or 3", never "1-3")
    • ensureLabelTypesDeclaresTheOneArgumentItReads (0 and 2 args are arity errors, an empty list stays a value error)
    • countsInsideTheDeclaredRangeAreNeverRejectedForTheirCount (census over every registered function)
    • theArityShapeDetectorRecognisesTheShapesTheIssueNamed (control for the census)
  • Updated expectations to the uniform error: SQLFunctionDurationTest, Issue12362SqlDurationIsoFormTest, SQLFunctionTimeBucketTest, SQLFunctionPhase3Test
  • mvn -o -pl engine -am test -Dtest='com/arcadedb/function/sql/**/*Test,SqlParserRobustnessTest,SQLFunctionTimeBucketTest,*Vector*Test,*Geo*Test,*BellmanFord*Test,*Function*Test' -DexcludedGroups=benchmark,slow: 296 classes, 4729 tests, 0 failures, 0 errors
  • After the adversarial fixes: SqlParserRobustnessTest 35/35, TypeCreationTest (ensureLabelTypes callers) 113/113, vector function tests green

Coverage

Entry point Status
54 functions in the issue11944FunctionsDeclareTheArityTheyEnforce table (geo, graph, math, time, timeseries, vector) fixed, tested at min-1 and max+1
vector.add / vector.subtract (counted through SQLFunctionVectorAbstract.validateParameterCount, now removed) fixed
vector.dequantizeInt8 (1 or 3, never 2) fixed: overrides checkArity, one message for every wrong count
ensureLabelTypes (0..MAX with a hidden non-empty check, extras ignored) fixed: declares 1..1
A function that still declares 0..MAX but counts arguments itself guarded by the census, every registered function probed from min to min+3
Variadic functions that branch on the count (BoolAnd, BoolOr, Average, Sysdate, Date, Set, List, UnionAll, Map) checked by hand: none rejects a count (map()'s even-count check is a value check)

Known gaps

  • The census probes unbounded functions only up to min+3 and skips names containing sleep, load, cypher.run and two-dot names (side effects or slow). A hand-written count check above min+3 in one of those would not be caught.
  • The Cypher and wire-protocol modules were not re-run; a grep shows none asserts on the old messages.

Scope changes

  • Adopted through an issue comment: the vector.add/vector.subtract helper spelling, the vector.avg/max/min/sum/normalizeScores/fuse params.length == 0 checks, and the vector.dequantizeInt8 gap.
  • Adopted from the adversarial pass, appended to the issue body as items 8 and 9: ensureLabelTypes and the vector.dequantizeInt8 gate wording.
  • No non-contextual issues filed.

Adversarial pass

Finding Disposition
ensureLabelTypes declares 0..MAX, refuses zero arguments inside execute() with a message the census cannot classify, and ignores extras Real, contextual: declares 1..1 and calls checkArity; the empty-list check stays as a value check. Test ensureLabelTypesDeclaresTheOneArgumentItReads
vector.dequantizeInt8 told a 0- or 4-argument call "1-3 arguments", which includes the refused 2 Real, contextual: the function overrides checkArity, so the gate and execute() both say "expects 1 or 3 arguments". Asserted in dequantizeInt8RejectsTwoArgumentsAsAnArityError

🤖 Generated with Claude Code


Review cycles

  • cycle 1: 60ff3334d0 (LGTM): classify-pr verdict LGTM on 60ff333; there are no reviews or inline comments on the head, and the three minor non-blocking notes need no code change.

Deferred items

  • skipped: The behavior change is real: extra arguments that used to be silently ignored are now rejected. Examples are duration(5, 'hour', 3) and the vector.avg/max/min/sum/normalizeScores family. The PR body flags it as a release note, so please carry it into the release notes.
    • No code change is needed. The PR body already flags this as a release note. The release notes are written during post-merge by the developer, not in this PR.
  • skipped: Some of the old messages were more descriptive, such as the accepted forms in duration and the syntax string in the vector functions. If the uniform "expects N arguments" message is not enough, consider a short hint, but this is optional.
    • The reviewer marked this optional. The uniform checkArity message is what the issue asked for, and the workflow says not to build beyond the request.
  • skipped: The census skips names containing sleep, load or cypher.run, and names with two dots. The PR body already lists these as known gaps.
    • This is informational only. These gaps are already documented in the PR body as known gaps, and the comment asks for no action.

Final state: clean-approval

Merge is the developer's responsibility: this workflow does not merge PRs.

Summary by CodeRabbit

  • Bug Fixes
    • SQL functions now consistently validate the number of arguments provided and report a clear argument-count error when a call falls outside the supported range.
    • Calls with unsupported argument counts are rejected, including functions that accept a limited range or specific argument counts.

About 46 SQL functions inherited the 0..MAX default arity and counted their
arguments inside execute(), so the parse-time gate let a wrong count through
and the caller got an IllegalArgumentException, InvalidArgumentException or
CommandSQLParsingException instead of the uniform "expects N arguments"
CommandSemanticException. Each now declares getMinArgs()/getMaxArgs() and
calls checkArity(). ensureLabelTypes declares 1..1, and vector.dequantizeInt8
overrides checkArity so every wrong count reads "expects 1 or 3 arguments".
A census in SqlParserRobustnessTest reports any function that rejects a count
inside its declared range.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Explain Change →

Walkthrough

SQL functions now declare supported argument-count bounds and use shared arity validation. Tests cover declared bounds, rejected counts, and the resulting exception messages.

Changes: SQL function arity

Layer / File(s) Summary
Declare and enforce function arity
engine/src/main/java/com/arcadedb/function/sql/{geo,graph,math,misc,time,vector}/*
The functions declare argument-count bounds and delegate count checks to checkArity(params). vector.dequantizeInt8 accepts exactly one or three arguments.
Validate declared bounds and errors
engine/src/test/java/com/arcadedb/engine/timeseries/SQLFunctionTimeBucketTest.java, engine/src/test/java/com/arcadedb/function/sql/time/*, engine/src/test/java/com/arcadedb/function/sql/vector/SQLFunctionPhase3Test.java, engine/src/test/java/com/arcadedb/query/sql/SqlParserRobustnessTest.java
Tests expect the arity exceptions and messages, check declared bounds, and probe registered functions for arity-shaped failures.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Suggested reviewers: lvca

Merge Risk: Low · up to 60ff3

Most SQL functions now reject wrong argument counts uniformly. Two cases still raise the older parsing exception instead of the uniform semantic error: vector.fuse with one argument, and the array form of vector.rrfScore with extra arguments. Neither affects valid queries, so the change is mergeable once these small inconsistencies are fixed or accepted.

Pre-merge checks: Passed 2

Check name Status Explanation
Title check Passed The title names the main change: SQL functions now declare the argument counts they enforce, which matches the raw summary (getMinArgs/getMaxArgs added and checkArity used across many SQL functions). …
Description check Passed The description follows the repository template: it has a summary of what changed, motivation through the linked issue, related issue (#11944), additional notes (behavior change, scope changes, advers…
Full details: Title check

Explanation

The title names the main change: SQL functions now declare the argument counts they enforce, which matches the raw summary (getMinArgs/getMaxArgs added and checkArity used across many SQL functions). It is specific enough for a teammate to scan history. The 'fix(#11944)' prefix is a conventional-commit style with an issue reference, which is acceptable here.

Full details: Description check

Explanation

The description follows the repository template: it has a summary of what changed, motivation through the linked issue, related issue (#11944), additional notes (behavior change, scope changes, adversarial pass, known gaps), and a checklist with the test plan. The checklist's Maven build item is ticked via a scoped test command rather than the full 'mvn clean package', which is a minor gap, and the Motivation section is folded into the opening paragraph rather than under its own heading. These are non-critical.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@mergify

mergify Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is merged.

@codacy-production

codacy-production Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity

Metric Results
Complexity 0

View in Codacy

🟢 Coverage 100.00% diff coverage · -4.56% coverage variation

Metric Results
Coverage variation ✅ -4.56% coverage variation
Diff coverage ✅ 100.00% diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (b65c0f8) 290562 256623 88.32%
Head commit (60ff333) 326262 (+35700) 273267 (+16644) 83.76% (-4.56%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#12461) 170 170 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@github-actions github-actions Bot added engine Core engine: document/schema API has-issue The PR links an issue it resolves severity:minor Cosmetic, documentation, edge case, or a workaround exists sql triage:lgtm PR triage: nothing blocking, ready for a maintainer vector Vector index and embedding search labels Nov 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Triage: triage:lgtm · severity:minor · areas: sql, engine, vector · has-issue

Looks good. This PR gives about 54 SQL functions declared getMinArgs()/getMaxArgs() and replaces their hand-written count checks with checkArity(params). A wrong argument count now fails at the parse-time gate with the uniform CommandSemanticException "expects N arguments". I found no security hazards, unrelated changes or correctness bugs, and I did not run the tests.

What I checked in the diff:

  • Declared bounds: each declared min/max matches the check it replaces. Examples are circle 3..3, bellmanFord 3..4, time_bucket 2..3, vector.fuse and vector.rrfScore 1..MAX, and vector.dequantizeInt8 with its own checkArity override for "1 or 3, never 2".
  • Cleanups: the removed validateParameterCount helper and the unused imports are consistent with the rest of the diff.
  • Null params: SQLFunctionEnsureLabelTypes now calls checkArity(params) first, so dropping its params != null guard is safe.
  • Tests: the four existing tests that asserted the old exceptions were updated. SqlParserRobustnessTest adds three coverage tests: a table with min-1 and max+1 probes, vector.dequantizeInt8 and ensureLabelTypes. It also adds a census over every registered function and a control for the census's arity detector. The census asserts that it reaches the functions the issue named.
  • Conventions: the code follows CLAUDE.md. The tests use the assertThat style, add no wall-clock assertions and add no new dependencies.

Minor, non-blocking points:

  • The behavior change is real: extra arguments that used to be silently ignored are now rejected. Examples are duration(5, 'hour', 3) and the vector.avg/max/min/sum/normalizeScores family. The PR body flags it as a release note, so please carry it into the release notes.
  • Some of the old messages were more descriptive, such as the accepted forms in duration and the syntax string in the vector functions. If the uniform "expects N arguments" message is not enough, consider a short hint, but this is optional.
  • The census skips names containing sleep, load or cypher.run, and names with two dots. The PR body already lists these as known gaps.

@codecov

codecov Bot commented Nov 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.41176% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 80.07%. Comparing base (b65c0f8) to head (60ff333).
⚠️ Report is 11 commits behind head on main.

Files with missing lines Patch % Lines
...on/sql/vector/SQLFunctionVectorDequantizeInt8.java 85.71% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main   #12461      +/-   ##
============================================
- Coverage     80.38%   80.07%   -0.32%     
- Complexity        0      198     +198     
============================================
  Files          2545     2578      +33     
  Lines        290562   292654    +2092     
  Branches      64129    64474     +345     
============================================
+ Hits         233576   234332     +756     
- Misses        33978    35316    +1338     
+ Partials      23008    23006       -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

engine Core engine: document/schema API has-issue The PR links an issue it resolves severity:minor Cosmetic, documentation, edge case, or a workaround exists sql triage:lgtm PR triage: nothing blocking, ready for a maintainer vector Vector index and embedding search

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SQL functions declare arity 0..MAX but enforce a stricter count inside execute() (~46 functions), invisible to the arity census

1 participant