Skip to content

Commit

Permalink
Add test cases for arithmetic decimal function "sqrt" and "factorial" (
Browse files Browse the repository at this point in the history
  • Loading branch information
anshuldata authored Aug 23, 2024
1 parent 136a324 commit 573adcb
Show file tree
Hide file tree
Showing 5 changed files with 198 additions and 13 deletions.
2 changes: 2 additions & 0 deletions bft/cases/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def __normalize_yaml_literal(self, value, data_type):
return float("inf")
elif value.lower().startswith("-inf"):
return float("-inf")
elif value.lower().startswith("1e"):
return float(value.lower())
elif value.lower().startswith("nan"):
return math.nan
else:
Expand Down
59 changes: 59 additions & 0 deletions cases/arithmetic_decimal/factorial_decimal.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
base_uri: https://github.com/substrait-io/substrait/blob/main/extensions/substrait/extensions/functions_arithmetic_decimal.yaml
function: factorial
cases:
- group:
id: basic
description: Basic examples without any special cases
args:
- value: 0
type: decimal<1,0>
result:
value: 1
type: decimal<38,0>
- group: basic
args:
- value: 1
type: decimal<1,0>
result:
value: 1
type: decimal<38,0>
- group: basic
args:
- value: 20
type: decimal<2,0>
result:
value: 2432902008176640000
type: decimal<38,0>
- group:
id: overflow
description: Examples demonstrating overflow behavior
args:
- value: 34
type: decimal<2,0>
result:
special: error
- group:
id: negative_value
description: Examples demonstrating behavior on negative value
args:
- value: -1
type: decimal<1,0>
result:
special: error
- group:
id: null_values
description: test with null values
args:
- value: null
type: decimal<38, 0>
result:
value: null
type: decimal<38, 0>
- group: null_values
args:
- value: null
type: decimal<1, 0>
result:
value: null
type: decimal<38, 0>

112 changes: 112 additions & 0 deletions cases/arithmetic_decimal/sqrt_decimal.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
base_uri: https://github.com/substrait-io/substrait/blob/main/extensions/substrait/extensions/functions_arithmetic_decimal.yaml
function: sqrt
cases:
- group:
id: basic
description: Basic examples without any special cases
args:
- value: 25
type: decimal<2,0>
result:
value: 5
type: fp64
- group: basic
args:
- value: 0
type: decimal<1,0>
result:
value: 0
type: fp64
- group:
id: max_input
description: max allowed input returns correct result
args:
- value: 99999999999999999999999999999999999999
type: decimal<38,0>
result:
value: 1e+19
type: fp64
- group:
id: real_number
description: real number as input
args:
- value: 6.25
type: decimal<3,2>
result:
value: 2.5
type: fp64
- group: real_number
args:
- value: 2.0000007152557373046875
type: decimal<23,22>
result:
value: 1.4142138152541635
type: fp64
- group:
id: verify_real_number
description: verify real number operation are different and doesn't behave as nearby int
args:
- value: 9
type: decimal<1,0>
result:
value: 3
type: fp64
- group: verify_real_number
args:
- value: 8.3
type: decimal<2,1>
result:
value: 2.8809720581775866
type: fp64
- group: verify_real_number
args:
- value: 8.5
type: decimal<2,1>
result:
value: 2.9154759474226504
type: fp64
- group: verify_real_number
args:
- value: 8.7
type: decimal<2,1>
result:
value: 2.949576240750525
type: fp64
- group: verify_real_number
args:
- value: 9.2
type: decimal<2,1>
result:
value: 3.03315017762062
type: fp64
- group:
id: negative_input
description: negative input returns error
args:
- value: -9223372036854775800
type: decimal<19,0>
result:
special: error
- group: negative_input
args:
- value: -2.5
type: decimal<2,1>
result:
special: error
- group:
id: null_values
description: test with null values
args:
- value: null
type: decimal<38, 0>
result:
value: null
type: fp64
- group: null_values
args:
- value: null
type: decimal<1, 0>
result:
value: null
type: fp64

16 changes: 10 additions & 6 deletions dialects/duckdb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,6 @@ scalar_functions:
- i64_i64
- fp32_fp32
- fp64_fp64
- name: arithmetic_decimal.power
local_name: pow
required_options:
complex_number_result: NAN
supported_kernels:
- dec_dec
- name: arithmetic.sqrt
local_name: sqrt
required_options:
Expand Down Expand Up @@ -677,3 +671,13 @@ aggregate_functions:
aggregate: true
supported_kernels:
- bool
- name: arithmetic_decimal.power
local_name: pow
required_options:
complex_number_result: NAN
supported_kernels:
- dec_dec
- name: arithmetic_decimal.sqrt
local_name: sqrt
supported_kernels:
- dec
22 changes: 15 additions & 7 deletions dialects/snowflake.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,6 @@ scalar_functions:
rounding: TIE_TO_EVEN
supported_kernels:
- fp64_fp64
- name: arithmetic_decimal.power
local_name: pow
required_options:
overflow: ERROR
complex_number_result: ERROR
supported_kernels:
- dec_dec
- name: arithmetic.sqrt
local_name: sqrt
required_options:
Expand Down Expand Up @@ -384,3 +377,18 @@ aggregate_functions:
local_name: bitxor
supported_kernels:
- dec_dec
- name: arithmetic_decimal.power
local_name: pow
required_options:
overflow: ERROR
complex_number_result: ERROR
supported_kernels:
- dec_dec
- name: arithmetic_decimal.sqrt
local_name: sqrt
supported_kernels:
- dec
- name: arithmetic_decimal.factorial
local_name: factorial
supported_kernels:
- dec

0 comments on commit 573adcb

Please sign in to comment.