Skip to content

Commit

Permalink
feat: add remaining arithmetic functions
Browse files Browse the repository at this point in the history
  • Loading branch information
richtia committed Jul 27, 2023
1 parent 4b31a31 commit 5a836b1
Show file tree
Hide file tree
Showing 11 changed files with 371 additions and 0 deletions.
1 change: 1 addition & 0 deletions bft/tests/test_sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def tester(dialects):
instance.prepare(dialects)
return instance


@pytest.mark.parametrize("case", cases())
def test_scalar_functions(case, tester):
run_test(case, tester)
39 changes: 39 additions & 0 deletions cases/arithmetic/exp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
function: exp
cases:
- group:
id: basic
description: Basic examples without any special cases
args:
- value: 0.0
type: fp32
result:
value: 1.0
type: fp32
- group: basic
args:
- value: 0.693
type: fp64
result:
value: 1.9997056605411638
type: fp64
- group: basic
args:
- value: 0
type: fp64
result:
value: 1.0
type: fp64
- group: basic
args:
- value: 2.0000007152557373046875
type: fp64
result:
value: 7.3890613839973085
type: fp64
- group: basic
args:
- value: null
type: fp64
result:
value: null
type: fp64
32 changes: 32 additions & 0 deletions cases/arithmetic/factorial.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
function: factorial
cases:
- group:
id: basic
description: Basic examples without any special cases
args:
- value: 0
type: i32
result:
value: 1
type: i32
- group: basic
args:
- value: 1
type: i64
result:
value: 1
type: i64
- group: basic
args:
- value: 14
type: i64
result:
value: 87178291200
type: i64
- group: basic
args:
- value: null
type: i64
result:
value: null
type: i64
85 changes: 85 additions & 0 deletions cases/arithmetic/modulus.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
function: modulus
cases:
- group:
id: basic
description: Basic examples without any special cases
args:
- value: 9
type: i8
- value: 3
type: i8
result:
value: 0
type: i8
- group: basic
args:
- value: 10
type: i8
- value: 3
type: i8
result:
value: 1
type: i8
- group: basic
args:
- value: 10
type: i8
- value: -3
type: i8
result:
value: 1
type: i8
- group: basic
args:
- value: -10
type: i8
- value: 3
type: i8
result:
value: -1
type: i8
- group: basic
args:
- value: -10
type: i8
- value: -3
type: i8
result:
value: -1
type: i8
- group: basic
args:
- value: 5
type: i8
- value: 0
type: i8
result:
value: null
type: i8
- group: basic
args:
- value: 5
type: i8
- value: null
type: i8
result:
value: null
type: i8
- group: basic
args:
- value: null
type: i8
- value: 1
type: i8
result:
value: null
type: i8
- group: basic
args:
- value: null
type: i8
- value: null
type: i8
result:
value: null
type: i8
60 changes: 60 additions & 0 deletions cases/arithmetic/power.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
function: power
cases:
- group:
id: basic
description: Basic examples without any special cases
args:
- value: 8
type: i64
- value: 2
type: i64
result:
value: 64
type: i64
- group: basic
args:
- value: 8
type: i64
- value: -1
type: i64
result:
value: 0.125
type: i64
- group: basic
args:
- value: 8.0
type: fp32
- value: -1
type: fp32
result:
value: 0.125
type: fp32
- group: basic
args:
- value: 2
type: fp64
- value: -2
type: fp64
result:
value: 0.25
type: fp64
- group: basic
args:
- value: 13
type: i64
- value: 10
type: i64
result:
value: 137858491849
type: i64
- group:
id: floating_exception
description: Examples demonstrating exceptional floating point cases
args:
- value: 1.5e+100
type: fp64
- value: 1.5e+208
type: fp64
result:
value: Infinity
type: fp64
52 changes: 52 additions & 0 deletions cases/arithmetic/sqrt.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
function: sqrt
cases:
- group:
id: basic
description: Basic examples without any special cases
args:
- value: 25
type: i64
result:
value: 5
type: i64
- group: basic
args:
- value: 0
type: i64
result:
value: 0
type: i64
- group: basic
args:
- value: -1
type: i64
result:
special: error
- group: basic
args:
- value: 9223372036854775800
type: i64
result:
value: 3037000499.97605
type: i64
- group: basic
args:
- value: null
type: i64
result:
value: null
type: i64
- group: basic
args:
- value: 6.4516
type: fp32
result:
value: 2.54
type: fp32
- group: basic
args:
- value: 2.0000007152557373046875
type: fp64
result:
value: 1.4142138152541635
type: fp64
7 changes: 7 additions & 0 deletions dialects/datafusion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ scalar_functions:
required_options:
overflow: SILENT
rounding: TIE_TO_EVEN
- name: modulus
unsupported: true
- name: power
- name: sqrt
- name: exp
- name: factorial
unsupported: True
- name: abs
unsupported: true
required_options:
Expand Down
20 changes: 20 additions & 0 deletions dialects/duckdb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,26 @@ scalar_functions:
required_options:
overflow: ERROR
rounding: TIE_TO_EVEN
- name: modulus
local_name: "%"
infix: True
required_options:
overflow: ERROR
rounding: TIE_TO_EVEN
- name: power
required_options:
overflow: ERROR
rounding: TIE_TO_EVEN
- name: sqrt
required_options:
overflow: ERROR
rounding: TIE_TO_EVEN
- name: exp
required_options:
overflow: ERROR
rounding: TIE_TO_EVEN
- name: factorial
unsupported: true
- name: abs
required_options:
overflow: ERROR
Expand Down
22 changes: 22 additions & 0 deletions dialects/postgres.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,28 @@ scalar_functions:
- fp32
- fp32
result: fp32
- name: modulus
local_name: "%"
infix: True
required_options:
overflow: ERROR
unsupported_kernels:
- args:
- i8
- i8
result: i8
- args:
- fp32
- fp32
result: fp32
- name: power
- name: sqrt
unsupported_kernels:
- args:
- fp32
result: fp32
- name: exp
- name: factorial
- name: abs
required_options:
overflow: ERROR
Expand Down
10 changes: 10 additions & 0 deletions dialects/sqlite.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ scalar_functions:
infix: True
required_options:
overflow: SILENT
- name: modulus
local_name: "%"
infix: True
required_options:
overflow: SILENT
- name: power
- name: sqrt
- name: exp
- name: factorial
unsupported: True
- name: abs
required_options:
overflow: SILENT
Expand Down
Loading

0 comments on commit 5a836b1

Please sign in to comment.