Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SMALLEST and LARGEST functions in PyDough #226

Open
knassre-bodo opened this issue Jan 21, 2025 · 0 comments
Open

Add SMALLEST and LARGEST functions in PyDough #226

knassre-bodo opened this issue Jan 21, 2025 · 0 comments
Labels
documentation Improvements or additions to documentation effort - low quick & simple issue enhancement New feature or request user feature Adding a new user-facing feature/functionality

Comments

@knassre-bodo
Copy link
Contributor

knassre-bodo commented Jan 21, 2025

Goal: add a functions to PyDough with the following functionalities, which should be tested e2e (see test_pipeline.py for examples):

  • SMALLEST(X, Y, ...) is equivalent to the SQL function LEAST(X, Y, ...), or the Python min function when called on results from each record (as opposed to be being used as an aggregation).
  • LARGEST(X, Y, ...) is equivalent to the SQL function GREATEST(X, Y, ...), or the Python max function when called on results from each record (as opposed to be being used as an aggregation).

Not every SQL dialect has LEAST or GREATEST, but the ones that don't generally allow MIN or MAX to take in 2+ arguments (in which case they do this behavior instead of aggregation). The way to handle this in SQLGlot is to convert to a 2+ argument call to MIN or MAX. For ANSI, a fallback convert to a convoluted CASE statement can be done (e.g. LEAST(a, b, c) => CASE WHEN a <= LEAST(b, c) THEN a ELSE LEAST(b, c) END with LEAST(b, c) recursively transformed in a similar manner). Both functions should throw an error if called on <2 arguments.

These features need to be documented in the function list documentation

@knassre-bodo knassre-bodo added documentation Improvements or additions to documentation effort - low quick & simple issue enhancement New feature or request user feature Adding a new user-facing feature/functionality labels Jan 21, 2025
@knassre-bodo knassre-bodo changed the title Add SMALLEST and LARGEST in PyDough Add SMALLEST and LARGEST functions in PyDough Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation effort - low quick & simple issue enhancement New feature or request user feature Adding a new user-facing feature/functionality
Projects
None yet
Development

No branches or pull requests

1 participant