From f510b7d33468a179b3849f13c579d3d5d3449352 Mon Sep 17 00:00:00 2001 From: Richard Tia Date: Fri, 15 Jul 2022 16:14:11 -0700 Subject: [PATCH 1/6] feat: add string trimming and padding functions --- extensions/functions_string.yaml | 147 ++++++++++++++++++++++++++++++- 1 file changed, 146 insertions(+), 1 deletion(-) diff --git a/extensions/functions_string.yaml b/extensions/functions_string.yaml index 66b389301..e78b0c52f 100644 --- a/extensions/functions_string.yaml +++ b/extensions/functions_string.yaml @@ -27,7 +27,9 @@ scalar_functions: return: "BOOLEAN" - name: substring - description: Extract a portion of a string from another string. + description: >- + Extract a substring of a specified length starting from position start. + A start value of 1 refers to the first characters of the string. impls: - args: - value: "varchar" @@ -163,3 +165,146 @@ scalar_functions: - value: "fixedchar" - value: "varchar" return: "BOOLEAN" + - + name: ltrim + description: >- + Remove any occurrence of the characters from the left side of the string. + If no characters are specified, spaces are removed. + impls: + - args: + - value: "varchar" + - value: "varchar" + return: "varchar" + - args: + - value: "string" + - value: "string" + return: "string" + - args: + - value: "fixedchar" + - value: "fixedchar" + return: "string" + - + name: rtrim + description: >- + Remove any occurrence of the characters from the right side of the string. + If no characters are specified, spaces are removed. + impls: + - args: + - value: "varchar" + - value: "varchar" + return: "varchar" + - args: + - value: "string" + - value: "string" + return: "string" + - args: + - value: "fixedchar" + - value: "fixedchar" + return: "string" + - + name: trim + description: >- + Remove any occurrence of the characters from the left and right sides of + the string. If no characters are specified, spaces are removed. + impls: + - args: + - value: "varchar" + - value: "varchar" + return: "varchar" + - args: + - value: "string" + - value: "string" + return: "string" + - args: + - value: "fixedchar" + - value: "fixedchar" + return: "string" + - + name: lpad + description: Left-pad the string with the characters until the specified length of the string has been reached. + impls: + - args: + - value: "varchar" + - value: i32 + - value: "varchar" + return: "string" + - args: + - value: "string" + - value: i32 + - value: "string" + return: "string" + - args: + - value: "fixedchar" + - value: i32 + - value: "fixedchar" + return: "string" + - + name: rpad + description: Right-pad the string with the characters until the specified length of the string has been reached. + impls: + - args: + - value: "varchar" + - value: i32 + - value: "varchar" + return: "string" + - args: + - value: "string" + - value: i32 + - value: "string" + return: "string" + - args: + - value: "fixedchar" + - value: i32 + - value: "fixedchar" + return: "string" + - + name: center + description: Pad the string with characters from each side until the specified length of the string has been reached. + impls: + - args: + - value: "varchar" + - value: i32 + - value: "varchar" + return: "string" + - args: + - value: "string" + - value: i32 + - value: "string" + return: "string" + - args: + - value: "fixedchar" + - value: i32 + - value: "fixedchar" + return: "string" + - + name: left + description: Extract count characters starting from the left of the string. + impls: + - args: + - value: "varchar" + - value: i32 + return: "varchar" + - args: + - value: "string" + - value: i32 + return: "string" + - args: + - value: "fixedchar" + - value: i32 + return: "string" + - + name: right + description: Extract count characters starting from the right of the string. + impls: + - args: + - value: "varchar" + - value: i32 + return: "varchar" + - args: + - value: "string" + - value: i32 + return: "string" + - args: + - value: "fixedchar" + - value: i32 + return: "string" From 3bfdb96591fe850d98ae585d17e0e23c8c423e62 Mon Sep 17 00:00:00 2001 From: Richard Tia Date: Mon, 18 Jul 2022 15:17:44 -0700 Subject: [PATCH 2/6] refactor: add names and descriptions for args --- extensions/functions_string.yaml | 90 ++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/extensions/functions_string.yaml b/extensions/functions_string.yaml index e78b0c52f..f16a84c3c 100644 --- a/extensions/functions_string.yaml +++ b/extensions/functions_string.yaml @@ -173,15 +173,27 @@ scalar_functions: impls: - args: - value: "varchar" + name: "input" + description: "The string to remove characters from." - value: "varchar" + name: "characters" + description: "The set of characters to remove." return: "varchar" - args: - value: "string" + name: "input" + description: "The string to remove characters from." - value: "string" + name: "characters" + description: "The set of characters to remove." return: "string" - args: - value: "fixedchar" + name: "input" + description: "The string to remove characters from." - value: "fixedchar" + name: "characters" + description: "The set of characters to remove." return: "string" - name: rtrim @@ -191,15 +203,27 @@ scalar_functions: impls: - args: - value: "varchar" + name: "input" + description: "The string to remove characters from." - value: "varchar" + name: "characters" + description: "The set of characters to remove." return: "varchar" - args: - value: "string" + name: "input" + description: "The string to remove characters from." - value: "string" + name: "characters" + description: "The set of characters to remove." return: "string" - args: - value: "fixedchar" + name: "input" + description: "The string to remove characters from." - value: "fixedchar" + name: "characters" + description: "The set of characters to remove." return: "string" - name: trim @@ -209,15 +233,27 @@ scalar_functions: impls: - args: - value: "varchar" + name: "input" + description: "The string to remove characters from." - value: "varchar" + name: "characters" + description: "The set of characters to remove." return: "varchar" - args: - value: "string" + name: "input" + description: "The string to remove characters from." - value: "string" + name: "characters" + description: "The set of characters to remove." return: "string" - args: - value: "fixedchar" + name: "input" + description: "The string to remove characters from." - value: "fixedchar" + name: "characters" + description: "The set of characters to remove." return: "string" - name: lpad @@ -225,18 +261,36 @@ scalar_functions: impls: - args: - value: "varchar" + name: "input" + description: "The string to pad." - value: i32 + name: "length" + description: "The length of the output string." - value: "varchar" + name: "characters" + description: "The set of characters to use for padding." return: "string" - args: - value: "string" + name: "input" + description: "The string to pad." - value: i32 + name: "length" + description: "The length of the output string." - value: "string" + name: "characters" + description: "The set of characters to use for padding." return: "string" - args: - value: "fixedchar" + name: "input" + description: "The string to pad." - value: i32 + name: "length" + description: "The length of the output string." - value: "fixedchar" + name: "characters" + description: "The set of characters to use for padding." return: "string" - name: rpad @@ -244,18 +298,36 @@ scalar_functions: impls: - args: - value: "varchar" + name: "input" + description: "The string to pad." - value: i32 + name: "length" + description: "The length of the output string." - value: "varchar" + name: "characters" + description: "The set of characters to use for padding." return: "string" - args: - value: "string" + name: "input" + description: "The string to pad." - value: i32 + name: "length" + description: "The length of the output string." - value: "string" + name: "characters" + description: "The set of characters to use for padding." return: "string" - args: - value: "fixedchar" + name: "input" + description: "The string to pad." - value: i32 + name: "length" + description: "The length of the output string." - value: "fixedchar" + name: "characters" + description: "The set of characters to use for padding." return: "string" - name: center @@ -263,18 +335,36 @@ scalar_functions: impls: - args: - value: "varchar" + name: "input" + description: "The string to pad." - value: i32 + name: "length" + description: "The length of the output string." - value: "varchar" + name: "characters" + description: "The set of characters to use for padding." return: "string" - args: - value: "string" + name: "input" + description: "The string to pad." - value: i32 + name: "length" + description: "The length of the output string." - value: "string" + name: "characters" + description: "The set of characters to use for padding." return: "string" - args: - value: "fixedchar" + name: "input" + description: "The string to pad." - value: i32 + name: "length" + description: "The length of the output string." - value: "fixedchar" + name: "characters" + description: "The set of characters to use for padding." return: "string" - name: left From 2b0e096e77ca763a0d3e69bb92d7642666d1bfa4 Mon Sep 17 00:00:00 2001 From: Richard Tia Date: Thu, 21 Jul 2022 12:19:12 -0700 Subject: [PATCH 3/6] refactor: remove promotions and function definitions for fixedchar --- extensions/functions_string.yaml | 91 ++++++-------------------------- 1 file changed, 16 insertions(+), 75 deletions(-) diff --git a/extensions/functions_string.yaml b/extensions/functions_string.yaml index f16a84c3c..dab8cb296 100644 --- a/extensions/functions_string.yaml +++ b/extensions/functions_string.yaml @@ -175,7 +175,7 @@ scalar_functions: - value: "varchar" name: "input" description: "The string to remove characters from." - - value: "varchar" + - value: "varchar" name: "characters" description: "The set of characters to remove." return: "varchar" @@ -187,14 +187,6 @@ scalar_functions: name: "characters" description: "The set of characters to remove." return: "string" - - args: - - value: "fixedchar" - name: "input" - description: "The string to remove characters from." - - value: "fixedchar" - name: "characters" - description: "The set of characters to remove." - return: "string" - name: rtrim description: >- @@ -205,7 +197,7 @@ scalar_functions: - value: "varchar" name: "input" description: "The string to remove characters from." - - value: "varchar" + - value: "varchar" name: "characters" description: "The set of characters to remove." return: "varchar" @@ -217,14 +209,6 @@ scalar_functions: name: "characters" description: "The set of characters to remove." return: "string" - - args: - - value: "fixedchar" - name: "input" - description: "The string to remove characters from." - - value: "fixedchar" - name: "characters" - description: "The set of characters to remove." - return: "string" - name: trim description: >- @@ -235,7 +219,7 @@ scalar_functions: - value: "varchar" name: "input" description: "The string to remove characters from." - - value: "varchar" + - value: "varchar" name: "characters" description: "The set of characters to remove." return: "varchar" @@ -247,14 +231,6 @@ scalar_functions: name: "characters" description: "The set of characters to remove." return: "string" - - args: - - value: "fixedchar" - name: "input" - description: "The string to remove characters from." - - value: "fixedchar" - name: "characters" - description: "The set of characters to remove." - return: "string" - name: lpad description: Left-pad the string with the characters until the specified length of the string has been reached. @@ -266,10 +242,10 @@ scalar_functions: - value: i32 name: "length" description: "The length of the output string." - - value: "varchar" + - value: "varchar" name: "characters" description: "The set of characters to use for padding." - return: "string" + return: "varchar" - args: - value: "string" name: "input" @@ -281,17 +257,6 @@ scalar_functions: name: "characters" description: "The set of characters to use for padding." return: "string" - - args: - - value: "fixedchar" - name: "input" - description: "The string to pad." - - value: i32 - name: "length" - description: "The length of the output string." - - value: "fixedchar" - name: "characters" - description: "The set of characters to use for padding." - return: "string" - name: rpad description: Right-pad the string with the characters until the specified length of the string has been reached. @@ -303,10 +268,10 @@ scalar_functions: - value: i32 name: "length" description: "The length of the output string." - - value: "varchar" + - value: "varchar" name: "characters" description: "The set of characters to use for padding." - return: "string" + return: "varchar" - args: - value: "string" name: "input" @@ -318,33 +283,28 @@ scalar_functions: name: "characters" description: "The set of characters to use for padding." return: "string" - - args: - - value: "fixedchar" - name: "input" - description: "The string to pad." - - value: i32 - name: "length" - description: "The length of the output string." - - value: "fixedchar" - name: "characters" - description: "The set of characters to use for padding." - return: "string" - name: center - description: Pad the string with characters from each side until the specified length of the string has been reached. + description: >- + Pad the string with characters from each side until the specified length of the string has + been reached. If padding is uneven, the default option is to have extra padding on the right. impls: - args: + - options: [ RIGHT, LEFT ] + required: false - value: "varchar" name: "input" description: "The string to pad." - value: i32 name: "length" description: "The length of the output string." - - value: "varchar" + - value: "varchar" name: "characters" description: "The set of characters to use for padding." - return: "string" + return: "varchar" - args: + - options: [ RIGHT, LEFT ] + required: false - value: "string" name: "input" description: "The string to pad." @@ -355,17 +315,6 @@ scalar_functions: name: "characters" description: "The set of characters to use for padding." return: "string" - - args: - - value: "fixedchar" - name: "input" - description: "The string to pad." - - value: i32 - name: "length" - description: "The length of the output string." - - value: "fixedchar" - name: "characters" - description: "The set of characters to use for padding." - return: "string" - name: left description: Extract count characters starting from the left of the string. @@ -378,10 +327,6 @@ scalar_functions: - value: "string" - value: i32 return: "string" - - args: - - value: "fixedchar" - - value: i32 - return: "string" - name: right description: Extract count characters starting from the right of the string. @@ -394,7 +339,3 @@ scalar_functions: - value: "string" - value: i32 return: "string" - - args: - - value: "fixedchar" - - value: i32 - return: "string" From cf41bdf9ce47816939a99b9a0c96117e20943d69 Mon Sep 17 00:00:00 2001 From: Richard Tia Date: Tue, 26 Jul 2022 08:41:47 -0700 Subject: [PATCH 4/6] refactor: update arg lengths --- extensions/functions_string.yaml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/extensions/functions_string.yaml b/extensions/functions_string.yaml index b914a339d..89012e85f 100644 --- a/extensions/functions_string.yaml +++ b/extensions/functions_string.yaml @@ -261,7 +261,7 @@ scalar_functions: - value: "varchar" name: "input" description: "The string to remove characters from." - - value: "varchar" + - value: "varchar" name: "characters" description: "The set of characters to remove." return: "varchar" @@ -283,7 +283,7 @@ scalar_functions: - value: "varchar" name: "input" description: "The string to remove characters from." - - value: "varchar" + - value: "varchar" name: "characters" description: "The set of characters to remove." return: "varchar" @@ -305,7 +305,7 @@ scalar_functions: - value: "varchar" name: "input" description: "The string to remove characters from." - - value: "varchar" + - value: "varchar" name: "characters" description: "The set of characters to remove." return: "varchar" @@ -328,7 +328,7 @@ scalar_functions: - value: i32 name: "length" description: "The length of the output string." - - value: "varchar" + - value: "varchar" name: "characters" description: "The set of characters to use for padding." return: "varchar" @@ -354,7 +354,7 @@ scalar_functions: - value: i32 name: "length" description: "The length of the output string." - - value: "varchar" + - value: "varchar" name: "characters" description: "The set of characters to use for padding." return: "varchar" @@ -384,7 +384,7 @@ scalar_functions: - value: i32 name: "length" description: "The length of the output string." - - value: "varchar" + - value: "varchar" name: "characters" description: "The set of characters to use for padding." return: "varchar" From bdcba3e80ecc252c3438bb90a64fbe5bfb26ab71 Mon Sep 17 00:00:00 2001 From: Richard Tia Date: Wed, 27 Jul 2022 10:59:16 -0700 Subject: [PATCH 5/6] refactor: update descriptions for lpad and rpad --- extensions/functions_string.yaml | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/extensions/functions_string.yaml b/extensions/functions_string.yaml index 89012e85f..5ad26a3b0 100644 --- a/extensions/functions_string.yaml +++ b/extensions/functions_string.yaml @@ -319,7 +319,12 @@ scalar_functions: return: "string" - name: lpad - description: Left-pad the string with the characters until the specified length of the string has been reached. + description: >- + Left-pad the input string with the string of 'characters' until the specified length of the + string has been reached. If the input string is longer than 'length', remove characters from + the right-side to shorten it to 'length' characters. If the string of 'characters' is longer + than the remaining 'length' needed to be filled, only pad until 'length' has been reached. + If 'characters' is not specified, the default value is a single space. impls: - args: - value: "varchar" @@ -330,7 +335,7 @@ scalar_functions: description: "The length of the output string." - value: "varchar" name: "characters" - description: "The set of characters to use for padding." + description: "The string of characters to use for padding." return: "varchar" - args: - value: "string" @@ -341,11 +346,16 @@ scalar_functions: description: "The length of the output string." - value: "string" name: "characters" - description: "The set of characters to use for padding." + description: "The string of characters to use for padding." return: "string" - name: rpad - description: Right-pad the string with the characters until the specified length of the string has been reached. + description: >- + Right-pad the input string with the string of 'characters' until the specified length of the + string has been reached. If the input string is longer than 'length', remove characters from + the left-side to shorten it to 'length' characters. If the string of 'characters' is longer + than the remaining 'length' needed to be filled, only pad until 'length' has been reached. + If 'characters' is not specified, the default value is a single space. impls: - args: - value: "varchar" @@ -356,7 +366,7 @@ scalar_functions: description: "The length of the output string." - value: "varchar" name: "characters" - description: "The set of characters to use for padding." + description: "The string of characters to use for padding." return: "varchar" - args: - value: "string" @@ -367,7 +377,7 @@ scalar_functions: description: "The length of the output string." - value: "string" name: "characters" - description: "The set of characters to use for padding." + description: "The string of characters to use for padding." return: "string" - name: center From 0b47bd596bf7738ff7fc8151454a4687e7712966 Mon Sep 17 00:00:00 2001 From: Richard Tia Date: Thu, 28 Jul 2022 08:13:04 -0700 Subject: [PATCH 6/6] refactor: remove center function --- extensions/functions_string.yaml | 32 -------------------------------- 1 file changed, 32 deletions(-) diff --git a/extensions/functions_string.yaml b/extensions/functions_string.yaml index 5ad26a3b0..9b8a84ad2 100644 --- a/extensions/functions_string.yaml +++ b/extensions/functions_string.yaml @@ -379,38 +379,6 @@ scalar_functions: name: "characters" description: "The string of characters to use for padding." return: "string" - - - name: center - description: >- - Pad the string with characters from each side until the specified length of the string has - been reached. If padding is uneven, the default option is to have extra padding on the right. - impls: - - args: - - options: [ RIGHT, LEFT ] - required: false - - value: "varchar" - name: "input" - description: "The string to pad." - - value: i32 - name: "length" - description: "The length of the output string." - - value: "varchar" - name: "characters" - description: "The set of characters to use for padding." - return: "varchar" - - args: - - options: [ RIGHT, LEFT ] - required: false - - value: "string" - name: "input" - description: "The string to pad." - - value: i32 - name: "length" - description: "The length of the output string." - - value: "string" - name: "characters" - description: "The set of characters to use for padding." - return: "string" - name: left description: Extract count characters starting from the left of the string.