← 输入框|github.com|刷新
Skip to content

DuckDB: generate ATAN2 and POWER with two arguments - #1378

Open
555aaditya wants to merge 1 commit into
sqlancer:mainfrom
555aaditya:fix/duckdb-binary-math-function-arity
Open

555aaditya wants to merge 1 commit into
sqlancer:mainfrom
555aaditya:fix/duckdb-binary-math-function-arity

Conversation

@555aaditya

Copy link
Copy Markdown

DuckDBExpressionGenerator.DBFunction declares ATAN2 and POWER with one argument, but both functions take two. DuckDB rejects every such call with a binder error. DuckDBErrors ignores "You might need to add explicit type casts.", so every query that picked one of these two functions was silently wasted.

Checked against DuckDB 1.3.0.0 (the driver version in pom.xml), using a throwaway JDBC program:

SELECT ATAN2(1)   -> Binder Error: No function matches the given name and argument types 'atan2(INTEGER_LITERAL)'. You might need to add explicit type casts.
                     Candidate functions: atan2(DOUBLE, DOUBLE) -> DOUBLE
SELECT ATAN2(1,2) -> 0.4636476090008061
SELECT POWER(2)   -> Binder Error: No function matches the given name and argument types 'power(INTEGER_LITERAL)'. ... Candidate functions: power(DOUBLE, DOUBLE) -> DOUBLE
SELECT POWER(2,3) -> 8.0

The change declares both functions with two arguments. I looked at the other DBFunction entries and did not find another one with a wrong argument count, but I only checked them by reading, not by running each one.

I did not add a regression test. An embedded-DuckDB unit test is easy to write (I wrote one, and it fails on main and passes with this change), but on macOS it crashed the forked test JVM when it ran after TestStatementReducer: testSQLite3WithStatementReducer leaves its database0..N threads running SQLite code after the timeout, and loading DuckDB into that JVM then aborted with POINTER_BEING_FREED_WAS_NOT_ALLOCATED in DuckDB's zone_free. I did not want to add a flaky test to the unit tier, and I could not check Linux. If you prefer a test in sqlancer.dbms plus a CI line, I am happy to add it.

Verified on macOS (arm64), OpenJDK 11.0.33, Maven 3.10.1:

  • mvn -B verify -DskipTests=true: BUILD SUCCESS.
  • python3 src/check_names.py: exit 0.
  • mvn -Djacoco.skip=true '-Dtest=!sqlancer.dbms.**,!sqlancer.qpg.**' test: 125 tests, 0 failures, 3 skipped (the same as on origin/main).
  • mvn -Djacoco.skip=true -Dtest=TestDuckDBNoREC test: passes (307 s).
  • mvn -Djacoco.skip=true -Dtest=TestDuckDBTLP test: passes (304 s).

@mrigger

Both functions take two arguments (atan2(DOUBLE, DOUBLE) and power(DOUBLE, DOUBLE) are their only signatures in DuckDB 1.3.0.0), but they were declared with one. DuckDB rejected every such call with a binder error, which the expected error "You might need to add explicit type casts." ignores, so the generated queries were wasted.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant