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

[Func/Arith] Multiply, Division and Modulus #32

Merged
merged 9 commits into from
Feb 6, 2024
Merged

[Func/Arith] Multiply, Division and Modulus #32

merged 9 commits into from
Feb 6, 2024

Conversation

sanjibansg
Copy link
Contributor

@sanjibansg sanjibansg commented Dec 2, 2023

This PR adds the Multiply, Division, and Modulus functions.

Copy link
Contributor Author

@sanjibansg sanjibansg left a comment

Choose a reason for hiding this comment

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

I have some questions regarding the modulus function in various kernels.

cc: @richtia @EpsilonPrime

dialects/datafusion.yaml Show resolved Hide resolved
dialects/duckdb.yaml Show resolved Hide resolved
@@ -67,8 +67,6 @@ scalar_functions:
- name: modulus
local_name: "%"
infix: True
required_options:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

postgres supports modulus with numeric operands, but as per Substrait documentation, it should only work on integer values.

Copy link
Member

Choose a reason for hiding this comment

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

We'll need to update the substrait docs here too

@@ -37,8 +37,6 @@ scalar_functions:
- name: modulus
local_name: "%"
infix: True
required_options:
Copy link
Contributor Author

@sanjibansg sanjibansg Dec 6, 2023

Choose a reason for hiding this comment

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

SQLite supports two different operations for modulus.

  1. % operator that will not work for non-integer operands.
  2. mod function that shall work for non-integer operands.

Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to test both?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not right now. AFAIK, right now the BFT assumes every dialect has only one implementation of a function. I will create an issue to make it change.

rounding: TIE_TO_EVEN
on_division_by_zero: LIMIT
on_domain_error: NAN
- name: modulus
Copy link
Contributor Author

Choose a reason for hiding this comment

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

cudf also supports mod function on floating points, while the substrait documentation states operation on only integer arguments.

Copy link
Member

Choose a reason for hiding this comment

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

I'll make this change in the substrait spec.

is 0. This is the default behavior in many systems because it helps to avoid
bias in rounding.

#### TIE_AWAY_FROM_ZERO
Copy link
Member

Choose a reason for hiding this comment

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

Ideally we would point to these common options instead of duplicating them everywhere.

Copy link
Member

Choose a reason for hiding this comment

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

@sanjibansg let's use this PR to address the duplication issues

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will have some framework-level changes. I have thought to make a separate YAML file containing the definition of such options. Functions that follow such options, and do not have any exceptions, should fetch the definition from that YAML, or should have their own definition here. I will make a separate PR for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#47

@sanjibansg sanjibansg changed the title feat: more arithmetic supplemental functions [Func/Arith] Multiply, Division and Modulus Feb 2, 2024
@sanjibansg sanjibansg marked this pull request as ready for review February 2, 2024 11:05
@sanjibansg sanjibansg merged commit a2a927a into main Feb 6, 2024
7 checks passed
@sanjibansg sanjibansg deleted the scalar branch February 6, 2024 18:50
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.

3 participants