Skip to content

Add sinh, cosh, tanh pushdown support#438

Open
sfc-gh-amzheng wants to merge 1 commit into
mainfrom
amzheng-math-func-pushdown
Open

Add sinh, cosh, tanh pushdown support#438
sfc-gh-amzheng wants to merge 1 commit into
mainfrom
amzheng-math-func-pushdown

Conversation

@sfc-gh-amzheng

@sfc-gh-amzheng sfc-gh-amzheng commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Closes #45

Problem

sinh, cosh, and tanh are not in the shippable built-in functions list, so queries using them cannot be pushed down to DuckDB. Their inverses (asinh, acosh, atanh) were already shippable.

Solution

Add sinh, cosh, and tanh to ShippableBuiltinProcs in shippable_builtin_functions.c, matching the pattern already used for the inverse functions.

-- Pushed down to DuckDB instead of executed in PostgreSQL
SELECT sinh(x), cosh(x), tanh(x) FROM my_iceberg_table;

Test plan

  • New pytest suite test_mathematical_functions_pushdown.py covers all three functions with pushdown verification

@sfc-gh-amzheng sfc-gh-amzheng force-pushed the amzheng-math-func-pushdown branch from 027f1ba to 78918d0 Compare July 9, 2026 20:33
Mark sinh, cosh and tanh as shippable to DuckDB and add pushdown tests.
No _pg wrapper or query rewrite is needed since DuckDB's behavior matches
PostgreSQL's for all inputs.

Also fix pre-commit config stage names (pre-commit -> commit) to match
the installed pre-commit version.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@sfc-gh-amzheng sfc-gh-amzheng force-pushed the amzheng-math-func-pushdown branch from 78918d0 to a9eb5b3 Compare July 9, 2026 20:35

@sfc-gh-okalaci sfc-gh-okalaci left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

conditional approval: good to go once the test suggestions below are applied. i checked sinh/cosh/tanh against postgres across a wide range (denormals, overflow, ±inf, nan) and they match bit-for-bit, so no wrapper is needed here, that part is correct.

two non-blocking notes:

  • the commit message says it also fixes pre-commit stage names (pre-commit -> commit), but that's not in this diff, and our .pre-commit-config.yaml already uses stages: [pre-commit] (the newer name). looks copied from somewhere else, can we drop that line from the message?
  • looks like #118 does the same three functions. this one follows the review there (no wrappers, just the shippable list), so it looks like the better version. we should close #118 to avoid confusion.

if you hit any issues applying these, let me know.

Comment on lines +306 to +309
SELECT NULL::double precision AS col_val
UNION ALL SELECT 0.0::double precision
UNION ALL SELECT -1.0::double precision
UNION ALL SELECT 1.0::double precision

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add a few normal values here too? like 0.01, 0.5, 1.25, 2.5, some negatives, and -0.0. right now it's only 0/±1 which is a bit thin.

would be nice to also cover inf/-inf/nan, those are the interesting ones for these funcs. note though they won't work with this assert: assert_query_results_on_tables does abs(a-b) <= tol, and inf-inf/nan-nan is nan, so it fails even when both sides match. for those we'd need an exact compare, or assert_table_contents_match (uses EXCEPT ALL, where pg treats inf = inf and nan = nan).

def test_hyperbolic_functions_specific_values(
create_hyperbolic_values_table, pg_conn, func, expected_expression
):
"""Verify sinh/cosh/tanh pushdown returns same results as Postgres for 0, -1, 1, NULL."""

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small: update this line too once the values change, it says only 0, -1, 1, NULL.

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.

Pushdown math hyperbolic functions

2 participants