From d6482f679a77e01030e0f8da0dabb8cea26bfa95 Mon Sep 17 00:00:00 2001 From: Anshul Data Date: Thu, 1 Aug 2024 13:33:31 +0530 Subject: [PATCH 1/2] feat: add arithmetic function for bitwise not with decimal arguments --- extensions/functions_arithmetic_decimal.yaml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/extensions/functions_arithmetic_decimal.yaml b/extensions/functions_arithmetic_decimal.yaml index 57cdbe396..349e93d9e 100644 --- a/extensions/functions_arithmetic_decimal.yaml +++ b/extensions/functions_arithmetic_decimal.yaml @@ -183,6 +183,17 @@ scalar_functions: values: [ NAN, ERROR ] return: fp64 + - name: "bitwise_not" + description: > + Return the bitwise NOT result for one decimal input. + In inputs scale must be 0 (i.e. only integer types are allowed). + Result precision should be one more than input precision. + Result exceeding precision limit will raise an error. + impls: + - args: + - name: x + value: "DECIMAL" + return: "DECIMAL" aggregate_functions: - name: "sum" description: Sum a set of values. From 048875eb1c72bdcd2119651a449dd708dc0aec53 Mon Sep 17 00:00:00 2001 From: Anshul Data Date: Mon, 12 Aug 2024 17:08:54 +0530 Subject: [PATCH 2/2] Address review comments --- cases_new/arithmetic_decimal/bitwise_not.yaml | 46 +++++++++++++++++++ extensions/functions_arithmetic_decimal.yaml | 21 ++++----- extensions/functions_snowflake.yaml | 12 +++++ 3 files changed, 68 insertions(+), 11 deletions(-) create mode 100644 cases_new/arithmetic_decimal/bitwise_not.yaml create mode 100644 extensions/functions_snowflake.yaml diff --git a/cases_new/arithmetic_decimal/bitwise_not.yaml b/cases_new/arithmetic_decimal/bitwise_not.yaml new file mode 100644 index 000000000..582dac624 --- /dev/null +++ b/cases_new/arithmetic_decimal/bitwise_not.yaml @@ -0,0 +1,46 @@ +base_uri: > + https://github.com/substrait-io/substrait/blob/main/extensions/substrait/extensions/functions_arithmetic_decimal.yaml +function: bitwise_not +cases: +- group: basic + description: Basic examples without any special cases + tests: + - (1|decimal<1, 0>): -2|decimal<1, 0> + - (1|decimal<2, 0>): -2|decimal<2, 0> + - (1|decimal<3, 0>): -2|decimal<3, 0> + - (1|decimal<4, 0>): -2|decimal<4, 0> + - (1|decimal<5, 0>): -2|decimal<5, 0> + - (1|decimal<6, 0>): -2|decimal<6, 0> + - (1|decimal<7, 0>): -2|decimal<7, 0> + - (1|decimal<8, 0>): -2|decimal<8, 0> + - (1|decimal<9, 0>): -2|decimal<9, 0> + - (1|decimal<10, 0>): -2|decimal<10, 0> + - (1|decimal<11, 0>): -2|decimal<11, 0> + - (1|decimal<12, 0>): -2|decimal<12, 0> + - (1|decimal<13, 0>): -2|decimal<13, 0> + - (1|decimal<14, 0>): -2|decimal<14, 0> + - (1|decimal<15, 0>): -2|decimal<15, 0> + - (1|decimal<16, 0>): -2|decimal<16, 0> + - (1|decimal<17, 0>): -2|decimal<17, 0> + - (1|decimal<18, 0>): -2|decimal<18, 0> + - (1|decimal<19, 0>): -2|decimal<19, 0> + - (1|decimal<20, 0>): -2|decimal<20, 0> + - (1|decimal<21, 0>): -2|decimal<21, 0> + - (1|decimal<22, 0>): -2|decimal<22, 0> + - (1|decimal<23, 0>): -2|decimal<23, 0> + - (1|decimal<24, 0>): -2|decimal<24, 0> + - (1|decimal<25, 0>): -2|decimal<25, 0> + - (1|decimal<26, 0>): -2|decimal<26, 0> + - (1|decimal<27, 0>): -2|decimal<27, 0> + - (1|decimal<28, 0>): -2|decimal<28, 0> + - (1|decimal<29, 0>): -2|decimal<29, 0> + - (1|decimal<30, 0>): -2|decimal<30, 0> + - (1|decimal<31, 0>): -2|decimal<31, 0> + - (1|decimal<32, 0>): -2|decimal<32, 0> + - (1|decimal<33, 0>): -2|decimal<33, 0> + - (1|decimal<34, 0>): -2|decimal<34, 0> + - (1|decimal<35, 0>): -2|decimal<35, 0> + - (1|decimal<36, 0>): -2|decimal<36, 0> + - (1|decimal<37, 0>): -2|decimal<37, 0> + - (1|decimal<38, 0>): -2|decimal<38, 0> + - (null|decimal<38, 0>): null|decimal<38, 0> diff --git a/extensions/functions_arithmetic_decimal.yaml b/extensions/functions_arithmetic_decimal.yaml index 349e93d9e..931d64fed 100644 --- a/extensions/functions_arithmetic_decimal.yaml +++ b/extensions/functions_arithmetic_decimal.yaml @@ -149,6 +149,16 @@ scalar_functions: return: |- max_precision = max(P1, P2) DECIMAL + - name: "bitwise_not" + description: > + Return the bitwise NOT result for one decimal input. + In inputs scale must be 0 (i.e. only integer types are allowed). + Result precision will be equal to input precision. + impls: + - args: + - name: x + value: "DECIMAL" + return: "DECIMAL" - name: "sqrt" description: Square root of the value. Sqrt of 0 is 0 and sqrt of negative values will raise an error. impls: @@ -183,17 +193,6 @@ scalar_functions: values: [ NAN, ERROR ] return: fp64 - - name: "bitwise_not" - description: > - Return the bitwise NOT result for one decimal input. - In inputs scale must be 0 (i.e. only integer types are allowed). - Result precision should be one more than input precision. - Result exceeding precision limit will raise an error. - impls: - - args: - - name: x - value: "DECIMAL" - return: "DECIMAL" aggregate_functions: - name: "sum" description: Sum a set of values. diff --git a/extensions/functions_snowflake.yaml b/extensions/functions_snowflake.yaml new file mode 100644 index 000000000..a7831e7cb --- /dev/null +++ b/extensions/functions_snowflake.yaml @@ -0,0 +1,12 @@ +%YAML 1.2 +--- +scalar_functions: + - name: "bitwise_not" + description: > + Return the bitwise NOT result for one decimal input in which Precision is 1. + Result precision will be equal to 2. + impls: + - args: + - name: x + value: "DECIMAL<1,0>" + return: "DECIMAL<2,0>"