From b2bc641594662e0319fc71dcc7f3a7c79eba4ef0 Mon Sep 17 00:00:00 2001 From: Charles Blackmon-Luca <20627856+charlesbluca@users.noreply.github.com> Date: Tue, 12 Oct 2021 07:11:23 -0700 Subject: [PATCH] First pass at CONCAT function --- dask_sql/physical/rex/core/call.py | 1 + tests/integration/test_rex.py | 70 +++++++++++++++--------------- 2 files changed, 37 insertions(+), 34 deletions(-) diff --git a/dask_sql/physical/rex/core/call.py b/dask_sql/physical/rex/core/call.py index 606603c8c..687b948b9 100644 --- a/dask_sql/physical/rex/core/call.py +++ b/dask_sql/physical/rex/core/call.py @@ -740,6 +740,7 @@ class RexCallPlugin(BaseRexPlugin): "truncate": Operation(da.trunc), # string operations "||": ReduceOperation(operation=operator.add), + "concat": ReduceOperation(operation=operator.add), "char_length": TensorScalarOperation(lambda x: x.str.len(), lambda x: len(x)), "upper": TensorScalarOperation(lambda x: x.str.upper(), lambda x: x.upper()), "lower": TensorScalarOperation(lambda x: x.str.lower(), lambda x: x.lower()), diff --git a/tests/integration/test_rex.py b/tests/integration/test_rex.py index 7cfa8414f..ad7a3fb3e 100644 --- a/tests/integration/test_rex.py +++ b/tests/integration/test_rex.py @@ -411,25 +411,26 @@ def test_string_functions(c): """ SELECT a || 'hello' || a AS a, - CHAR_LENGTH(a) AS b, - UPPER(a) AS c, - LOWER(a) AS d, - POSITION('a' IN a FROM 4) AS e, - POSITION('ZL' IN a) AS f, - TRIM('a' FROM a) AS g, - TRIM(BOTH 'a' FROM a) AS h, - TRIM(LEADING 'a' FROM a) AS i, - TRIM(TRAILING 'a' FROM a) AS j, - OVERLAY(a PLACING 'XXX' FROM -1) AS k, - OVERLAY(a PLACING 'XXX' FROM 2 FOR 4) AS l, - OVERLAY(a PLACING 'XXX' FROM 2 FOR 1) AS m, - SUBSTRING(a FROM -1) AS n, - SUBSTRING(a FROM 10) AS o, - SUBSTRING(a FROM 2) AS p, - SUBSTRING(a FROM 2 FOR 2) AS q, - INITCAP(a) AS r, - INITCAP(UPPER(a)) AS s, - INITCAP(LOWER(a)) AS t + CONCAT(a, 'hello', a) as b, + CHAR_LENGTH(a) AS c, + UPPER(a) AS d, + LOWER(a) AS e, + POSITION('a' IN a FROM 4) AS f, + POSITION('ZL' IN a) AS g, + TRIM('a' FROM a) AS h, + TRIM(BOTH 'a' FROM a) AS i, + TRIM(LEADING 'a' FROM a) AS j, + TRIM(TRAILING 'a' FROM a) AS k, + OVERLAY(a PLACING 'XXX' FROM -1) AS l, + OVERLAY(a PLACING 'XXX' FROM 2 FOR 4) AS m, + OVERLAY(a PLACING 'XXX' FROM 2 FOR 1) AS n, + SUBSTRING(a FROM -1) AS o, + SUBSTRING(a FROM 10) AS p, + SUBSTRING(a FROM 2) AS q, + SUBSTRING(a FROM 2 FOR 2) AS r, + INITCAP(a) AS s, + INITCAP(UPPER(a)) AS t, + INITCAP(LOWER(a)) AS u FROM string_table """ @@ -438,25 +439,26 @@ def test_string_functions(c): expected_df = pd.DataFrame( { "a": ["a normal stringhelloa normal string"], - "b": [15], - "c": ["A NORMAL STRING"], - "d": ["a normal string"], - "e": [7], - "f": [0], - "g": [" normal string"], + "b": ["a normal stringhelloa normal string"], + "c": [15], + "d": ["A NORMAL STRING"], + "e": ["a normal string"], + "f": [7], + "g": [0], "h": [" normal string"], "i": [" normal string"], - "j": ["a normal string"], - "k": ["XXXormal string"], - "l": ["aXXXmal string"], - "m": ["aXXXnormal string"], - "n": ["a normal string"], - "o": ["string"], - "p": [" normal string"], - "q": [" n"], - "r": ["A Normal String"], + "j": [" normal string"], + "k": ["a normal string"], + "l": ["XXXormal string"], + "m": ["aXXXmal string"], + "n": ["aXXXnormal string"], + "o": ["a normal string"], + "p": ["string"], + "q": [" normal string"], + "r": [" n"], "s": ["A Normal String"], "t": ["A Normal String"], + "u": ["A Normal String"], } )