Skip to content

Conversation

kevinzwang
Copy link
Member

@kevinzwang kevinzwang commented May 14, 2025

Changes Made

Added a proc macro that can be used by function expressions to easily convert from function expressions to argument structs.

It can be used as follows:

// deriving the macro
#[derive(FunctionArgs)]
struct TestArgs<T> {
    arg1: T,
    arg2: Vec<T>, // variadic
    arg3: Option<T>, // optional
}

// use the derived TryFrom
let args: FunctionArgs<ExprRef>;

let parsed_args = TestArgs::try_from(args)?;
f(parsed_args.arg1, parsed_args.arg2, parsed_args.arg3)

I've implemented it for all numeric functions (except round, which expects a literal) in this PR

Todo for future PRs:

  • literal arguments
  • implementation in all scalar UDFs
  • use as an associated type with ScalarUDF + autogeneration of function docs using this?

Related Issues

none

Checklist

  • Documented in API Docs (if applicable)
  • Documented in User Guide (if applicable)
  • If adding a new documentation page, doc is added to docs/mkdocs.yml navigation
  • Documentation builds and is formatted properly (tag @/ccmao1130 for docs review)

Copy link

codecov bot commented May 14, 2025

Codecov Report

Attention: Patch coverage is 92.04244% with 30 lines in your changes missing coverage. Please review.

Project coverage is 77.89%. Comparing base (c15ecc5) to head (f938036).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/common/macros/src/function_args.rs 86.27% 21 Missing ⚠️
src/daft-dsl/src/functions/function_args.rs 81.81% 4 Missing ⚠️
src/daft-dsl/src/functions/macro_tests.rs 88.46% 3 Missing ⚠️
src/daft-functions/src/numeric/clip.rs 95.65% 1 Missing ⚠️
src/daft-functions/src/numeric/trigonometry.rs 96.42% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4348      +/-   ##
==========================================
+ Coverage   77.85%   77.89%   +0.04%     
==========================================
  Files         836      839       +3     
  Lines      111927   112105     +178     
==========================================
+ Hits        87139    87323     +184     
+ Misses      24788    24782       -6     
Files with missing lines Coverage Δ
src/common/macros/src/lib.rs 100.00% <100.00%> (ø)
src/daft-dsl/src/functions/mod.rs 86.25% <ø> (ø)
src/daft-functions/src/numeric/abs.rs 86.36% <100.00%> (+3.03%) ⬆️
src/daft-functions/src/numeric/cbrt.rs 84.61% <100.00%> (+2.79%) ⬆️
src/daft-functions/src/numeric/ceil.rs 86.20% <100.00%> (+2.20%) ⬆️
src/daft-functions/src/numeric/exp.rs 78.00% <100.00%> (+5.27%) ⬆️
src/daft-functions/src/numeric/floor.rs 86.36% <100.00%> (+3.03%) ⬆️
src/daft-functions/src/numeric/log.rs 86.48% <100.00%> (+4.20%) ⬆️
src/daft-functions/src/numeric/mod.rs 100.00% <100.00%> (+15.29%) ⬆️
src/daft-functions/src/numeric/sign.rs 85.71% <100.00%> (+1.37%) ⬆️
... and 6 more

... and 5 files with indirect coverage changes

🚀 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.

@kevinzwang kevinzwang marked this pull request as ready for review May 16, 2025 23:17
@kevinzwang kevinzwang enabled auto-merge (squash) May 17, 2025 02:40
@kevinzwang kevinzwang merged commit b16b570 into main May 19, 2025
55 checks passed
@kevinzwang kevinzwang deleted the kevin/function-arg-macro branch May 19, 2025 22:51
kevinzwang added a commit that referenced this pull request May 23, 2025
## Changes Made

Add literal support for the FunctionArgs proc macro. 

Now, instead of using serde to serialize a Rust struct into a
LiteralValue for Python functions, we can just store the Python objects
directly as a `LiteralValue::Python`, and then implement the extraction
to Rust struct in `FromLiteral`. This allows us to remove the
LiteralValue serialization functionality, and also eliminates the need
to special case every type in the Python-exposed `lit` function.

## Related Issues

follow-up on #4348

## Checklist

- [x] Documented in API Docs (if applicable)
- [x] Documented in User Guide (if applicable)
- [x] If adding a new documentation page, doc is added to
`docs/mkdocs.yml` navigation
- [x] Documentation builds and is formatted properly (tag @/ccmao1130
for docs review)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants