Skip to content

Commit

Permalink
feat: add modulus function
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjibansg committed Dec 6, 2023
1 parent 7370528 commit 79baeaa
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 11 deletions.
4 changes: 3 additions & 1 deletion dialects/cudf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ scalar_functions:
overflow: SILENT # cudf rolls over on overflow
rounding: TIE_TO_EVEN
- name: divide
local_name: division
local_name: divide
required_options:
overflow: SILENT # cudf rolls over on overflow
rounding: TIE_TO_EVEN
on_division_by_zero: LIMIT
on_domain_error: NAN
- name: modulus
local_name: mod
26 changes: 25 additions & 1 deletion dialects/datafusion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,31 @@ scalar_functions:
overflow: ERROR
rounding: TIE_TO_EVEN
- name: modulus
unsupported: true
unsupported_kernels:
- args:
- i8
- i8
result: i8
- args:
- i16
- i16
result: i16
- args:
- i32
- i32
result: i32
- args:
- i64
- i64
result: i64
- args:
- fp32
- fp32
result: fp32
- args:
- fp64
- fp64
result: fp64
- name: power
- name: sqrt
required_options:
Expand Down
12 changes: 9 additions & 3 deletions dialects/duckdb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,15 @@ scalar_functions:
- name: modulus
local_name: "%"
infix: True
required_options:
overflow: ERROR
rounding: TIE_TO_EVEN
unsupported_kernels:
- args:
- fp32
- fp32
result: fp32
- args:
- fp64
- fp64
result: fp64
- name: power
required_options:
overflow: ERROR
Expand Down
2 changes: 0 additions & 2 deletions dialects/postgres.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ scalar_functions:
- name: modulus
local_name: "%"
infix: True
required_options:
overflow: ERROR
unsupported_kernels:
- args:
- i8
Expand Down
2 changes: 0 additions & 2 deletions dialects/sqlite.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ scalar_functions:
- name: modulus
local_name: "%"
infix: True
required_options:
overflow: SILENT
- name: power
- name: sqrt
required_options:
Expand Down
2 changes: 0 additions & 2 deletions dialects/velox_presto.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ scalar_functions:
result: fp32
- name: modulus
local_name: mod
required_options:
overflow: ERROR
unsupported_kernels:
- args:
- i8
Expand Down
43 changes: 43 additions & 0 deletions supplemental/arithmetic/modulus.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Modulus

## Options
Not supported

### Overflow

Not supported

### Rounding

Not supported

## Details

### Overflow and rounding
The Modulus function will not require options such as Overflow or rounding
which are present in other arithmetic functions, because there will not be
an event in the allowed kernels and data type where the modulus function can
behave in one of such ways. Modulus function is defined for integer values only
and they do not operate on floating values. Thus, they cannot have floats as
remainders. Additionally, result of modulus on two operands will always result
a value within the range.

### Not commutative

Modulus as an arithmetic operation is not commutative by nature.

## Properties

### Null propagating

If any of the inputs is null then the output will be null

### NaN propagating

If any of the inputs is NaN (and the other input is not null) then the output
will be NaN

### Stateless

The output will be the same regardless of the order of input rows. This is not
guaranteed to be true for integer division when overflow is SILENT.

0 comments on commit 79baeaa

Please sign in to comment.