From 4557c0f31de339761bb08cea50905f58f058a8a3 Mon Sep 17 00:00:00 2001 From: Richard Tia Date: Thu, 4 May 2023 10:51:06 -0700 Subject: [PATCH] test: add concat function --- bft/testers/postgres/runner.py | 2 +- bft/testers/sqlite/runner.py | 2 +- cases/string/concat.yaml | 42 ++++++++++++++++++++++++++++++++++ dialects/postgres.yaml | 5 +++- dialects/sqlite.yaml | 5 +++- dialects/velox_presto.yaml | 5 +++- 6 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 cases/string/concat.yaml diff --git a/bft/testers/postgres/runner.py b/bft/testers/postgres/runner.py index 1b3b392c..af8bf9ed 100644 --- a/bft/testers/postgres/runner.py +++ b/bft/testers/postgres/runner.py @@ -59,7 +59,7 @@ def run_sql_case(self, case: Case, mapping: SqlMapping) -> SqlCaseResult: arg_vals = ",".join( [ "'" + literal_to_str(arg) + "'" - if arg.type == "string" + if arg.type == "string" and arg.value is not None else literal_to_str(arg) for arg in case.args ] diff --git a/bft/testers/sqlite/runner.py b/bft/testers/sqlite/runner.py index 7662ecd7..98bfff60 100644 --- a/bft/testers/sqlite/runner.py +++ b/bft/testers/sqlite/runner.py @@ -50,7 +50,7 @@ def run_sql_case(self, case: Case, mapping: SqlMapping) -> SqlCaseResult: arg_vals = ",".join( [ "'" + literal_to_str(arg) + "'" - if arg.type == "string" + if arg.type == "string" and arg.value is not None else literal_to_str(arg) for arg in case.args ] diff --git a/cases/string/concat.yaml b/cases/string/concat.yaml new file mode 100644 index 00000000..3791b2bf --- /dev/null +++ b/cases/string/concat.yaml @@ -0,0 +1,42 @@ +function: concat +cases: + - group: + id: basic + description: Basic examples without any special cases + args: + - value: 'abcd' + type: string + - value: 'efg' + type: string + result: + value: 'abcdefg' + type: string + - group: + id: null_input + description: Examples with null as input + args: + - value: 'abcd' + type: string + - value: null + type: string + result: + value: null + type: string + - group: null_input + args: + - value: null + type: string + - value: 'abcd' + type: string + result: + value: null + type: string + - group: null_input + args: + - value: null + type: string + - value: null + type: string + result: + value: null + type: string \ No newline at end of file diff --git a/dialects/postgres.yaml b/dialects/postgres.yaml index 88336560..147ca61c 100644 --- a/dialects/postgres.yaml +++ b/dialects/postgres.yaml @@ -56,4 +56,7 @@ scalar_functions: infix: False - name: substring local_name: substring - infix: False \ No newline at end of file + infix: False + - name: concat + local_name: "||" + infix: True diff --git a/dialects/sqlite.yaml b/dialects/sqlite.yaml index 196bf00c..6c1bd77a 100644 --- a/dialects/sqlite.yaml +++ b/dialects/sqlite.yaml @@ -40,4 +40,7 @@ scalar_functions: infix: False - name: substring local_name: substring - infix: False \ No newline at end of file + infix: False + - name: concat + local_name: "||" + infix: True diff --git a/dialects/velox_presto.yaml b/dialects/velox_presto.yaml index 6c5877e2..ebe5cb19 100644 --- a/dialects/velox_presto.yaml +++ b/dialects/velox_presto.yaml @@ -64,4 +64,7 @@ scalar_functions: infix: False - name: substring local_name: substring - infix: False \ No newline at end of file + infix: False + - name: concat + local_name: concat + infix: False