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 28, 2023
1 parent 4b31a31 commit f7d24df
Show file tree
Hide file tree
Showing 14 changed files with 394 additions and 1 deletion.
3 changes: 3 additions & 0 deletions bft/testers/datafusion/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ def run_sql_case(self, case: Case, mapping: SqlMapping) -> SqlCaseResult:
return SqlCaseResult.success()
elif case.result == "error":
return SqlCaseResult.unexpected_pass(str(result))
elif case.result == "nan":
if case.result == str(result):
return SqlCaseResult.success()
else:
if result == case.result.value:
return SqlCaseResult.success()
Expand Down
3 changes: 3 additions & 0 deletions bft/testers/postgres/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,13 @@ def run_sql_case(self, case: Case, mapping: SqlMapping) -> SqlCaseResult:
expr = f"SELECT {mapping.local_name}({joined_arg_names}) FROM my_table;"
result = self.conn.execute(expr).fetchone()[0]

print(f"case result: {case.result}")
if case.result == "undefined":
return SqlCaseResult.success()
elif case.result == "error":
return SqlCaseResult.unexpected_pass(str(result))
elif case.result == "nan":
return SqlCaseResult.error(str(result))
else:
if result == case.result.value:
return SqlCaseResult.success()
Expand Down
2 changes: 2 additions & 0 deletions bft/testers/sqlite/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ def run_sql_case(self, case: Case, mapping: SqlMapping) -> SqlCaseResult:
return SqlCaseResult.success()
elif case.result == "error":
return SqlCaseResult.unexpected_pass(str(result))
elif case.result == "nan":
return SqlCaseResult.error(str(result))
else:
if result == case.result.value:
return SqlCaseResult.success()
Expand Down
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.25
type: fp32
result:
value: 1.2840254166877414
type: fp32
- group: basic
args:
- value: 0.693
type: fp64
result:
value: 1.9997056605411638
type: fp64
- group: basic
args:
- value: 2.0000007152557373046875
type: fp64
result:
value: 7.3890613839973085
type: fp64
- group: basic
args:
- value: 0.0
type: fp64
result:
value: 1.0
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
51 changes: 51 additions & 0 deletions cases/arithmetic/power.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
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: 1
type: fp32
- value: -1
type: fp32
result:
value: 1
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
71 changes: 71 additions & 0 deletions cases/arithmetic/sqrt.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
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: -9223372036854775800
type: i64
options:
on_domain_error: ERROR
result:
special: error
- group: basic
args:
- value: -9223372036854775800
type: i64
options:
on_domain_error: NONE
result:
value: null
type: i64
- group: basic
args:
- value: -9223372036854775800
type: i64
options:
on_domain_error: NAN
result:
special: nan
- 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.25
type: fp32
result:
value: 2.5
type: fp32
- group: basic
args:
- value: 2.0000007152557373046875
type: fp64
result:
value: 1.4142138152541635
type: fp64
13 changes: 13 additions & 0 deletions dialects/datafusion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ scalar_functions:
required_options:
overflow: SILENT
rounding: TIE_TO_EVEN
- name: modulus
unsupported: true
- name: power
- name: sqrt
required_options:
on_domain_error: NAN
- name: exp
unsupported_kernels:
- args:
- fp32
result: fp32
- 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:
on_domain_error: 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
Loading

0 comments on commit f7d24df

Please sign in to comment.