mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-10-27 14:16:18 +00:00
feat: adds regex_extract function and more type tests (#7107)
* feat: adds format, regex_extract function and more type tests Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * fix: forgot functions Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * chore: forgot null type Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * test: forgot date type Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * feat: remove format function Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * test: update results after upgrading datafusion Signed-off-by: Dennis Zhuang <killme2008@gmail.com> --------- Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
This commit is contained in:
@@ -0,0 +1,211 @@
|
||||
-- String concatenation function tests
|
||||
-- Test CONCAT function
|
||||
-- Basic concatenation
|
||||
SELECT CONCAT('hello', 'world');
|
||||
|
||||
+-------------------------------------+
|
||||
| concat(Utf8("hello"),Utf8("world")) |
|
||||
+-------------------------------------+
|
||||
| helloworld |
|
||||
+-------------------------------------+
|
||||
|
||||
SELECT CONCAT('hello', ' ', 'world');
|
||||
|
||||
+-----------------------------------------------+
|
||||
| concat(Utf8("hello"),Utf8(" "),Utf8("world")) |
|
||||
+-----------------------------------------------+
|
||||
| hello world |
|
||||
+-----------------------------------------------+
|
||||
|
||||
SELECT CONCAT('a', 'b', 'c', 'd');
|
||||
|
||||
+-------------------------------------------------+
|
||||
| concat(Utf8("a"),Utf8("b"),Utf8("c"),Utf8("d")) |
|
||||
+-------------------------------------------------+
|
||||
| abcd |
|
||||
+-------------------------------------------------+
|
||||
|
||||
-- Concatenation with NULL values
|
||||
SELECT CONCAT('hello', NULL);
|
||||
|
||||
+----------------------------+
|
||||
| concat(Utf8("hello"),NULL) |
|
||||
+----------------------------+
|
||||
| hello |
|
||||
+----------------------------+
|
||||
|
||||
SELECT CONCAT(NULL, 'world');
|
||||
|
||||
+----------------------------+
|
||||
| concat(NULL,Utf8("world")) |
|
||||
+----------------------------+
|
||||
| world |
|
||||
+----------------------------+
|
||||
|
||||
SELECT CONCAT(NULL, NULL);
|
||||
|
||||
+-------------------+
|
||||
| concat(NULL,NULL) |
|
||||
+-------------------+
|
||||
| |
|
||||
+-------------------+
|
||||
|
||||
-- Concatenation with numbers (should convert to string)
|
||||
SELECT CONCAT('value: ', 42);
|
||||
|
||||
+-----------------------------------+
|
||||
| concat(Utf8("value: "),Int64(42)) |
|
||||
+-----------------------------------+
|
||||
| value: 42 |
|
||||
+-----------------------------------+
|
||||
|
||||
SELECT CONCAT(1, 2, 3);
|
||||
|
||||
+------------------------------------+
|
||||
| concat(Int64(1),Int64(2),Int64(3)) |
|
||||
+------------------------------------+
|
||||
| 123 |
|
||||
+------------------------------------+
|
||||
|
||||
-- Test with table data
|
||||
CREATE TABLE concat_test(first_name VARCHAR, last_name VARCHAR, age INTEGER, ts TIMESTAMP TIME INDEX);
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
INSERT INTO concat_test VALUES
|
||||
('John', 'Doe', 30, 1000),
|
||||
('Jane', 'Smith', 25, 2000),
|
||||
('Bob', NULL, 35, 3000),
|
||||
(NULL, 'Wilson', 40, 4000);
|
||||
|
||||
Affected Rows: 4
|
||||
|
||||
-- Concatenate table columns
|
||||
SELECT CONCAT(first_name, ' ', last_name) as full_name FROM concat_test ORDER BY ts;
|
||||
|
||||
+------------+
|
||||
| full_name |
|
||||
+------------+
|
||||
| John Doe |
|
||||
| Jane Smith |
|
||||
| Bob |
|
||||
| Wilson |
|
||||
+------------+
|
||||
|
||||
SELECT CONCAT(first_name, ' is ', age, ' years old') FROM concat_test ORDER BY ts;
|
||||
|
||||
+--------------------------------------------------------------------------------+
|
||||
| concat(concat_test.first_name,Utf8(" is "),concat_test.age,Utf8(" years old")) |
|
||||
+--------------------------------------------------------------------------------+
|
||||
| John is 30 years old |
|
||||
| Jane is 25 years old |
|
||||
| Bob is 35 years old |
|
||||
| is 40 years old |
|
||||
+--------------------------------------------------------------------------------+
|
||||
|
||||
-- Test CONCAT_WS (concat with separator)
|
||||
SELECT CONCAT_WS(' ', first_name, last_name) as full_name FROM concat_test ORDER BY ts;
|
||||
|
||||
+------------+
|
||||
| full_name |
|
||||
+------------+
|
||||
| John Doe |
|
||||
| Jane Smith |
|
||||
| Bob |
|
||||
| Wilson |
|
||||
+------------+
|
||||
|
||||
SELECT CONCAT_WS('-', first_name, last_name, age) FROM concat_test ORDER BY ts;
|
||||
|
||||
+-----------------------------------------------------------------------------------+
|
||||
| concat_ws(Utf8("-"),concat_test.first_name,concat_test.last_name,concat_test.age) |
|
||||
+-----------------------------------------------------------------------------------+
|
||||
| John-Doe-30 |
|
||||
| Jane-Smith-25 |
|
||||
| Bob-35 |
|
||||
| Wilson-40 |
|
||||
+-----------------------------------------------------------------------------------+
|
||||
|
||||
SELECT CONCAT_WS(',', 'a', 'b', 'c', 'd');
|
||||
|
||||
+--------------------------------------------------------------+
|
||||
| concat_ws(Utf8(","),Utf8("a"),Utf8("b"),Utf8("c"),Utf8("d")) |
|
||||
+--------------------------------------------------------------+
|
||||
| a,b,c,d |
|
||||
+--------------------------------------------------------------+
|
||||
|
||||
-- CONCAT_WS with NULL values (should skip NULLs)
|
||||
SELECT CONCAT_WS(' ', 'hello', NULL, 'world');
|
||||
|
||||
+-------------------------------------------------------+
|
||||
| concat_ws(Utf8(" "),Utf8("hello"),NULL,Utf8("world")) |
|
||||
+-------------------------------------------------------+
|
||||
| hello world |
|
||||
+-------------------------------------------------------+
|
||||
|
||||
SELECT CONCAT_WS('|', first_name, last_name) FROM concat_test ORDER BY ts;
|
||||
|
||||
+-------------------------------------------------------------------+
|
||||
| concat_ws(Utf8("|"),concat_test.first_name,concat_test.last_name) |
|
||||
+-------------------------------------------------------------------+
|
||||
| John|Doe |
|
||||
| Jane|Smith |
|
||||
| Bob |
|
||||
| Wilson |
|
||||
+-------------------------------------------------------------------+
|
||||
|
||||
-- Test pipe operator ||
|
||||
SELECT 'hello' || 'world';
|
||||
|
||||
+--------------------------------+
|
||||
| Utf8("hello") || Utf8("world") |
|
||||
+--------------------------------+
|
||||
| helloworld |
|
||||
+--------------------------------+
|
||||
|
||||
SELECT 'hello' || ' ' || 'world';
|
||||
|
||||
+---------------------------------------------+
|
||||
| Utf8("hello") || Utf8(" ") || Utf8("world") |
|
||||
+---------------------------------------------+
|
||||
| hello world |
|
||||
+---------------------------------------------+
|
||||
|
||||
SELECT first_name || ' ' || last_name FROM concat_test WHERE first_name IS NOT NULL AND last_name IS NOT NULL ORDER BY ts;
|
||||
|
||||
+--------------------------------------------------------------+
|
||||
| concat_test.first_name || Utf8(" ") || concat_test.last_name |
|
||||
+--------------------------------------------------------------+
|
||||
| John Doe |
|
||||
| Jane Smith |
|
||||
+--------------------------------------------------------------+
|
||||
|
||||
-- Unicode concatenation
|
||||
SELECT CONCAT('Hello ', '世界');
|
||||
|
||||
+-------------------------------------+
|
||||
| concat(Utf8("Hello "),Utf8("世界")) |
|
||||
+-------------------------------------+
|
||||
| Hello 世界 |
|
||||
+-------------------------------------+
|
||||
|
||||
SELECT CONCAT('🚀', ' ', '🌟');
|
||||
|
||||
+-----------------------------------------+
|
||||
| concat(Utf8("🚀"),Utf8(" "),Utf8("🌟")) |
|
||||
+-----------------------------------------+
|
||||
| 🚀 🌟 |
|
||||
+-----------------------------------------+
|
||||
|
||||
SELECT '中文' || '🐄';
|
||||
|
||||
+----------------------------+
|
||||
| Utf8("中文") || Utf8("🐄") |
|
||||
+----------------------------+
|
||||
| 中文🐄 |
|
||||
+----------------------------+
|
||||
|
||||
DROP TABLE concat_test;
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
-- String concatenation function tests
|
||||
-- Test CONCAT function
|
||||
|
||||
-- Basic concatenation
|
||||
SELECT CONCAT('hello', 'world');
|
||||
|
||||
SELECT CONCAT('hello', ' ', 'world');
|
||||
|
||||
SELECT CONCAT('a', 'b', 'c', 'd');
|
||||
|
||||
-- Concatenation with NULL values
|
||||
SELECT CONCAT('hello', NULL);
|
||||
|
||||
SELECT CONCAT(NULL, 'world');
|
||||
|
||||
SELECT CONCAT(NULL, NULL);
|
||||
|
||||
-- Concatenation with numbers (should convert to string)
|
||||
SELECT CONCAT('value: ', 42);
|
||||
|
||||
SELECT CONCAT(1, 2, 3);
|
||||
|
||||
-- Test with table data
|
||||
CREATE TABLE concat_test(first_name VARCHAR, last_name VARCHAR, age INTEGER, ts TIMESTAMP TIME INDEX);
|
||||
|
||||
INSERT INTO concat_test VALUES
|
||||
('John', 'Doe', 30, 1000),
|
||||
('Jane', 'Smith', 25, 2000),
|
||||
('Bob', NULL, 35, 3000),
|
||||
(NULL, 'Wilson', 40, 4000);
|
||||
|
||||
-- Concatenate table columns
|
||||
SELECT CONCAT(first_name, ' ', last_name) as full_name FROM concat_test ORDER BY ts;
|
||||
|
||||
SELECT CONCAT(first_name, ' is ', age, ' years old') FROM concat_test ORDER BY ts;
|
||||
|
||||
-- Test CONCAT_WS (concat with separator)
|
||||
SELECT CONCAT_WS(' ', first_name, last_name) as full_name FROM concat_test ORDER BY ts;
|
||||
|
||||
SELECT CONCAT_WS('-', first_name, last_name, age) FROM concat_test ORDER BY ts;
|
||||
|
||||
SELECT CONCAT_WS(',', 'a', 'b', 'c', 'd');
|
||||
|
||||
-- CONCAT_WS with NULL values (should skip NULLs)
|
||||
SELECT CONCAT_WS(' ', 'hello', NULL, 'world');
|
||||
|
||||
SELECT CONCAT_WS('|', first_name, last_name) FROM concat_test ORDER BY ts;
|
||||
|
||||
-- Test pipe operator ||
|
||||
SELECT 'hello' || 'world';
|
||||
|
||||
SELECT 'hello' || ' ' || 'world';
|
||||
|
||||
SELECT first_name || ' ' || last_name FROM concat_test WHERE first_name IS NOT NULL AND last_name IS NOT NULL ORDER BY ts;
|
||||
|
||||
-- Unicode concatenation
|
||||
SELECT CONCAT('Hello ', '世界');
|
||||
|
||||
SELECT CONCAT('🚀', ' ', '🌟');
|
||||
|
||||
SELECT '中文' || '🐄';
|
||||
|
||||
DROP TABLE concat_test;
|
||||
@@ -0,0 +1,183 @@
|
||||
-- String length function tests
|
||||
-- LENGTH function
|
||||
SELECT LENGTH('hello');
|
||||
|
||||
+-----------------------+
|
||||
| length(Utf8("hello")) |
|
||||
+-----------------------+
|
||||
| 5 |
|
||||
+-----------------------+
|
||||
|
||||
SELECT LENGTH('');
|
||||
|
||||
+------------------+
|
||||
| length(Utf8("")) |
|
||||
+------------------+
|
||||
| 0 |
|
||||
+------------------+
|
||||
|
||||
SELECT LENGTH(NULL);
|
||||
|
||||
+--------------+
|
||||
| length(NULL) |
|
||||
+--------------+
|
||||
| |
|
||||
+--------------+
|
||||
|
||||
SELECT LENGTH('hello world');
|
||||
|
||||
+-----------------------------+
|
||||
| length(Utf8("hello world")) |
|
||||
+-----------------------------+
|
||||
| 11 |
|
||||
+-----------------------------+
|
||||
|
||||
-- CHAR_LENGTH (character length)
|
||||
SELECT CHAR_LENGTH('hello');
|
||||
|
||||
+----------------------------+
|
||||
| char_length(Utf8("hello")) |
|
||||
+----------------------------+
|
||||
| 5 |
|
||||
+----------------------------+
|
||||
|
||||
SELECT CHAR_LENGTH('');
|
||||
|
||||
+-----------------------+
|
||||
| char_length(Utf8("")) |
|
||||
+-----------------------+
|
||||
| 0 |
|
||||
+-----------------------+
|
||||
|
||||
SELECT CHAR_LENGTH(NULL);
|
||||
|
||||
+-------------------+
|
||||
| char_length(NULL) |
|
||||
+-------------------+
|
||||
| |
|
||||
+-------------------+
|
||||
|
||||
-- CHARACTER_LENGTH (alias for CHAR_LENGTH)
|
||||
SELECT CHARACTER_LENGTH('hello world');
|
||||
|
||||
+---------------------------------------+
|
||||
| character_length(Utf8("hello world")) |
|
||||
+---------------------------------------+
|
||||
| 11 |
|
||||
+---------------------------------------+
|
||||
|
||||
-- Unicode character length
|
||||
SELECT LENGTH('世界') AS a, CHAR_LENGTH('世界') AS b;
|
||||
|
||||
+---+---+
|
||||
| a | b |
|
||||
+---+---+
|
||||
| 2 | 2 |
|
||||
+---+---+
|
||||
|
||||
SELECT LENGTH('🚀🌟') AS a, CHAR_LENGTH('🚀🌟') AS b;
|
||||
|
||||
+---+---+
|
||||
| a | b |
|
||||
+---+---+
|
||||
| 2 | 2 |
|
||||
+---+---+
|
||||
|
||||
SELECT LENGTH('café') AS a, CHAR_LENGTH('café') AS b;
|
||||
|
||||
+---+---+
|
||||
| a | b |
|
||||
+---+---+
|
||||
| 4 | 4 |
|
||||
+---+---+
|
||||
|
||||
-- Test with table data
|
||||
CREATE TABLE length_test(s VARCHAR, ts TIMESTAMP TIME INDEX);
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
INSERT INTO length_test VALUES
|
||||
('hello', 1000),
|
||||
('world!', 2000),
|
||||
('', 3000),
|
||||
('中文测试', 4000),
|
||||
('🚀🎉🌟', 5000),
|
||||
(NULL, 6000);
|
||||
|
||||
Affected Rows: 6
|
||||
|
||||
SELECT s, LENGTH(s) AS a, CHAR_LENGTH(s) AS b FROM length_test ORDER BY ts;
|
||||
|
||||
+----------+---+---+
|
||||
| s | a | b |
|
||||
+----------+---+---+
|
||||
| hello | 5 | 5 |
|
||||
| world! | 6 | 6 |
|
||||
| | 0 | 0 |
|
||||
| 中文测试 | 4 | 4 |
|
||||
| 🚀🎉🌟 | 3 | 3 |
|
||||
| | | |
|
||||
+----------+---+---+
|
||||
|
||||
-- BIT_LENGTH (length in bits)
|
||||
SELECT BIT_LENGTH('hello');
|
||||
|
||||
+---------------------------+
|
||||
| bit_length(Utf8("hello")) |
|
||||
+---------------------------+
|
||||
| 40 |
|
||||
+---------------------------+
|
||||
|
||||
SELECT BIT_LENGTH('');
|
||||
|
||||
+----------------------+
|
||||
| bit_length(Utf8("")) |
|
||||
+----------------------+
|
||||
| 0 |
|
||||
+----------------------+
|
||||
|
||||
SELECT BIT_LENGTH('世界');
|
||||
|
||||
+--------------------------+
|
||||
| bit_length(Utf8("世界")) |
|
||||
+--------------------------+
|
||||
| 48 |
|
||||
+--------------------------+
|
||||
|
||||
-- OCTET_LENGTH (length in bytes)
|
||||
SELECT OCTET_LENGTH('hello');
|
||||
|
||||
+-----------------------------+
|
||||
| octet_length(Utf8("hello")) |
|
||||
+-----------------------------+
|
||||
| 5 |
|
||||
+-----------------------------+
|
||||
|
||||
SELECT OCTET_LENGTH('');
|
||||
|
||||
+------------------------+
|
||||
| octet_length(Utf8("")) |
|
||||
+------------------------+
|
||||
| 0 |
|
||||
+------------------------+
|
||||
|
||||
SELECT OCTET_LENGTH('世界');
|
||||
|
||||
+----------------------------+
|
||||
| octet_length(Utf8("世界")) |
|
||||
+----------------------------+
|
||||
| 6 |
|
||||
+----------------------------+
|
||||
|
||||
SELECT OCTET_LENGTH('🚀');
|
||||
|
||||
+--------------------------+
|
||||
| octet_length(Utf8("🚀")) |
|
||||
+--------------------------+
|
||||
| 4 |
|
||||
+--------------------------+
|
||||
|
||||
DROP TABLE length_test;
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
-- String length function tests
|
||||
|
||||
-- LENGTH function
|
||||
SELECT LENGTH('hello');
|
||||
|
||||
SELECT LENGTH('');
|
||||
|
||||
SELECT LENGTH(NULL);
|
||||
|
||||
SELECT LENGTH('hello world');
|
||||
|
||||
-- CHAR_LENGTH (character length)
|
||||
SELECT CHAR_LENGTH('hello');
|
||||
|
||||
SELECT CHAR_LENGTH('');
|
||||
|
||||
SELECT CHAR_LENGTH(NULL);
|
||||
|
||||
-- CHARACTER_LENGTH (alias for CHAR_LENGTH)
|
||||
SELECT CHARACTER_LENGTH('hello world');
|
||||
|
||||
-- Unicode character length
|
||||
SELECT LENGTH('世界') AS a, CHAR_LENGTH('世界') AS b;
|
||||
|
||||
SELECT LENGTH('🚀🌟') AS a, CHAR_LENGTH('🚀🌟') AS b;
|
||||
|
||||
SELECT LENGTH('café') AS a, CHAR_LENGTH('café') AS b;
|
||||
|
||||
-- Test with table data
|
||||
CREATE TABLE length_test(s VARCHAR, ts TIMESTAMP TIME INDEX);
|
||||
|
||||
INSERT INTO length_test VALUES
|
||||
('hello', 1000),
|
||||
('world!', 2000),
|
||||
('', 3000),
|
||||
('中文测试', 4000),
|
||||
('🚀🎉🌟', 5000),
|
||||
(NULL, 6000);
|
||||
|
||||
SELECT s, LENGTH(s) AS a, CHAR_LENGTH(s) AS b FROM length_test ORDER BY ts;
|
||||
|
||||
-- BIT_LENGTH (length in bits)
|
||||
SELECT BIT_LENGTH('hello');
|
||||
|
||||
SELECT BIT_LENGTH('');
|
||||
|
||||
SELECT BIT_LENGTH('世界');
|
||||
|
||||
-- OCTET_LENGTH (length in bytes)
|
||||
SELECT OCTET_LENGTH('hello');
|
||||
|
||||
SELECT OCTET_LENGTH('');
|
||||
|
||||
SELECT OCTET_LENGTH('世界');
|
||||
|
||||
SELECT OCTET_LENGTH('🚀');
|
||||
|
||||
DROP TABLE length_test;
|
||||
@@ -0,0 +1,280 @@
|
||||
-- String LIKE pattern matching tests
|
||||
-- Basic LIKE patterns
|
||||
SELECT 'hello world' LIKE 'hello%';
|
||||
|
||||
+-----------------------------------------+
|
||||
| Utf8("hello world") LIKE Utf8("hello%") |
|
||||
+-----------------------------------------+
|
||||
| true |
|
||||
+-----------------------------------------+
|
||||
|
||||
SELECT 'hello world' LIKE '%world';
|
||||
|
||||
+-----------------------------------------+
|
||||
| Utf8("hello world") LIKE Utf8("%world") |
|
||||
+-----------------------------------------+
|
||||
| true |
|
||||
+-----------------------------------------+
|
||||
|
||||
SELECT 'hello world' LIKE '%llo%';
|
||||
|
||||
+----------------------------------------+
|
||||
| Utf8("hello world") LIKE Utf8("%llo%") |
|
||||
+----------------------------------------+
|
||||
| true |
|
||||
+----------------------------------------+
|
||||
|
||||
SELECT 'hello world' LIKE 'hello_world';
|
||||
|
||||
+----------------------------------------------+
|
||||
| Utf8("hello world") LIKE Utf8("hello_world") |
|
||||
+----------------------------------------------+
|
||||
| true |
|
||||
+----------------------------------------------+
|
||||
|
||||
SELECT 'hello world' LIKE 'hello world';
|
||||
|
||||
+----------------------------------------------+
|
||||
| Utf8("hello world") LIKE Utf8("hello world") |
|
||||
+----------------------------------------------+
|
||||
| true |
|
||||
+----------------------------------------------+
|
||||
|
||||
-- LIKE with NOT
|
||||
SELECT 'hello world' NOT LIKE 'goodbye%';
|
||||
|
||||
+-----------------------------------------------+
|
||||
| Utf8("hello world") NOT LIKE Utf8("goodbye%") |
|
||||
+-----------------------------------------------+
|
||||
| true |
|
||||
+-----------------------------------------------+
|
||||
|
||||
SELECT 'hello world' NOT LIKE 'hello%';
|
||||
|
||||
+---------------------------------------------+
|
||||
| Utf8("hello world") NOT LIKE Utf8("hello%") |
|
||||
+---------------------------------------------+
|
||||
| false |
|
||||
+---------------------------------------------+
|
||||
|
||||
-- Case sensitivity
|
||||
SELECT 'Hello World' LIKE 'hello%';
|
||||
|
||||
+-----------------------------------------+
|
||||
| Utf8("Hello World") LIKE Utf8("hello%") |
|
||||
+-----------------------------------------+
|
||||
| false |
|
||||
+-----------------------------------------+
|
||||
|
||||
SELECT 'Hello World' ILIKE 'hello%';
|
||||
|
||||
+------------------------------------------+
|
||||
| Utf8("Hello World") ILIKE Utf8("hello%") |
|
||||
+------------------------------------------+
|
||||
| true |
|
||||
+------------------------------------------+
|
||||
|
||||
SELECT 'Hello World' ILIKE 'HELLO%';
|
||||
|
||||
+------------------------------------------+
|
||||
| Utf8("Hello World") ILIKE Utf8("HELLO%") |
|
||||
+------------------------------------------+
|
||||
| true |
|
||||
+------------------------------------------+
|
||||
|
||||
-- Test with table data
|
||||
CREATE TABLE like_test("name" VARCHAR, email VARCHAR, ts TIMESTAMP TIME INDEX);
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
INSERT INTO like_test VALUES
|
||||
('John Doe', 'john@example.com', 1000),
|
||||
('Jane Smith', 'jane@gmail.com', 2000),
|
||||
('Bob Wilson', 'bob@yahoo.com', 3000),
|
||||
('Alice Johnson', 'alice@company.org', 4000),
|
||||
('Charlie Brown', 'charlie@test.net', 5000);
|
||||
|
||||
Affected Rows: 5
|
||||
|
||||
-- Pattern matching on names
|
||||
SELECT "name" FROM like_test WHERE "name" LIKE 'J%' ORDER BY ts;
|
||||
|
||||
+------------+
|
||||
| name |
|
||||
+------------+
|
||||
| John Doe |
|
||||
| Jane Smith |
|
||||
+------------+
|
||||
|
||||
SELECT "name" FROM like_test WHERE "name" LIKE '%son' ORDER BY ts;
|
||||
|
||||
+---------------+
|
||||
| name |
|
||||
+---------------+
|
||||
| Bob Wilson |
|
||||
| Alice Johnson |
|
||||
+---------------+
|
||||
|
||||
-- Contains space
|
||||
SELECT "name" FROM like_test WHERE "name" LIKE '% %' ORDER BY ts;
|
||||
|
||||
+---------------+
|
||||
| name |
|
||||
+---------------+
|
||||
| John Doe |
|
||||
| Jane Smith |
|
||||
| Bob Wilson |
|
||||
| Alice Johnson |
|
||||
| Charlie Brown |
|
||||
+---------------+
|
||||
|
||||
-- Pattern matching on emails
|
||||
SELECT "name", email FROM like_test WHERE email LIKE '%@gmail.com' ORDER BY ts;
|
||||
|
||||
+------------+----------------+
|
||||
| name | email |
|
||||
+------------+----------------+
|
||||
| Jane Smith | jane@gmail.com |
|
||||
+------------+----------------+
|
||||
|
||||
SELECT "name", email FROM like_test WHERE email LIKE '%.com' ORDER BY ts;
|
||||
|
||||
+------------+------------------+
|
||||
| name | email |
|
||||
+------------+------------------+
|
||||
| John Doe | john@example.com |
|
||||
| Jane Smith | jane@gmail.com |
|
||||
| Bob Wilson | bob@yahoo.com |
|
||||
+------------+------------------+
|
||||
|
||||
SELECT "name", email FROM like_test WHERE email LIKE '%@%.org' ORDER BY ts;
|
||||
|
||||
+---------------+-------------------+
|
||||
| name | email |
|
||||
+---------------+-------------------+
|
||||
| Alice Johnson | alice@company.org |
|
||||
+---------------+-------------------+
|
||||
|
||||
-- Underscore wildcard
|
||||
SELECT "name" FROM like_test WHERE "name" LIKE 'Jo__ ___' ORDER BY ts;
|
||||
|
||||
+----------+
|
||||
| name |
|
||||
+----------+
|
||||
| John Doe |
|
||||
+----------+
|
||||
|
||||
SELECT email FROM like_test WHERE email LIKE '____@%' ORDER BY ts;
|
||||
|
||||
+------------------+
|
||||
| email |
|
||||
+------------------+
|
||||
| john@example.com |
|
||||
| jane@gmail.com |
|
||||
+------------------+
|
||||
|
||||
-- Multiple wildcards
|
||||
-- Contains 'o'
|
||||
SELECT "name" FROM like_test WHERE "name" LIKE '%o%' ORDER BY ts;
|
||||
|
||||
+---------------+
|
||||
| name |
|
||||
+---------------+
|
||||
| John Doe |
|
||||
| Bob Wilson |
|
||||
| Alice Johnson |
|
||||
| Charlie Brown |
|
||||
+---------------+
|
||||
|
||||
-- 'a' before and after @
|
||||
SELECT email FROM like_test WHERE email LIKE '%a%@%a%' ORDER BY ts;
|
||||
|
||||
+-------------------+
|
||||
| email |
|
||||
+-------------------+
|
||||
| jane@gmail.com |
|
||||
| alice@company.org |
|
||||
+-------------------+
|
||||
|
||||
-- Escaping special characters
|
||||
CREATE TABLE escape_test("text" VARCHAR, ts TIMESTAMP TIME INDEX);
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
INSERT INTO escape_test VALUES
|
||||
('100% complete', 1000),
|
||||
('test_file.txt', 2000),
|
||||
('50% done', 3000),
|
||||
('backup_2023.sql', 4000);
|
||||
|
||||
Affected Rows: 4
|
||||
|
||||
-- Need to escape % and _
|
||||
-- Contains %
|
||||
SELECT "text" FROM escape_test WHERE "text" LIKE '%\%%' ORDER BY ts;
|
||||
|
||||
+---------------+
|
||||
| text |
|
||||
+---------------+
|
||||
| 100% complete |
|
||||
| 50% done |
|
||||
+---------------+
|
||||
|
||||
-- Contains _
|
||||
SELECT "text" FROM escape_test WHERE "text" LIKE '%\_%' ORDER BY ts;
|
||||
|
||||
+-----------------+
|
||||
| text |
|
||||
+-----------------+
|
||||
| test_file.txt |
|
||||
| backup_2023.sql |
|
||||
+-----------------+
|
||||
|
||||
-- Unicode pattern matching
|
||||
CREATE TABLE unicode_like(s VARCHAR, ts TIMESTAMP TIME INDEX);
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
INSERT INTO unicode_like VALUES
|
||||
('Hello 世界', 1000),
|
||||
('🚀 rocket', 2000),
|
||||
('café shop', 3000);
|
||||
|
||||
Affected Rows: 3
|
||||
|
||||
SELECT s FROM unicode_like WHERE s LIKE '%世界' ORDER BY ts;
|
||||
|
||||
+------------+
|
||||
| s |
|
||||
+------------+
|
||||
| Hello 世界 |
|
||||
+------------+
|
||||
|
||||
SELECT s FROM unicode_like WHERE s LIKE '🚀%' ORDER BY ts;
|
||||
|
||||
+-----------+
|
||||
| s |
|
||||
+-----------+
|
||||
| 🚀 rocket |
|
||||
+-----------+
|
||||
|
||||
SELECT s FROM unicode_like WHERE s LIKE '%é%' ORDER BY ts;
|
||||
|
||||
+-----------+
|
||||
| s |
|
||||
+-----------+
|
||||
| café shop |
|
||||
+-----------+
|
||||
|
||||
DROP TABLE like_test;
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
DROP TABLE escape_test;
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
DROP TABLE unicode_like;
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
-- String LIKE pattern matching tests
|
||||
|
||||
-- Basic LIKE patterns
|
||||
SELECT 'hello world' LIKE 'hello%';
|
||||
|
||||
SELECT 'hello world' LIKE '%world';
|
||||
|
||||
SELECT 'hello world' LIKE '%llo%';
|
||||
|
||||
SELECT 'hello world' LIKE 'hello_world';
|
||||
|
||||
SELECT 'hello world' LIKE 'hello world';
|
||||
|
||||
-- LIKE with NOT
|
||||
SELECT 'hello world' NOT LIKE 'goodbye%';
|
||||
|
||||
SELECT 'hello world' NOT LIKE 'hello%';
|
||||
|
||||
-- Case sensitivity
|
||||
SELECT 'Hello World' LIKE 'hello%';
|
||||
|
||||
SELECT 'Hello World' ILIKE 'hello%';
|
||||
|
||||
SELECT 'Hello World' ILIKE 'HELLO%';
|
||||
|
||||
-- Test with table data
|
||||
CREATE TABLE like_test("name" VARCHAR, email VARCHAR, ts TIMESTAMP TIME INDEX);
|
||||
|
||||
INSERT INTO like_test VALUES
|
||||
('John Doe', 'john@example.com', 1000),
|
||||
('Jane Smith', 'jane@gmail.com', 2000),
|
||||
('Bob Wilson', 'bob@yahoo.com', 3000),
|
||||
('Alice Johnson', 'alice@company.org', 4000),
|
||||
('Charlie Brown', 'charlie@test.net', 5000);
|
||||
|
||||
-- Pattern matching on names
|
||||
SELECT "name" FROM like_test WHERE "name" LIKE 'J%' ORDER BY ts;
|
||||
|
||||
SELECT "name" FROM like_test WHERE "name" LIKE '%son' ORDER BY ts;
|
||||
|
||||
-- Contains space
|
||||
SELECT "name" FROM like_test WHERE "name" LIKE '% %' ORDER BY ts;
|
||||
|
||||
-- Pattern matching on emails
|
||||
SELECT "name", email FROM like_test WHERE email LIKE '%@gmail.com' ORDER BY ts;
|
||||
|
||||
SELECT "name", email FROM like_test WHERE email LIKE '%.com' ORDER BY ts;
|
||||
|
||||
SELECT "name", email FROM like_test WHERE email LIKE '%@%.org' ORDER BY ts;
|
||||
|
||||
-- Underscore wildcard
|
||||
SELECT "name" FROM like_test WHERE "name" LIKE 'Jo__ ___' ORDER BY ts;
|
||||
|
||||
SELECT email FROM like_test WHERE email LIKE '____@%' ORDER BY ts;
|
||||
|
||||
-- Multiple wildcards
|
||||
-- Contains 'o'
|
||||
SELECT "name" FROM like_test WHERE "name" LIKE '%o%' ORDER BY ts;
|
||||
|
||||
-- 'a' before and after @
|
||||
SELECT email FROM like_test WHERE email LIKE '%a%@%a%' ORDER BY ts;
|
||||
|
||||
-- Escaping special characters
|
||||
CREATE TABLE escape_test("text" VARCHAR, ts TIMESTAMP TIME INDEX);
|
||||
|
||||
INSERT INTO escape_test VALUES
|
||||
('100% complete', 1000),
|
||||
('test_file.txt', 2000),
|
||||
('50% done', 3000),
|
||||
('backup_2023.sql', 4000);
|
||||
|
||||
-- Need to escape % and _
|
||||
-- Contains %
|
||||
SELECT "text" FROM escape_test WHERE "text" LIKE '%\%%' ORDER BY ts;
|
||||
|
||||
-- Contains _
|
||||
SELECT "text" FROM escape_test WHERE "text" LIKE '%\_%' ORDER BY ts;
|
||||
|
||||
-- Unicode pattern matching
|
||||
CREATE TABLE unicode_like(s VARCHAR, ts TIMESTAMP TIME INDEX);
|
||||
|
||||
INSERT INTO unicode_like VALUES
|
||||
('Hello 世界', 1000),
|
||||
('🚀 rocket', 2000),
|
||||
('café shop', 3000);
|
||||
|
||||
SELECT s FROM unicode_like WHERE s LIKE '%世界' ORDER BY ts;
|
||||
|
||||
SELECT s FROM unicode_like WHERE s LIKE '🚀%' ORDER BY ts;
|
||||
|
||||
SELECT s FROM unicode_like WHERE s LIKE '%é%' ORDER BY ts;
|
||||
|
||||
DROP TABLE like_test;
|
||||
|
||||
DROP TABLE escape_test;
|
||||
|
||||
DROP TABLE unicode_like;
|
||||
@@ -0,0 +1,278 @@
|
||||
-- String position/search function tests
|
||||
-- POSITION function
|
||||
SELECT POSITION('world' IN 'hello world');
|
||||
|
||||
+-------------------------------------------+
|
||||
| strpos(Utf8("hello world"),Utf8("world")) |
|
||||
+-------------------------------------------+
|
||||
| 7 |
|
||||
+-------------------------------------------+
|
||||
|
||||
SELECT POSITION('xyz' IN 'hello world');
|
||||
|
||||
+-----------------------------------------+
|
||||
| strpos(Utf8("hello world"),Utf8("xyz")) |
|
||||
+-----------------------------------------+
|
||||
| 0 |
|
||||
+-----------------------------------------+
|
||||
|
||||
SELECT POSITION('' IN 'hello world');
|
||||
|
||||
+--------------------------------------+
|
||||
| strpos(Utf8("hello world"),Utf8("")) |
|
||||
+--------------------------------------+
|
||||
| 1 |
|
||||
+--------------------------------------+
|
||||
|
||||
SELECT POSITION('world' IN '');
|
||||
|
||||
+--------------------------------+
|
||||
| strpos(Utf8(""),Utf8("world")) |
|
||||
+--------------------------------+
|
||||
| 0 |
|
||||
+--------------------------------+
|
||||
|
||||
-- STRPOS function (same as POSITION)
|
||||
SELECT STRPOS('hello world', 'world');
|
||||
|
||||
+-------------------------------------------+
|
||||
| strpos(Utf8("hello world"),Utf8("world")) |
|
||||
+-------------------------------------------+
|
||||
| 7 |
|
||||
+-------------------------------------------+
|
||||
|
||||
SELECT STRPOS('hello world', 'xyz');
|
||||
|
||||
+-----------------------------------------+
|
||||
| strpos(Utf8("hello world"),Utf8("xyz")) |
|
||||
+-----------------------------------------+
|
||||
| 0 |
|
||||
+-----------------------------------------+
|
||||
|
||||
SELECT STRPOS('hello world', 'hello');
|
||||
|
||||
+-------------------------------------------+
|
||||
| strpos(Utf8("hello world"),Utf8("hello")) |
|
||||
+-------------------------------------------+
|
||||
| 1 |
|
||||
+-------------------------------------------+
|
||||
|
||||
SELECT STRPOS('hello world', 'o');
|
||||
|
||||
+---------------------------------------+
|
||||
| strpos(Utf8("hello world"),Utf8("o")) |
|
||||
+---------------------------------------+
|
||||
| 5 |
|
||||
+---------------------------------------+
|
||||
|
||||
-- INSTR function
|
||||
SELECT INSTR('hello world', 'world');
|
||||
|
||||
+------------------------------------------+
|
||||
| instr(Utf8("hello world"),Utf8("world")) |
|
||||
+------------------------------------------+
|
||||
| 7 |
|
||||
+------------------------------------------+
|
||||
|
||||
SELECT INSTR('hello world', 'o');
|
||||
|
||||
+--------------------------------------+
|
||||
| instr(Utf8("hello world"),Utf8("o")) |
|
||||
+--------------------------------------+
|
||||
| 5 |
|
||||
+--------------------------------------+
|
||||
|
||||
SELECT INSTR('hello world', 'xyz');
|
||||
|
||||
+----------------------------------------+
|
||||
| instr(Utf8("hello world"),Utf8("xyz")) |
|
||||
+----------------------------------------+
|
||||
| 0 |
|
||||
+----------------------------------------+
|
||||
|
||||
-- Case sensitive search
|
||||
SELECT POSITION('WORLD' IN 'hello world');
|
||||
|
||||
+-------------------------------------------+
|
||||
| strpos(Utf8("hello world"),Utf8("WORLD")) |
|
||||
+-------------------------------------------+
|
||||
| 0 |
|
||||
+-------------------------------------------+
|
||||
|
||||
SELECT POSITION('World' IN 'hello world');
|
||||
|
||||
+-------------------------------------------+
|
||||
| strpos(Utf8("hello world"),Utf8("World")) |
|
||||
+-------------------------------------------+
|
||||
| 0 |
|
||||
+-------------------------------------------+
|
||||
|
||||
-- LEFT and RIGHT functions
|
||||
SELECT LEFT('hello world', 5);
|
||||
|
||||
+------------------------------------+
|
||||
| left(Utf8("hello world"),Int64(5)) |
|
||||
+------------------------------------+
|
||||
| hello |
|
||||
+------------------------------------+
|
||||
|
||||
SELECT RIGHT('hello world', 5);
|
||||
|
||||
+-------------------------------------+
|
||||
| right(Utf8("hello world"),Int64(5)) |
|
||||
+-------------------------------------+
|
||||
| world |
|
||||
+-------------------------------------+
|
||||
|
||||
-- More than string length
|
||||
SELECT LEFT('hello', 10);
|
||||
|
||||
+-------------------------------+
|
||||
| left(Utf8("hello"),Int64(10)) |
|
||||
+-------------------------------+
|
||||
| hello |
|
||||
+-------------------------------+
|
||||
|
||||
-- More than string length
|
||||
SELECT RIGHT('hello', 10);
|
||||
|
||||
+--------------------------------+
|
||||
| right(Utf8("hello"),Int64(10)) |
|
||||
+--------------------------------+
|
||||
| hello |
|
||||
+--------------------------------+
|
||||
|
||||
-- Test with NULL values
|
||||
SELECT POSITION('world' IN NULL);
|
||||
|
||||
+----------------------------+
|
||||
| strpos(NULL,Utf8("world")) |
|
||||
+----------------------------+
|
||||
| |
|
||||
+----------------------------+
|
||||
|
||||
SELECT POSITION(NULL IN 'hello world');
|
||||
|
||||
+----------------------------------+
|
||||
| strpos(Utf8("hello world"),NULL) |
|
||||
+----------------------------------+
|
||||
| |
|
||||
+----------------------------------+
|
||||
|
||||
SELECT LEFT(NULL, 5);
|
||||
|
||||
+---------------------+
|
||||
| left(NULL,Int64(5)) |
|
||||
+---------------------+
|
||||
| |
|
||||
+---------------------+
|
||||
|
||||
SELECT RIGHT('hello', NULL);
|
||||
|
||||
+---------------------------+
|
||||
| right(Utf8("hello"),NULL) |
|
||||
+---------------------------+
|
||||
| |
|
||||
+---------------------------+
|
||||
|
||||
-- Test with table data
|
||||
CREATE TABLE position_test(s VARCHAR, "search" VARCHAR, ts TIMESTAMP TIME INDEX);
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
INSERT INTO position_test VALUES
|
||||
('hello world', 'world', 1000),
|
||||
('hello world', 'hello', 2000),
|
||||
('hello world', 'xyz', 3000),
|
||||
('programming', 'gram', 4000),
|
||||
('database', 'base', 5000);
|
||||
|
||||
Affected Rows: 5
|
||||
|
||||
SELECT s, "search", POSITION("search" IN s) AS a, STRPOS(s, "search") AS b FROM position_test ORDER BY ts;
|
||||
|
||||
+-------------+--------+---+---+
|
||||
| s | search | a | b |
|
||||
+-------------+--------+---+---+
|
||||
| hello world | world | 7 | 7 |
|
||||
| hello world | hello | 1 | 1 |
|
||||
| hello world | xyz | 0 | 0 |
|
||||
| programming | gram | 4 | 4 |
|
||||
| database | base | 5 | 5 |
|
||||
+-------------+--------+---+---+
|
||||
|
||||
-- Test LEFT and RIGHT with table data
|
||||
SELECT s, LEFT(s, 5), RIGHT(s, 5) FROM position_test ORDER BY ts;
|
||||
|
||||
+-------------+--------------------------------+---------------------------------+
|
||||
| s | left(position_test.s,Int64(5)) | right(position_test.s,Int64(5)) |
|
||||
+-------------+--------------------------------+---------------------------------+
|
||||
| hello world | hello | world |
|
||||
| hello world | hello | world |
|
||||
| hello world | hello | world |
|
||||
| programming | progr | mming |
|
||||
| database | datab | abase |
|
||||
+-------------+--------------------------------+---------------------------------+
|
||||
|
||||
-- Unicode position tests
|
||||
SELECT POSITION('世' IN 'hello世界');
|
||||
|
||||
+--------------------------------------+
|
||||
| strpos(Utf8("hello世界"),Utf8("世")) |
|
||||
+--------------------------------------+
|
||||
| 6 |
|
||||
+--------------------------------------+
|
||||
|
||||
SELECT POSITION('界' IN 'hello世界');
|
||||
|
||||
+--------------------------------------+
|
||||
| strpos(Utf8("hello世界"),Utf8("界")) |
|
||||
+--------------------------------------+
|
||||
| 7 |
|
||||
+--------------------------------------+
|
||||
|
||||
SELECT STRPOS('café shop', 'é');
|
||||
|
||||
+-------------------------------------+
|
||||
| strpos(Utf8("café shop"),Utf8("é")) |
|
||||
+-------------------------------------+
|
||||
| 4 |
|
||||
+-------------------------------------+
|
||||
|
||||
SELECT LEFT('中文测试', 2);
|
||||
|
||||
+---------------------------------+
|
||||
| left(Utf8("中文测试"),Int64(2)) |
|
||||
+---------------------------------+
|
||||
| 中文 |
|
||||
+---------------------------------+
|
||||
|
||||
SELECT RIGHT('中文测试', 2);
|
||||
|
||||
+----------------------------------+
|
||||
| right(Utf8("中文测试"),Int64(2)) |
|
||||
+----------------------------------+
|
||||
| 测试 |
|
||||
+----------------------------------+
|
||||
|
||||
-- Multiple occurrences (finds first one)
|
||||
SELECT POSITION('o' IN 'hello world');
|
||||
|
||||
+---------------------------------------+
|
||||
| strpos(Utf8("hello world"),Utf8("o")) |
|
||||
+---------------------------------------+
|
||||
| 5 |
|
||||
+---------------------------------------+
|
||||
|
||||
SELECT STRPOS('hello world', 'l');
|
||||
|
||||
+---------------------------------------+
|
||||
| strpos(Utf8("hello world"),Utf8("l")) |
|
||||
+---------------------------------------+
|
||||
| 3 |
|
||||
+---------------------------------------+
|
||||
|
||||
DROP TABLE position_test;
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
-- String position/search function tests
|
||||
|
||||
-- POSITION function
|
||||
SELECT POSITION('world' IN 'hello world');
|
||||
|
||||
SELECT POSITION('xyz' IN 'hello world');
|
||||
|
||||
SELECT POSITION('' IN 'hello world');
|
||||
|
||||
SELECT POSITION('world' IN '');
|
||||
|
||||
-- STRPOS function (same as POSITION)
|
||||
SELECT STRPOS('hello world', 'world');
|
||||
|
||||
SELECT STRPOS('hello world', 'xyz');
|
||||
|
||||
SELECT STRPOS('hello world', 'hello');
|
||||
|
||||
SELECT STRPOS('hello world', 'o');
|
||||
|
||||
-- INSTR function
|
||||
SELECT INSTR('hello world', 'world');
|
||||
|
||||
SELECT INSTR('hello world', 'o');
|
||||
|
||||
SELECT INSTR('hello world', 'xyz');
|
||||
|
||||
-- Case sensitive search
|
||||
SELECT POSITION('WORLD' IN 'hello world');
|
||||
|
||||
SELECT POSITION('World' IN 'hello world');
|
||||
|
||||
-- LEFT and RIGHT functions
|
||||
SELECT LEFT('hello world', 5);
|
||||
|
||||
SELECT RIGHT('hello world', 5);
|
||||
|
||||
-- More than string length
|
||||
SELECT LEFT('hello', 10);
|
||||
|
||||
-- More than string length
|
||||
SELECT RIGHT('hello', 10);
|
||||
|
||||
-- Test with NULL values
|
||||
SELECT POSITION('world' IN NULL);
|
||||
|
||||
SELECT POSITION(NULL IN 'hello world');
|
||||
|
||||
SELECT LEFT(NULL, 5);
|
||||
|
||||
SELECT RIGHT('hello', NULL);
|
||||
|
||||
-- Test with table data
|
||||
CREATE TABLE position_test(s VARCHAR, "search" VARCHAR, ts TIMESTAMP TIME INDEX);
|
||||
|
||||
INSERT INTO position_test VALUES
|
||||
('hello world', 'world', 1000),
|
||||
('hello world', 'hello', 2000),
|
||||
('hello world', 'xyz', 3000),
|
||||
('programming', 'gram', 4000),
|
||||
('database', 'base', 5000);
|
||||
|
||||
SELECT s, "search", POSITION("search" IN s) AS a, STRPOS(s, "search") AS b FROM position_test ORDER BY ts;
|
||||
|
||||
-- Test LEFT and RIGHT with table data
|
||||
SELECT s, LEFT(s, 5), RIGHT(s, 5) FROM position_test ORDER BY ts;
|
||||
|
||||
-- Unicode position tests
|
||||
SELECT POSITION('世' IN 'hello世界');
|
||||
|
||||
SELECT POSITION('界' IN 'hello世界');
|
||||
|
||||
SELECT STRPOS('café shop', 'é');
|
||||
|
||||
SELECT LEFT('中文测试', 2);
|
||||
|
||||
SELECT RIGHT('中文测试', 2);
|
||||
|
||||
-- Multiple occurrences (finds first one)
|
||||
SELECT POSITION('o' IN 'hello world');
|
||||
|
||||
SELECT STRPOS('hello world', 'l');
|
||||
|
||||
DROP TABLE position_test;
|
||||
@@ -0,0 +1,143 @@
|
||||
-- Regular expression function tests
|
||||
-- REGEXP_MATCHES function
|
||||
SELECT regexp_like('hello123world', '\d+');
|
||||
|
||||
+------------------------------------------------+
|
||||
| regexp_like(Utf8("hello123world"),Utf8("\d+")) |
|
||||
+------------------------------------------------+
|
||||
| true |
|
||||
+------------------------------------------------+
|
||||
|
||||
SELECT regexp_like('no numbers here', '\d+');
|
||||
|
||||
+--------------------------------------------------+
|
||||
| regexp_like(Utf8("no numbers here"),Utf8("\d+")) |
|
||||
+--------------------------------------------------+
|
||||
| false |
|
||||
+--------------------------------------------------+
|
||||
|
||||
SELECT regexp_like('email@example.com', '[a-zA-Z0-9]+@[a-zA-Z0-9]+\.[a-zA-Z]+');
|
||||
|
||||
+-------------------------------------------------------------------------------------+
|
||||
| regexp_like(Utf8("email@example.com"),Utf8("[a-zA-Z0-9]+@[a-zA-Z0-9]+\.[a-zA-Z]+")) |
|
||||
+-------------------------------------------------------------------------------------+
|
||||
| true |
|
||||
+-------------------------------------------------------------------------------------+
|
||||
|
||||
-- REGEXP_REPLACE function
|
||||
SELECT REGEXP_REPLACE('hello123world', '\d+', 'XXX');
|
||||
|
||||
+---------------------------------------------------------------+
|
||||
| regexp_replace(Utf8("hello123world"),Utf8("\d+"),Utf8("XXX")) |
|
||||
+---------------------------------------------------------------+
|
||||
| helloXXXworld |
|
||||
+---------------------------------------------------------------+
|
||||
|
||||
SELECT REGEXP_REPLACE('phone: 123-456-7890', '\d{3}-\d{3}-\d{4}', 'XXX-XXX-XXXX');
|
||||
|
||||
+--------------------------------------------------------------------------------------------+
|
||||
| regexp_replace(Utf8("phone: 123-456-7890"),Utf8("\d{3}-\d{3}-\d{4}"),Utf8("XXX-XXX-XXXX")) |
|
||||
+--------------------------------------------------------------------------------------------+
|
||||
| phone: XXX-XXX-XXXX |
|
||||
+--------------------------------------------------------------------------------------------+
|
||||
|
||||
SELECT REGEXP_REPLACE(' extra spaces ', '\s+', ' ');
|
||||
|
||||
+------------------------------------------------------------------+
|
||||
| regexp_replace(Utf8(" extra spaces "),Utf8("\s+"),Utf8(" ")) |
|
||||
+------------------------------------------------------------------+
|
||||
| extra spaces |
|
||||
+------------------------------------------------------------------+
|
||||
|
||||
-- REGEXP_EXTRACT function
|
||||
SELECT REGEXP_EXTRACT('version 1.2.3', '\d+\.\d+\.\d+');
|
||||
|
||||
+-------------------------------------------------------------+
|
||||
| regexp_extract(Utf8("version 1.2.3"),Utf8("\d+\.\d+\.\d+")) |
|
||||
+-------------------------------------------------------------+
|
||||
| 1.2.3 |
|
||||
+-------------------------------------------------------------+
|
||||
|
||||
SELECT REGEXP_EXTRACT('no match here', '\d+\.\d+\.\d+');
|
||||
|
||||
+-------------------------------------------------------------+
|
||||
| regexp_extract(Utf8("no match here"),Utf8("\d+\.\d+\.\d+")) |
|
||||
+-------------------------------------------------------------+
|
||||
| |
|
||||
+-------------------------------------------------------------+
|
||||
|
||||
-- Test with ~ operator (regex match)
|
||||
SELECT 'hello123' ~ '\d+';
|
||||
|
||||
+--------------------------------+
|
||||
| Utf8("hello123") ~ Utf8("\d+") |
|
||||
+--------------------------------+
|
||||
| true |
|
||||
+--------------------------------+
|
||||
|
||||
SELECT 'hello world' ~ '\d+';
|
||||
|
||||
+-----------------------------------+
|
||||
| Utf8("hello world") ~ Utf8("\d+") |
|
||||
+-----------------------------------+
|
||||
| false |
|
||||
+-----------------------------------+
|
||||
|
||||
SELECT 'email@example.com' ~ '[a-zA-Z0-9]+@[a-zA-Z0-9]+\.[a-zA-Z]+';
|
||||
|
||||
+--------------------------------------------------------------------------+
|
||||
| Utf8("email@example.com") ~ Utf8("[a-zA-Z0-9]+@[a-zA-Z0-9]+\.[a-zA-Z]+") |
|
||||
+--------------------------------------------------------------------------+
|
||||
| true |
|
||||
+--------------------------------------------------------------------------+
|
||||
|
||||
-- Test with table data
|
||||
CREATE TABLE regex_test("text" VARCHAR, ts TIMESTAMP TIME INDEX);
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
INSERT INTO regex_test VALUES
|
||||
('Phone: 123-456-7890', 1000),
|
||||
('Email: user@domain.com', 2000),
|
||||
('Version 2.1.0', 3000),
|
||||
('No pattern here', 4000);
|
||||
|
||||
Affected Rows: 4
|
||||
|
||||
SELECT "text", REGEXP_EXTRACT("text", '\d{3}-\d{3}-\d{4}') as phone FROM regex_test ORDER BY ts;
|
||||
|
||||
+------------------------+--------------+
|
||||
| text | phone |
|
||||
+------------------------+--------------+
|
||||
| Phone: 123-456-7890 | 123-456-7890 |
|
||||
| Email: user@domain.com | |
|
||||
| Version 2.1.0 | |
|
||||
| No pattern here | |
|
||||
+------------------------+--------------+
|
||||
|
||||
SELECT "text", REGEXP_EXTRACT("text", '[a-zA-Z0-9]+@[a-zA-Z0-9]+\.[a-zA-Z]+') as email FROM regex_test ORDER BY ts;
|
||||
|
||||
+------------------------+-----------------+
|
||||
| text | email |
|
||||
+------------------------+-----------------+
|
||||
| Phone: 123-456-7890 | |
|
||||
| Email: user@domain.com | user@domain.com |
|
||||
| Version 2.1.0 | |
|
||||
| No pattern here | |
|
||||
+------------------------+-----------------+
|
||||
|
||||
SELECT "text", REGEXP_EXTRACT("text", '\d+\.\d+\.\d+') as version FROM regex_test ORDER BY ts;
|
||||
|
||||
+------------------------+---------+
|
||||
| text | version |
|
||||
+------------------------+---------+
|
||||
| Phone: 123-456-7890 | |
|
||||
| Email: user@domain.com | |
|
||||
| Version 2.1.0 | 2.1.0 |
|
||||
| No pattern here | |
|
||||
+------------------------+---------+
|
||||
|
||||
DROP TABLE regex_test;
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
-- Regular expression function tests
|
||||
|
||||
-- REGEXP_MATCHES function
|
||||
SELECT regexp_like('hello123world', '\d+');
|
||||
|
||||
SELECT regexp_like('no numbers here', '\d+');
|
||||
|
||||
SELECT regexp_like('email@example.com', '[a-zA-Z0-9]+@[a-zA-Z0-9]+\.[a-zA-Z]+');
|
||||
|
||||
-- REGEXP_REPLACE function
|
||||
SELECT REGEXP_REPLACE('hello123world', '\d+', 'XXX');
|
||||
|
||||
SELECT REGEXP_REPLACE('phone: 123-456-7890', '\d{3}-\d{3}-\d{4}', 'XXX-XXX-XXXX');
|
||||
|
||||
SELECT REGEXP_REPLACE(' extra spaces ', '\s+', ' ');
|
||||
|
||||
-- REGEXP_EXTRACT function
|
||||
SELECT REGEXP_EXTRACT('version 1.2.3', '\d+\.\d+\.\d+');
|
||||
|
||||
SELECT REGEXP_EXTRACT('no match here', '\d+\.\d+\.\d+');
|
||||
|
||||
-- Test with ~ operator (regex match)
|
||||
SELECT 'hello123' ~ '\d+';
|
||||
|
||||
SELECT 'hello world' ~ '\d+';
|
||||
|
||||
SELECT 'email@example.com' ~ '[a-zA-Z0-9]+@[a-zA-Z0-9]+\.[a-zA-Z]+';
|
||||
|
||||
-- Test with table data
|
||||
CREATE TABLE regex_test("text" VARCHAR, ts TIMESTAMP TIME INDEX);
|
||||
|
||||
INSERT INTO regex_test VALUES
|
||||
('Phone: 123-456-7890', 1000),
|
||||
('Email: user@domain.com', 2000),
|
||||
('Version 2.1.0', 3000),
|
||||
('No pattern here', 4000);
|
||||
|
||||
SELECT "text", REGEXP_EXTRACT("text", '\d{3}-\d{3}-\d{4}') as phone FROM regex_test ORDER BY ts;
|
||||
|
||||
SELECT "text", REGEXP_EXTRACT("text", '[a-zA-Z0-9]+@[a-zA-Z0-9]+\.[a-zA-Z]+') as email FROM regex_test ORDER BY ts;
|
||||
|
||||
SELECT "text", REGEXP_EXTRACT("text", '\d+\.\d+\.\d+') as version FROM regex_test ORDER BY ts;
|
||||
|
||||
DROP TABLE regex_test;
|
||||
@@ -0,0 +1,217 @@
|
||||
-- String REPEAT function tests
|
||||
-- Basic REPEAT function
|
||||
SELECT REPEAT('hello', 3);
|
||||
|
||||
+--------------------------------+
|
||||
| repeat(Utf8("hello"),Int64(3)) |
|
||||
+--------------------------------+
|
||||
| hellohellohello |
|
||||
+--------------------------------+
|
||||
|
||||
SELECT REPEAT('a', 5);
|
||||
|
||||
+----------------------------+
|
||||
| repeat(Utf8("a"),Int64(5)) |
|
||||
+----------------------------+
|
||||
| aaaaa |
|
||||
+----------------------------+
|
||||
|
||||
SELECT REPEAT('', 3);
|
||||
|
||||
+---------------------------+
|
||||
| repeat(Utf8(""),Int64(3)) |
|
||||
+---------------------------+
|
||||
| |
|
||||
+---------------------------+
|
||||
|
||||
SELECT REPEAT('test', 0);
|
||||
|
||||
+-------------------------------+
|
||||
| repeat(Utf8("test"),Int64(0)) |
|
||||
+-------------------------------+
|
||||
| |
|
||||
+-------------------------------+
|
||||
|
||||
SELECT REPEAT('test', 1);
|
||||
|
||||
+-------------------------------+
|
||||
| repeat(Utf8("test"),Int64(1)) |
|
||||
+-------------------------------+
|
||||
| test |
|
||||
+-------------------------------+
|
||||
|
||||
-- REPEAT with NULL values
|
||||
SELECT REPEAT(NULL, 3);
|
||||
|
||||
+-----------------------+
|
||||
| repeat(NULL,Int64(3)) |
|
||||
+-----------------------+
|
||||
| |
|
||||
+-----------------------+
|
||||
|
||||
SELECT REPEAT('hello', NULL);
|
||||
|
||||
+----------------------------+
|
||||
| repeat(Utf8("hello"),NULL) |
|
||||
+----------------------------+
|
||||
| |
|
||||
+----------------------------+
|
||||
|
||||
-- REPEAT with negative numbers
|
||||
SELECT REPEAT('hello', -1);
|
||||
|
||||
+---------------------------------+
|
||||
| repeat(Utf8("hello"),Int64(-1)) |
|
||||
+---------------------------------+
|
||||
| |
|
||||
+---------------------------------+
|
||||
|
||||
-- REPEAT with special characters
|
||||
SELECT REPEAT('*', 10);
|
||||
|
||||
+-----------------------------+
|
||||
| repeat(Utf8("*"),Int64(10)) |
|
||||
+-----------------------------+
|
||||
| ********** |
|
||||
+-----------------------------+
|
||||
|
||||
SELECT REPEAT('-=', 5);
|
||||
|
||||
+-----------------------------+
|
||||
| repeat(Utf8("-="),Int64(5)) |
|
||||
+-----------------------------+
|
||||
| -=-=-=-=-= |
|
||||
+-----------------------------+
|
||||
|
||||
SELECT REPEAT('!@#', 3);
|
||||
|
||||
+------------------------------+
|
||||
| repeat(Utf8("!@#"),Int64(3)) |
|
||||
+------------------------------+
|
||||
| !@#!@#!@# |
|
||||
+------------------------------+
|
||||
|
||||
-- Test with table data
|
||||
CREATE TABLE repeat_test(s VARCHAR, n INTEGER, ts TIMESTAMP TIME INDEX);
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
INSERT INTO repeat_test VALUES
|
||||
('hello', 2, 1000),
|
||||
('*', 5, 2000),
|
||||
('test', 0, 3000),
|
||||
('a', 10, 4000),
|
||||
(NULL, 3, 5000),
|
||||
('hi', NULL, 6000);
|
||||
|
||||
Affected Rows: 6
|
||||
|
||||
SELECT s, n, REPEAT(s, n) FROM repeat_test ORDER BY ts;
|
||||
|
||||
+-------+----+-------------------------------------+
|
||||
| s | n | repeat(repeat_test.s,repeat_test.n) |
|
||||
+-------+----+-------------------------------------+
|
||||
| hello | 2 | hellohello |
|
||||
| * | 5 | ***** |
|
||||
| test | 0 | |
|
||||
| a | 10 | aaaaaaaaaa |
|
||||
| | 3 | |
|
||||
| hi | | |
|
||||
+-------+----+-------------------------------------+
|
||||
|
||||
-- Unicode REPEAT
|
||||
SELECT REPEAT('世', 3);
|
||||
|
||||
+-----------------------------+
|
||||
| repeat(Utf8("世"),Int64(3)) |
|
||||
+-----------------------------+
|
||||
| 世世世 |
|
||||
+-----------------------------+
|
||||
|
||||
SELECT REPEAT('🚀', 5);
|
||||
|
||||
+-----------------------------+
|
||||
| repeat(Utf8("🚀"),Int64(5)) |
|
||||
+-----------------------------+
|
||||
| 🚀🚀🚀🚀🚀 |
|
||||
+-----------------------------+
|
||||
|
||||
SELECT REPEAT('café', 2);
|
||||
|
||||
+-------------------------------+
|
||||
| repeat(Utf8("café"),Int64(2)) |
|
||||
+-------------------------------+
|
||||
| cafécafé |
|
||||
+-------------------------------+
|
||||
|
||||
-- REPEAT with spaces and formatting
|
||||
SELECT REPEAT(' ', 10);
|
||||
|
||||
+-----------------------------+
|
||||
| repeat(Utf8(" "),Int64(10)) |
|
||||
+-----------------------------+
|
||||
| |
|
||||
+-----------------------------+
|
||||
|
||||
SELECT REPEAT('\t', 3);
|
||||
|
||||
+-----------------------------+
|
||||
| repeat(Utf8("\t"),Int64(3)) |
|
||||
+-----------------------------+
|
||||
| \t\t\t |
|
||||
+-----------------------------+
|
||||
|
||||
SELECT CONCAT('Start', REPEAT('-', 10), 'End');
|
||||
|
||||
+---------------------------------------------------------------+
|
||||
| concat(Utf8("Start"),repeat(Utf8("-"),Int64(10)),Utf8("End")) |
|
||||
+---------------------------------------------------------------+
|
||||
| Start----------End |
|
||||
+---------------------------------------------------------------+
|
||||
|
||||
-- Large REPEAT operations
|
||||
SELECT LENGTH(REPEAT('a', 100));
|
||||
|
||||
+---------------------------------------+
|
||||
| length(repeat(Utf8("a"), Int64(100))) |
|
||||
+---------------------------------------+
|
||||
| 100 |
|
||||
+---------------------------------------+
|
||||
|
||||
SELECT LENGTH(REPEAT('ab', 50));
|
||||
|
||||
+---------------------------------------+
|
||||
| length(repeat(Utf8("ab"), Int64(50))) |
|
||||
+---------------------------------------+
|
||||
| 100 |
|
||||
+---------------------------------------+
|
||||
|
||||
-- Combining REPEAT with other functions
|
||||
SELECT UPPER(REPEAT('hello', 3));
|
||||
|
||||
+---------------------------------------+
|
||||
| upper(repeat(Utf8("hello"),Int64(3))) |
|
||||
+---------------------------------------+
|
||||
| HELLOHELLOHELLO |
|
||||
+---------------------------------------+
|
||||
|
||||
SELECT REPEAT(UPPER('hello'), 2);
|
||||
|
||||
+---------------------------------------+
|
||||
| repeat(upper(Utf8("hello")),Int64(2)) |
|
||||
+---------------------------------------+
|
||||
| HELLOHELLO |
|
||||
+---------------------------------------+
|
||||
|
||||
SELECT REVERSE(REPEAT('abc', 3));
|
||||
|
||||
+---------------------------------------+
|
||||
| reverse(repeat(Utf8("abc"),Int64(3))) |
|
||||
+---------------------------------------+
|
||||
| cbacbacba |
|
||||
+---------------------------------------+
|
||||
|
||||
DROP TABLE repeat_test;
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
-- String REPEAT function tests
|
||||
|
||||
-- Basic REPEAT function
|
||||
SELECT REPEAT('hello', 3);
|
||||
|
||||
SELECT REPEAT('a', 5);
|
||||
|
||||
SELECT REPEAT('', 3);
|
||||
|
||||
SELECT REPEAT('test', 0);
|
||||
|
||||
SELECT REPEAT('test', 1);
|
||||
|
||||
-- REPEAT with NULL values
|
||||
SELECT REPEAT(NULL, 3);
|
||||
|
||||
SELECT REPEAT('hello', NULL);
|
||||
|
||||
-- REPEAT with negative numbers
|
||||
SELECT REPEAT('hello', -1);
|
||||
|
||||
-- REPEAT with special characters
|
||||
SELECT REPEAT('*', 10);
|
||||
|
||||
SELECT REPEAT('-=', 5);
|
||||
|
||||
SELECT REPEAT('!@#', 3);
|
||||
|
||||
-- Test with table data
|
||||
CREATE TABLE repeat_test(s VARCHAR, n INTEGER, ts TIMESTAMP TIME INDEX);
|
||||
|
||||
INSERT INTO repeat_test VALUES
|
||||
('hello', 2, 1000),
|
||||
('*', 5, 2000),
|
||||
('test', 0, 3000),
|
||||
('a', 10, 4000),
|
||||
(NULL, 3, 5000),
|
||||
('hi', NULL, 6000);
|
||||
|
||||
SELECT s, n, REPEAT(s, n) FROM repeat_test ORDER BY ts;
|
||||
|
||||
-- Unicode REPEAT
|
||||
SELECT REPEAT('世', 3);
|
||||
|
||||
SELECT REPEAT('🚀', 5);
|
||||
|
||||
SELECT REPEAT('café', 2);
|
||||
|
||||
-- REPEAT with spaces and formatting
|
||||
SELECT REPEAT(' ', 10);
|
||||
|
||||
SELECT REPEAT('\t', 3);
|
||||
|
||||
SELECT CONCAT('Start', REPEAT('-', 10), 'End');
|
||||
|
||||
-- Large REPEAT operations
|
||||
SELECT LENGTH(REPEAT('a', 100));
|
||||
|
||||
SELECT LENGTH(REPEAT('ab', 50));
|
||||
|
||||
-- Combining REPEAT with other functions
|
||||
SELECT UPPER(REPEAT('hello', 3));
|
||||
|
||||
SELECT REPEAT(UPPER('hello'), 2);
|
||||
|
||||
SELECT REVERSE(REPEAT('abc', 3));
|
||||
|
||||
DROP TABLE repeat_test;
|
||||
@@ -0,0 +1,180 @@
|
||||
-- String REPLACE function tests
|
||||
-- Basic REPLACE function
|
||||
SELECT REPLACE('hello world', 'world', 'universe');
|
||||
|
||||
+-------------------------------------------------------------+
|
||||
| replace(Utf8("hello world"),Utf8("world"),Utf8("universe")) |
|
||||
+-------------------------------------------------------------+
|
||||
| hello universe |
|
||||
+-------------------------------------------------------------+
|
||||
|
||||
SELECT REPLACE('hello world', 'xyz', 'abc');
|
||||
|
||||
+------------------------------------------------------+
|
||||
| replace(Utf8("hello world"),Utf8("xyz"),Utf8("abc")) |
|
||||
+------------------------------------------------------+
|
||||
| hello world |
|
||||
+------------------------------------------------------+
|
||||
|
||||
SELECT REPLACE('hello hello hello', 'hello', 'hi');
|
||||
|
||||
+-------------------------------------------------------------+
|
||||
| replace(Utf8("hello hello hello"),Utf8("hello"),Utf8("hi")) |
|
||||
+-------------------------------------------------------------+
|
||||
| hi hi hi |
|
||||
+-------------------------------------------------------------+
|
||||
|
||||
-- REPLACE with empty strings
|
||||
SELECT REPLACE('hello world', 'world', '');
|
||||
|
||||
+-----------------------------------------------------+
|
||||
| replace(Utf8("hello world"),Utf8("world"),Utf8("")) |
|
||||
+-----------------------------------------------------+
|
||||
| hello |
|
||||
+-----------------------------------------------------+
|
||||
|
||||
SELECT REPLACE('hello world', '', 'xyz');
|
||||
|
||||
+---------------------------------------------------+
|
||||
| replace(Utf8("hello world"),Utf8(""),Utf8("xyz")) |
|
||||
+---------------------------------------------------+
|
||||
| xyzhxyzexyzlxyzlxyzoxyz xyzwxyzoxyzrxyzlxyzdxyz |
|
||||
+---------------------------------------------------+
|
||||
|
||||
SELECT REPLACE('', 'xyz', 'abc');
|
||||
|
||||
+-------------------------------------------+
|
||||
| replace(Utf8(""),Utf8("xyz"),Utf8("abc")) |
|
||||
+-------------------------------------------+
|
||||
| |
|
||||
+-------------------------------------------+
|
||||
|
||||
-- Case sensitive replacement
|
||||
SELECT REPLACE('Hello World', 'hello', 'hi');
|
||||
|
||||
+-------------------------------------------------------+
|
||||
| replace(Utf8("Hello World"),Utf8("hello"),Utf8("hi")) |
|
||||
+-------------------------------------------------------+
|
||||
| Hello World |
|
||||
+-------------------------------------------------------+
|
||||
|
||||
SELECT REPLACE('Hello World', 'Hello', 'Hi');
|
||||
|
||||
+-------------------------------------------------------+
|
||||
| replace(Utf8("Hello World"),Utf8("Hello"),Utf8("Hi")) |
|
||||
+-------------------------------------------------------+
|
||||
| Hi World |
|
||||
+-------------------------------------------------------+
|
||||
|
||||
-- NULL handling
|
||||
SELECT REPLACE(NULL, 'world', 'universe');
|
||||
|
||||
+----------------------------------------------+
|
||||
| replace(NULL,Utf8("world"),Utf8("universe")) |
|
||||
+----------------------------------------------+
|
||||
| |
|
||||
+----------------------------------------------+
|
||||
|
||||
SELECT REPLACE('hello world', NULL, 'universe');
|
||||
|
||||
+----------------------------------------------------+
|
||||
| replace(Utf8("hello world"),NULL,Utf8("universe")) |
|
||||
+----------------------------------------------------+
|
||||
| |
|
||||
+----------------------------------------------------+
|
||||
|
||||
SELECT REPLACE('hello world', 'world', NULL);
|
||||
|
||||
+-------------------------------------------------+
|
||||
| replace(Utf8("hello world"),Utf8("world"),NULL) |
|
||||
+-------------------------------------------------+
|
||||
| |
|
||||
+-------------------------------------------------+
|
||||
|
||||
-- Test with table data
|
||||
CREATE TABLE replace_test(s VARCHAR, old_str VARCHAR, new_str VARCHAR, ts TIMESTAMP TIME INDEX);
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
INSERT INTO replace_test VALUES
|
||||
('hello world', 'world', 'universe', 1000),
|
||||
('programming language', 'language', 'paradigm', 2000),
|
||||
('test test test', 'test', 'exam', 3000),
|
||||
('no match here', 'xyz', 'abc', 4000);
|
||||
|
||||
Affected Rows: 4
|
||||
|
||||
SELECT s, old_str, new_str, REPLACE(s, old_str, new_str) FROM replace_test ORDER BY ts;
|
||||
|
||||
+----------------------+----------+----------+-------------------------------------------------------------------+
|
||||
| s | old_str | new_str | replace(replace_test.s,replace_test.old_str,replace_test.new_str) |
|
||||
+----------------------+----------+----------+-------------------------------------------------------------------+
|
||||
| hello world | world | universe | hello universe |
|
||||
| programming language | language | paradigm | programming paradigm |
|
||||
| test test test | test | exam | exam exam exam |
|
||||
| no match here | xyz | abc | no match here |
|
||||
+----------------------+----------+----------+-------------------------------------------------------------------+
|
||||
|
||||
-- Unicode replacement
|
||||
SELECT REPLACE('hello 世界', '世界', 'world');
|
||||
|
||||
+--------------------------------------------------------+
|
||||
| replace(Utf8("hello 世界"),Utf8("世界"),Utf8("world")) |
|
||||
+--------------------------------------------------------+
|
||||
| hello world |
|
||||
+--------------------------------------------------------+
|
||||
|
||||
SELECT REPLACE('café shop', 'é', 'e');
|
||||
|
||||
+------------------------------------------------+
|
||||
| replace(Utf8("café shop"),Utf8("é"),Utf8("e")) |
|
||||
+------------------------------------------------+
|
||||
| cafe shop |
|
||||
+------------------------------------------------+
|
||||
|
||||
SELECT REPLACE('🚀 rocket 🚀', '🚀', '✈️');
|
||||
|
||||
+-----------------------------------------------------+
|
||||
| replace(Utf8("🚀 rocket 🚀"),Utf8("🚀"),Utf8("✈️")) |
|
||||
+-----------------------------------------------------+
|
||||
| ✈️ rocket ✈️ |
|
||||
+-----------------------------------------------------+
|
||||
|
||||
-- Multiple character replacement
|
||||
SELECT REPLACE('hello-world-test', '-', '_');
|
||||
|
||||
+-------------------------------------------------------+
|
||||
| replace(Utf8("hello-world-test"),Utf8("-"),Utf8("_")) |
|
||||
+-------------------------------------------------------+
|
||||
| hello_world_test |
|
||||
+-------------------------------------------------------+
|
||||
|
||||
SELECT REPLACE('abc::def::ghi', '::', '-->');
|
||||
|
||||
+-------------------------------------------------------+
|
||||
| replace(Utf8("abc::def::ghi"),Utf8("::"),Utf8("-->")) |
|
||||
+-------------------------------------------------------+
|
||||
| abc-->def-->ghi |
|
||||
+-------------------------------------------------------+
|
||||
|
||||
-- Overlapping patterns
|
||||
SELECT REPLACE('ababab', 'ab', 'xy');
|
||||
|
||||
+-----------------------------------------------+
|
||||
| replace(Utf8("ababab"),Utf8("ab"),Utf8("xy")) |
|
||||
+-----------------------------------------------+
|
||||
| xyxyxy |
|
||||
+-----------------------------------------------+
|
||||
|
||||
SELECT REPLACE('aaa', 'aa', 'b');
|
||||
|
||||
+-------------------------------------------+
|
||||
| replace(Utf8("aaa"),Utf8("aa"),Utf8("b")) |
|
||||
+-------------------------------------------+
|
||||
| ba |
|
||||
+-------------------------------------------+
|
||||
|
||||
DROP TABLE replace_test;
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
-- String REPLACE function tests
|
||||
|
||||
-- Basic REPLACE function
|
||||
SELECT REPLACE('hello world', 'world', 'universe');
|
||||
|
||||
SELECT REPLACE('hello world', 'xyz', 'abc');
|
||||
|
||||
SELECT REPLACE('hello hello hello', 'hello', 'hi');
|
||||
|
||||
-- REPLACE with empty strings
|
||||
SELECT REPLACE('hello world', 'world', '');
|
||||
|
||||
SELECT REPLACE('hello world', '', 'xyz');
|
||||
|
||||
SELECT REPLACE('', 'xyz', 'abc');
|
||||
|
||||
-- Case sensitive replacement
|
||||
SELECT REPLACE('Hello World', 'hello', 'hi');
|
||||
|
||||
SELECT REPLACE('Hello World', 'Hello', 'Hi');
|
||||
|
||||
-- NULL handling
|
||||
SELECT REPLACE(NULL, 'world', 'universe');
|
||||
|
||||
SELECT REPLACE('hello world', NULL, 'universe');
|
||||
|
||||
SELECT REPLACE('hello world', 'world', NULL);
|
||||
|
||||
-- Test with table data
|
||||
CREATE TABLE replace_test(s VARCHAR, old_str VARCHAR, new_str VARCHAR, ts TIMESTAMP TIME INDEX);
|
||||
|
||||
INSERT INTO replace_test VALUES
|
||||
('hello world', 'world', 'universe', 1000),
|
||||
('programming language', 'language', 'paradigm', 2000),
|
||||
('test test test', 'test', 'exam', 3000),
|
||||
('no match here', 'xyz', 'abc', 4000);
|
||||
|
||||
SELECT s, old_str, new_str, REPLACE(s, old_str, new_str) FROM replace_test ORDER BY ts;
|
||||
|
||||
-- Unicode replacement
|
||||
SELECT REPLACE('hello 世界', '世界', 'world');
|
||||
|
||||
SELECT REPLACE('café shop', 'é', 'e');
|
||||
|
||||
SELECT REPLACE('🚀 rocket 🚀', '🚀', '✈️');
|
||||
|
||||
-- Multiple character replacement
|
||||
SELECT REPLACE('hello-world-test', '-', '_');
|
||||
|
||||
SELECT REPLACE('abc::def::ghi', '::', '-->');
|
||||
|
||||
-- Overlapping patterns
|
||||
SELECT REPLACE('ababab', 'ab', 'xy');
|
||||
|
||||
SELECT REPLACE('aaa', 'aa', 'b');
|
||||
|
||||
DROP TABLE replace_test;
|
||||
@@ -0,0 +1,200 @@
|
||||
-- String REVERSE function tests
|
||||
-- Basic REVERSE function
|
||||
SELECT REVERSE('hello');
|
||||
|
||||
+------------------------+
|
||||
| reverse(Utf8("hello")) |
|
||||
+------------------------+
|
||||
| olleh |
|
||||
+------------------------+
|
||||
|
||||
SELECT REVERSE('world');
|
||||
|
||||
+------------------------+
|
||||
| reverse(Utf8("world")) |
|
||||
+------------------------+
|
||||
| dlrow |
|
||||
+------------------------+
|
||||
|
||||
SELECT REVERSE('');
|
||||
|
||||
+-------------------+
|
||||
| reverse(Utf8("")) |
|
||||
+-------------------+
|
||||
| |
|
||||
+-------------------+
|
||||
|
||||
SELECT REVERSE(NULL);
|
||||
|
||||
+---------------+
|
||||
| reverse(NULL) |
|
||||
+---------------+
|
||||
| |
|
||||
+---------------+
|
||||
|
||||
-- REVERSE with numbers and special characters
|
||||
SELECT REVERSE('12345');
|
||||
|
||||
+------------------------+
|
||||
| reverse(Utf8("12345")) |
|
||||
+------------------------+
|
||||
| 54321 |
|
||||
+------------------------+
|
||||
|
||||
SELECT REVERSE('hello!');
|
||||
|
||||
+-------------------------+
|
||||
| reverse(Utf8("hello!")) |
|
||||
+-------------------------+
|
||||
| !olleh |
|
||||
+-------------------------+
|
||||
|
||||
SELECT REVERSE('a!@#$%b');
|
||||
|
||||
+--------------------------+
|
||||
| reverse(Utf8("a!@#$%b")) |
|
||||
+--------------------------+
|
||||
| b%$#@!a |
|
||||
+--------------------------+
|
||||
|
||||
-- REVERSE with palindromes
|
||||
SELECT REVERSE('radar');
|
||||
|
||||
+------------------------+
|
||||
| reverse(Utf8("radar")) |
|
||||
+------------------------+
|
||||
| radar |
|
||||
+------------------------+
|
||||
|
||||
SELECT REVERSE('madam');
|
||||
|
||||
+------------------------+
|
||||
| reverse(Utf8("madam")) |
|
||||
+------------------------+
|
||||
| madam |
|
||||
+------------------------+
|
||||
|
||||
SELECT REVERSE('racecar');
|
||||
|
||||
+--------------------------+
|
||||
| reverse(Utf8("racecar")) |
|
||||
+--------------------------+
|
||||
| racecar |
|
||||
+--------------------------+
|
||||
|
||||
-- Test with table data
|
||||
CREATE TABLE reverse_test(s VARCHAR, ts TIMESTAMP TIME INDEX);
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
INSERT INTO reverse_test VALUES
|
||||
('hello', 1000),
|
||||
('world', 2000),
|
||||
('12345', 3000),
|
||||
('radar', 4000),
|
||||
('', 5000),
|
||||
(NULL, 6000);
|
||||
|
||||
Affected Rows: 6
|
||||
|
||||
SELECT s, REVERSE(s) FROM reverse_test ORDER BY ts;
|
||||
|
||||
+-------+-------------------------+
|
||||
| s | reverse(reverse_test.s) |
|
||||
+-------+-------------------------+
|
||||
| hello | olleh |
|
||||
| world | dlrow |
|
||||
| 12345 | 54321 |
|
||||
| radar | radar |
|
||||
| | |
|
||||
| | |
|
||||
+-------+-------------------------+
|
||||
|
||||
-- Unicode REVERSE
|
||||
SELECT REVERSE('世界');
|
||||
|
||||
+-----------------------+
|
||||
| reverse(Utf8("世界")) |
|
||||
+-----------------------+
|
||||
| 界世 |
|
||||
+-----------------------+
|
||||
|
||||
SELECT REVERSE('café');
|
||||
|
||||
+-----------------------+
|
||||
| reverse(Utf8("café")) |
|
||||
+-----------------------+
|
||||
| éfac |
|
||||
+-----------------------+
|
||||
|
||||
SELECT REVERSE('🚀🌟');
|
||||
|
||||
+-----------------------+
|
||||
| reverse(Utf8("🚀🌟")) |
|
||||
+-----------------------+
|
||||
| 🌟🚀 |
|
||||
+-----------------------+
|
||||
|
||||
-- REVERSE with spaces
|
||||
SELECT REVERSE('hello world');
|
||||
|
||||
+------------------------------+
|
||||
| reverse(Utf8("hello world")) |
|
||||
+------------------------------+
|
||||
| dlrow olleh |
|
||||
+------------------------------+
|
||||
|
||||
SELECT REVERSE(' spaces ');
|
||||
|
||||
+-----------------------------+
|
||||
| reverse(Utf8(" spaces ")) |
|
||||
+-----------------------------+
|
||||
| secaps |
|
||||
+-----------------------------+
|
||||
|
||||
-- Combining REVERSE with other functions
|
||||
SELECT UPPER(REVERSE('hello'));
|
||||
|
||||
+-------------------------------+
|
||||
| upper(reverse(Utf8("hello"))) |
|
||||
+-------------------------------+
|
||||
| OLLEH |
|
||||
+-------------------------------+
|
||||
|
||||
SELECT REVERSE(UPPER('hello'));
|
||||
|
||||
+-------------------------------+
|
||||
| reverse(upper(Utf8("hello"))) |
|
||||
+-------------------------------+
|
||||
| OLLEH |
|
||||
+-------------------------------+
|
||||
|
||||
SELECT LENGTH(REVERSE('hello world'));
|
||||
|
||||
+--------------------------------------+
|
||||
| length(reverse(Utf8("hello world"))) |
|
||||
+--------------------------------------+
|
||||
| 11 |
|
||||
+--------------------------------------+
|
||||
|
||||
-- Double REVERSE (should return original)
|
||||
SELECT REVERSE(REVERSE('hello world'));
|
||||
|
||||
+---------------------------------------+
|
||||
| reverse(reverse(Utf8("hello world"))) |
|
||||
+---------------------------------------+
|
||||
| hello world |
|
||||
+---------------------------------------+
|
||||
|
||||
SELECT REVERSE(REVERSE('中文测试'));
|
||||
|
||||
+------------------------------------+
|
||||
| reverse(reverse(Utf8("中文测试"))) |
|
||||
+------------------------------------+
|
||||
| 中文测试 |
|
||||
+------------------------------------+
|
||||
|
||||
DROP TABLE reverse_test;
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
-- String REVERSE function tests
|
||||
|
||||
-- Basic REVERSE function
|
||||
SELECT REVERSE('hello');
|
||||
|
||||
SELECT REVERSE('world');
|
||||
|
||||
SELECT REVERSE('');
|
||||
|
||||
SELECT REVERSE(NULL);
|
||||
|
||||
-- REVERSE with numbers and special characters
|
||||
SELECT REVERSE('12345');
|
||||
|
||||
SELECT REVERSE('hello!');
|
||||
|
||||
SELECT REVERSE('a!@#$%b');
|
||||
|
||||
-- REVERSE with palindromes
|
||||
SELECT REVERSE('radar');
|
||||
|
||||
SELECT REVERSE('madam');
|
||||
|
||||
SELECT REVERSE('racecar');
|
||||
|
||||
-- Test with table data
|
||||
CREATE TABLE reverse_test(s VARCHAR, ts TIMESTAMP TIME INDEX);
|
||||
|
||||
INSERT INTO reverse_test VALUES
|
||||
('hello', 1000),
|
||||
('world', 2000),
|
||||
('12345', 3000),
|
||||
('radar', 4000),
|
||||
('', 5000),
|
||||
(NULL, 6000);
|
||||
|
||||
SELECT s, REVERSE(s) FROM reverse_test ORDER BY ts;
|
||||
|
||||
-- Unicode REVERSE
|
||||
SELECT REVERSE('世界');
|
||||
|
||||
SELECT REVERSE('café');
|
||||
|
||||
SELECT REVERSE('🚀🌟');
|
||||
|
||||
-- REVERSE with spaces
|
||||
SELECT REVERSE('hello world');
|
||||
|
||||
SELECT REVERSE(' spaces ');
|
||||
|
||||
-- Combining REVERSE with other functions
|
||||
SELECT UPPER(REVERSE('hello'));
|
||||
|
||||
SELECT REVERSE(UPPER('hello'));
|
||||
|
||||
SELECT LENGTH(REVERSE('hello world'));
|
||||
|
||||
-- Double REVERSE (should return original)
|
||||
SELECT REVERSE(REVERSE('hello world'));
|
||||
|
||||
SELECT REVERSE(REVERSE('中文测试'));
|
||||
|
||||
DROP TABLE reverse_test;
|
||||
@@ -0,0 +1,213 @@
|
||||
-- Migrated from DuckDB test: test/sql/function/string/test_string_split.test
|
||||
-- String split function tests
|
||||
-- Test basic string_split functionality
|
||||
SELECT string_to_array(NULL, NULL);
|
||||
|
||||
+----------------------------+
|
||||
| string_to_array(NULL,NULL) |
|
||||
+----------------------------+
|
||||
| |
|
||||
+----------------------------+
|
||||
|
||||
SELECT string_to_array('hello world', ' ');
|
||||
|
||||
+------------------------------------------------+
|
||||
| string_to_array(Utf8("hello world"),Utf8(" ")) |
|
||||
+------------------------------------------------+
|
||||
| [hello, world] |
|
||||
+------------------------------------------------+
|
||||
|
||||
SELECT string_to_array(NULL, ' ');
|
||||
|
||||
+---------------------------------+
|
||||
| string_to_array(NULL,Utf8(" ")) |
|
||||
+---------------------------------+
|
||||
| |
|
||||
+---------------------------------+
|
||||
|
||||
SELECT string_to_array('a b c', NULL);
|
||||
|
||||
+-------------------------------------+
|
||||
| string_to_array(Utf8("a b c"),NULL) |
|
||||
+-------------------------------------+
|
||||
| [a, , b, , c] |
|
||||
+-------------------------------------+
|
||||
|
||||
SELECT string_to_array('a b c', ' ');
|
||||
|
||||
+------------------------------------------+
|
||||
| string_to_array(Utf8("a b c"),Utf8(" ")) |
|
||||
+------------------------------------------+
|
||||
| [a, b, c] |
|
||||
+------------------------------------------+
|
||||
|
||||
-- Test with table data
|
||||
CREATE TABLE split_test(s VARCHAR, ts TIMESTAMP TIME INDEX);
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
INSERT INTO split_test VALUES
|
||||
('hello,world,test', 1000),
|
||||
('a|b|c|d', 2000),
|
||||
('no-separator', 3000),
|
||||
('', 4000),
|
||||
(NULL, 5000);
|
||||
|
||||
Affected Rows: 5
|
||||
|
||||
-- Test splitting with different separators
|
||||
SELECT s, string_to_array(s, ',') FROM split_test ORDER BY ts;
|
||||
|
||||
+------------------+-----------------------------------------+
|
||||
| s | string_to_array(split_test.s,Utf8(",")) |
|
||||
+------------------+-----------------------------------------+
|
||||
| hello,world,test | [hello, world, test] |
|
||||
| a|b|c|d | [a|b|c|d] |
|
||||
| no-separator | [no-separator] |
|
||||
| | [] |
|
||||
| | |
|
||||
+------------------+-----------------------------------------+
|
||||
|
||||
SELECT s, string_to_array(s, '|') FROM split_test ORDER BY ts;
|
||||
|
||||
+------------------+-----------------------------------------+
|
||||
| s | string_to_array(split_test.s,Utf8("|")) |
|
||||
+------------------+-----------------------------------------+
|
||||
| hello,world,test | [hello,world,test] |
|
||||
| a|b|c|d | [a, b, c, d] |
|
||||
| no-separator | [no-separator] |
|
||||
| | [] |
|
||||
| | |
|
||||
+------------------+-----------------------------------------+
|
||||
|
||||
SELECT s, string_to_array(s, '-') FROM split_test ORDER BY ts;
|
||||
|
||||
+------------------+-----------------------------------------+
|
||||
| s | string_to_array(split_test.s,Utf8("-")) |
|
||||
+------------------+-----------------------------------------+
|
||||
| hello,world,test | [hello,world,test] |
|
||||
| a|b|c|d | [a|b|c|d] |
|
||||
| no-separator | [no, separator] |
|
||||
| | [] |
|
||||
| | |
|
||||
+------------------+-----------------------------------------+
|
||||
|
||||
-- Test splitting with multi-character separator
|
||||
CREATE TABLE multi_sep_test(s VARCHAR, ts TIMESTAMP TIME INDEX);
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
INSERT INTO multi_sep_test VALUES
|
||||
('hello::world::test', 1000),
|
||||
('a---b---c', 2000),
|
||||
('single', 3000);
|
||||
|
||||
Affected Rows: 3
|
||||
|
||||
SELECT s, string_to_array(s, '::') FROM multi_sep_test ORDER BY ts;
|
||||
|
||||
+--------------------+----------------------------------------------+
|
||||
| s | string_to_array(multi_sep_test.s,Utf8("::")) |
|
||||
+--------------------+----------------------------------------------+
|
||||
| hello::world::test | [hello, world, test] |
|
||||
| a---b---c | [a---b---c] |
|
||||
| single | [single] |
|
||||
+--------------------+----------------------------------------------+
|
||||
|
||||
SELECT s, string_to_array(s, '---') FROM multi_sep_test ORDER BY ts;
|
||||
|
||||
+--------------------+-----------------------------------------------+
|
||||
| s | string_to_array(multi_sep_test.s,Utf8("---")) |
|
||||
+--------------------+-----------------------------------------------+
|
||||
| hello::world::test | [hello::world::test] |
|
||||
| a---b---c | [a, b, c] |
|
||||
| single | [single] |
|
||||
+--------------------+-----------------------------------------------+
|
||||
|
||||
-- Test with Unicode separators
|
||||
CREATE TABLE unicode_split_test(s VARCHAR, ts TIMESTAMP TIME INDEX);
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
INSERT INTO unicode_split_test VALUES
|
||||
('hello世world世test', 1000),
|
||||
('a🦆b🦆c', 2000);
|
||||
|
||||
Affected Rows: 2
|
||||
|
||||
SELECT s, string_to_array(s, '世') FROM unicode_split_test ORDER BY ts;
|
||||
|
||||
+--------------------+--------------------------------------------------+
|
||||
| s | string_to_array(unicode_split_test.s,Utf8("世")) |
|
||||
+--------------------+--------------------------------------------------+
|
||||
| hello世world世test | [hello, world, test] |
|
||||
| a🦆b🦆c | [a🦆b🦆c] |
|
||||
+--------------------+--------------------------------------------------+
|
||||
|
||||
SELECT s, string_to_array(s, '🦆') FROM unicode_split_test ORDER BY ts;
|
||||
|
||||
+--------------------+--------------------------------------------------+
|
||||
| s | string_to_array(unicode_split_test.s,Utf8("🦆")) |
|
||||
+--------------------+--------------------------------------------------+
|
||||
| hello世world世test | [hello世world世test] |
|
||||
| a🦆b🦆c | [a, b, c] |
|
||||
+--------------------+--------------------------------------------------+
|
||||
|
||||
-- Test edge cases
|
||||
-- Empty string
|
||||
SELECT string_to_array('', ',');
|
||||
|
||||
+-------------------------------------+
|
||||
| string_to_array(Utf8(""),Utf8(",")) |
|
||||
+-------------------------------------+
|
||||
| [] |
|
||||
+-------------------------------------+
|
||||
|
||||
-- Empty separator
|
||||
SELECT string_to_array('hello', '');
|
||||
|
||||
+-----------------------------------------+
|
||||
| string_to_array(Utf8("hello"),Utf8("")) |
|
||||
+-----------------------------------------+
|
||||
| [hello] |
|
||||
+-----------------------------------------+
|
||||
|
||||
-- Multiple consecutive separators
|
||||
SELECT string_to_array(',,hello,,world,,', ',');
|
||||
|
||||
+-----------------------------------------------------+
|
||||
| string_to_array(Utf8(",,hello,,world,,"),Utf8(",")) |
|
||||
+-----------------------------------------------------+
|
||||
| [, , hello, , world, , ] |
|
||||
+-----------------------------------------------------+
|
||||
|
||||
-- Trailing separator
|
||||
SELECT string_to_array('hello,', ',');
|
||||
|
||||
+-------------------------------------------+
|
||||
| string_to_array(Utf8("hello,"),Utf8(",")) |
|
||||
+-------------------------------------------+
|
||||
| [hello, ] |
|
||||
+-------------------------------------------+
|
||||
|
||||
-- Leading separator
|
||||
SELECT string_to_array(',hello', ',');
|
||||
|
||||
+-------------------------------------------+
|
||||
| string_to_array(Utf8(",hello"),Utf8(",")) |
|
||||
+-------------------------------------------+
|
||||
| [, hello] |
|
||||
+-------------------------------------------+
|
||||
|
||||
DROP TABLE split_test;
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
DROP TABLE multi_sep_test;
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
DROP TABLE unicode_split_test;
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
-- Migrated from DuckDB test: test/sql/function/string/test_string_split.test
|
||||
-- String split function tests
|
||||
|
||||
-- Test basic string_split functionality
|
||||
SELECT string_to_array(NULL, NULL);
|
||||
|
||||
SELECT string_to_array('hello world', ' ');
|
||||
|
||||
SELECT string_to_array(NULL, ' ');
|
||||
|
||||
SELECT string_to_array('a b c', NULL);
|
||||
|
||||
SELECT string_to_array('a b c', ' ');
|
||||
|
||||
-- Test with table data
|
||||
CREATE TABLE split_test(s VARCHAR, ts TIMESTAMP TIME INDEX);
|
||||
|
||||
INSERT INTO split_test VALUES
|
||||
('hello,world,test', 1000),
|
||||
('a|b|c|d', 2000),
|
||||
('no-separator', 3000),
|
||||
('', 4000),
|
||||
(NULL, 5000);
|
||||
|
||||
-- Test splitting with different separators
|
||||
SELECT s, string_to_array(s, ',') FROM split_test ORDER BY ts;
|
||||
|
||||
SELECT s, string_to_array(s, '|') FROM split_test ORDER BY ts;
|
||||
|
||||
SELECT s, string_to_array(s, '-') FROM split_test ORDER BY ts;
|
||||
|
||||
-- Test splitting with multi-character separator
|
||||
CREATE TABLE multi_sep_test(s VARCHAR, ts TIMESTAMP TIME INDEX);
|
||||
|
||||
INSERT INTO multi_sep_test VALUES
|
||||
('hello::world::test', 1000),
|
||||
('a---b---c', 2000),
|
||||
('single', 3000);
|
||||
|
||||
SELECT s, string_to_array(s, '::') FROM multi_sep_test ORDER BY ts;
|
||||
|
||||
SELECT s, string_to_array(s, '---') FROM multi_sep_test ORDER BY ts;
|
||||
|
||||
-- Test with Unicode separators
|
||||
CREATE TABLE unicode_split_test(s VARCHAR, ts TIMESTAMP TIME INDEX);
|
||||
|
||||
INSERT INTO unicode_split_test VALUES
|
||||
('hello世world世test', 1000),
|
||||
('a🦆b🦆c', 2000);
|
||||
|
||||
SELECT s, string_to_array(s, '世') FROM unicode_split_test ORDER BY ts;
|
||||
|
||||
SELECT s, string_to_array(s, '🦆') FROM unicode_split_test ORDER BY ts;
|
||||
|
||||
-- Test edge cases
|
||||
-- Empty string
|
||||
SELECT string_to_array('', ',');
|
||||
|
||||
-- Empty separator
|
||||
SELECT string_to_array('hello', '');
|
||||
|
||||
-- Multiple consecutive separators
|
||||
SELECT string_to_array(',,hello,,world,,', ',');
|
||||
|
||||
-- Trailing separator
|
||||
SELECT string_to_array('hello,', ',');
|
||||
|
||||
-- Leading separator
|
||||
SELECT string_to_array(',hello', ',');
|
||||
|
||||
DROP TABLE split_test;
|
||||
|
||||
DROP TABLE multi_sep_test;
|
||||
|
||||
DROP TABLE unicode_split_test;
|
||||
@@ -0,0 +1,173 @@
|
||||
-- Migrated from DuckDB test: test/sql/function/string/test_substring.test
|
||||
-- Substring function tests
|
||||
CREATE TABLE strings(s VARCHAR, "off" INTEGER, length INTEGER, ts TIMESTAMP TIME INDEX);
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
INSERT INTO strings VALUES
|
||||
('hello', 1, 2, 1000),
|
||||
('world', 2, 3, 2000),
|
||||
('b', 1, 1, 3000),
|
||||
(NULL, 2, 2, 4000);
|
||||
|
||||
Affected Rows: 4
|
||||
|
||||
-- Test zero length
|
||||
SELECT SUBSTRING('🦆ab', 1, 0), SUBSTRING('abc', 1, 0);
|
||||
|
||||
+----------------------------------------+---------------------------------------+
|
||||
| substr(Utf8("🦆ab"),Int64(1),Int64(0)) | substr(Utf8("abc"),Int64(1),Int64(0)) |
|
||||
+----------------------------------------+---------------------------------------+
|
||||
| | |
|
||||
+----------------------------------------+---------------------------------------+
|
||||
|
||||
-- Normal substring with constant offset/length
|
||||
SELECT SUBSTRING(s, 1, 2) FROM strings ORDER BY ts;
|
||||
|
||||
+-------------------------------------+
|
||||
| substr(strings.s,Int64(1),Int64(2)) |
|
||||
+-------------------------------------+
|
||||
| he |
|
||||
| wo |
|
||||
| b |
|
||||
| |
|
||||
+-------------------------------------+
|
||||
|
||||
-- Substring out of range
|
||||
SELECT SUBSTRING(s, 2, 2) FROM strings ORDER BY ts;
|
||||
|
||||
+-------------------------------------+
|
||||
| substr(strings.s,Int64(2),Int64(2)) |
|
||||
+-------------------------------------+
|
||||
| el |
|
||||
| or |
|
||||
| |
|
||||
| |
|
||||
+-------------------------------------+
|
||||
|
||||
-- Variable length offset/length
|
||||
SELECT SUBSTRING(s, "off", "length") FROM strings ORDER BY ts;
|
||||
|
||||
+----------------------------------------------+
|
||||
| substr(strings.s,strings.off,strings.length) |
|
||||
+----------------------------------------------+
|
||||
| he |
|
||||
| orl |
|
||||
| b |
|
||||
| |
|
||||
+----------------------------------------------+
|
||||
|
||||
SELECT SUBSTRING(s, "off", 2) FROM strings ORDER BY ts;
|
||||
|
||||
+----------------------------------------+
|
||||
| substr(strings.s,strings.off,Int64(2)) |
|
||||
+----------------------------------------+
|
||||
| he |
|
||||
| or |
|
||||
| b |
|
||||
| |
|
||||
+----------------------------------------+
|
||||
|
||||
SELECT SUBSTRING(s, 1, length) FROM strings ORDER BY ts;
|
||||
|
||||
+-------------------------------------------+
|
||||
| substr(strings.s,Int64(1),strings.length) |
|
||||
+-------------------------------------------+
|
||||
| he |
|
||||
| wor |
|
||||
| b |
|
||||
| |
|
||||
+-------------------------------------------+
|
||||
|
||||
SELECT SUBSTRING('hello', "off", length) FROM strings ORDER BY ts;
|
||||
|
||||
+--------------------------------------------------+
|
||||
| substr(Utf8("hello"),strings.off,strings.length) |
|
||||
+--------------------------------------------------+
|
||||
| he |
|
||||
| ell |
|
||||
| h |
|
||||
| el |
|
||||
+--------------------------------------------------+
|
||||
|
||||
-- Test with NULL values
|
||||
SELECT SUBSTRING(NULL, "off", length) FROM strings ORDER BY ts;
|
||||
|
||||
+-----------------------------------------+
|
||||
| substr(NULL,strings.off,strings.length) |
|
||||
+-----------------------------------------+
|
||||
| |
|
||||
| |
|
||||
| |
|
||||
| |
|
||||
+-----------------------------------------+
|
||||
|
||||
SELECT SUBSTRING(s, NULL, length) FROM strings ORDER BY ts;
|
||||
|
||||
+---------------------------------------+
|
||||
| substr(strings.s,NULL,strings.length) |
|
||||
+---------------------------------------+
|
||||
| |
|
||||
| |
|
||||
| |
|
||||
| |
|
||||
+---------------------------------------+
|
||||
|
||||
SELECT SUBSTRING(s, "off", NULL) FROM strings ORDER BY ts;
|
||||
|
||||
+------------------------------------+
|
||||
| substr(strings.s,strings.off,NULL) |
|
||||
+------------------------------------+
|
||||
| |
|
||||
| |
|
||||
| |
|
||||
| |
|
||||
+------------------------------------+
|
||||
|
||||
-- Test negative offsets
|
||||
SELECT SUBSTRING('hello', -1, 3);
|
||||
|
||||
+------------------------------------------+
|
||||
| substr(Utf8("hello"),Int64(-1),Int64(3)) |
|
||||
+------------------------------------------+
|
||||
| h |
|
||||
+------------------------------------------+
|
||||
|
||||
SELECT SUBSTRING('hello', 0, 3);
|
||||
|
||||
+-----------------------------------------+
|
||||
| substr(Utf8("hello"),Int64(0),Int64(3)) |
|
||||
+-----------------------------------------+
|
||||
| he |
|
||||
+-----------------------------------------+
|
||||
|
||||
-- Test with Unicode characters
|
||||
CREATE TABLE unicode_strings(s VARCHAR, ts TIMESTAMP TIME INDEX);
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
INSERT INTO unicode_strings VALUES
|
||||
('Hello 世界', 1000),
|
||||
('🦆🦀🐧', 2000),
|
||||
('café', 3000);
|
||||
|
||||
Affected Rows: 3
|
||||
|
||||
SELECT s, SUBSTRING(s, 1, 5), SUBSTRING(s, 7, 2) FROM unicode_strings ORDER BY ts;
|
||||
|
||||
+------------+---------------------------------------------+---------------------------------------------+
|
||||
| s | substr(unicode_strings.s,Int64(1),Int64(5)) | substr(unicode_strings.s,Int64(7),Int64(2)) |
|
||||
+------------+---------------------------------------------+---------------------------------------------+
|
||||
| Hello 世界 | Hello | 世界 |
|
||||
| 🦆🦀🐧 | 🦆🦀🐧 | |
|
||||
| café | café | |
|
||||
+------------+---------------------------------------------+---------------------------------------------+
|
||||
|
||||
DROP TABLE strings;
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
DROP TABLE unicode_strings;
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
-- Migrated from DuckDB test: test/sql/function/string/test_substring.test
|
||||
-- Substring function tests
|
||||
|
||||
CREATE TABLE strings(s VARCHAR, "off" INTEGER, length INTEGER, ts TIMESTAMP TIME INDEX);
|
||||
|
||||
INSERT INTO strings VALUES
|
||||
('hello', 1, 2, 1000),
|
||||
('world', 2, 3, 2000),
|
||||
('b', 1, 1, 3000),
|
||||
(NULL, 2, 2, 4000);
|
||||
|
||||
-- Test zero length
|
||||
SELECT SUBSTRING('🦆ab', 1, 0), SUBSTRING('abc', 1, 0);
|
||||
|
||||
-- Normal substring with constant offset/length
|
||||
SELECT SUBSTRING(s, 1, 2) FROM strings ORDER BY ts;
|
||||
|
||||
-- Substring out of range
|
||||
SELECT SUBSTRING(s, 2, 2) FROM strings ORDER BY ts;
|
||||
|
||||
-- Variable length offset/length
|
||||
SELECT SUBSTRING(s, "off", "length") FROM strings ORDER BY ts;
|
||||
|
||||
SELECT SUBSTRING(s, "off", 2) FROM strings ORDER BY ts;
|
||||
|
||||
SELECT SUBSTRING(s, 1, length) FROM strings ORDER BY ts;
|
||||
|
||||
SELECT SUBSTRING('hello', "off", length) FROM strings ORDER BY ts;
|
||||
|
||||
-- Test with NULL values
|
||||
SELECT SUBSTRING(NULL, "off", length) FROM strings ORDER BY ts;
|
||||
|
||||
SELECT SUBSTRING(s, NULL, length) FROM strings ORDER BY ts;
|
||||
|
||||
SELECT SUBSTRING(s, "off", NULL) FROM strings ORDER BY ts;
|
||||
|
||||
-- Test negative offsets
|
||||
SELECT SUBSTRING('hello', -1, 3);
|
||||
SELECT SUBSTRING('hello', 0, 3);
|
||||
|
||||
-- Test with Unicode characters
|
||||
CREATE TABLE unicode_strings(s VARCHAR, ts TIMESTAMP TIME INDEX);
|
||||
|
||||
INSERT INTO unicode_strings VALUES
|
||||
('Hello 世界', 1000),
|
||||
('🦆🦀🐧', 2000),
|
||||
('café', 3000);
|
||||
|
||||
SELECT s, SUBSTRING(s, 1, 5), SUBSTRING(s, 7, 2) FROM unicode_strings ORDER BY ts;
|
||||
|
||||
DROP TABLE strings;
|
||||
|
||||
DROP TABLE unicode_strings;
|
||||
@@ -0,0 +1,274 @@
|
||||
-- String TRIM and PAD function tests
|
||||
-- TRIM functions
|
||||
SELECT TRIM(' hello world ');
|
||||
|
||||
+--------------------------------+
|
||||
| btrim(Utf8(" hello world ")) |
|
||||
+--------------------------------+
|
||||
| hello world |
|
||||
+--------------------------------+
|
||||
|
||||
SELECT LTRIM(' hello world ');
|
||||
|
||||
+--------------------------------+
|
||||
| ltrim(Utf8(" hello world ")) |
|
||||
+--------------------------------+
|
||||
| hello world |
|
||||
+--------------------------------+
|
||||
|
||||
SELECT RTRIM(' hello world ');
|
||||
|
||||
+--------------------------------+
|
||||
| rtrim(Utf8(" hello world ")) |
|
||||
+--------------------------------+
|
||||
| hello world |
|
||||
+--------------------------------+
|
||||
|
||||
-- TRIM with specific characters
|
||||
SELECT TRIM('x' FROM 'xxxhello worldxxx');
|
||||
|
||||
+--------------------------------------------+
|
||||
| btrim(Utf8("xxxhello worldxxx"),Utf8("x")) |
|
||||
+--------------------------------------------+
|
||||
| hello world |
|
||||
+--------------------------------------------+
|
||||
|
||||
SELECT LTRIM('hello world', 'hel');
|
||||
|
||||
+----------------------------------------+
|
||||
| ltrim(Utf8("hello world"),Utf8("hel")) |
|
||||
+----------------------------------------+
|
||||
| o world |
|
||||
+----------------------------------------+
|
||||
|
||||
SELECT RTRIM('hello world', 'dlr');
|
||||
|
||||
+----------------------------------------+
|
||||
| rtrim(Utf8("hello world"),Utf8("dlr")) |
|
||||
+----------------------------------------+
|
||||
| hello wo |
|
||||
+----------------------------------------+
|
||||
|
||||
-- PAD functions
|
||||
SELECT LPAD('hello', 10, '*');
|
||||
|
||||
+-----------------------------------------+
|
||||
| lpad(Utf8("hello"),Int64(10),Utf8("*")) |
|
||||
+-----------------------------------------+
|
||||
| *****hello |
|
||||
+-----------------------------------------+
|
||||
|
||||
SELECT RPAD('hello', 10, '*');
|
||||
|
||||
+-----------------------------------------+
|
||||
| rpad(Utf8("hello"),Int64(10),Utf8("*")) |
|
||||
+-----------------------------------------+
|
||||
| hello***** |
|
||||
+-----------------------------------------+
|
||||
|
||||
-- Truncate
|
||||
SELECT LPAD('hello', 3, '*');
|
||||
|
||||
+----------------------------------------+
|
||||
| lpad(Utf8("hello"),Int64(3),Utf8("*")) |
|
||||
+----------------------------------------+
|
||||
| hel |
|
||||
+----------------------------------------+
|
||||
|
||||
-- Truncate
|
||||
SELECT RPAD('hello', 3, '*');
|
||||
|
||||
+----------------------------------------+
|
||||
| rpad(Utf8("hello"),Int64(3),Utf8("*")) |
|
||||
+----------------------------------------+
|
||||
| hel |
|
||||
+----------------------------------------+
|
||||
|
||||
-- PAD with multi-character padding
|
||||
SELECT LPAD('test', 10, 'ab');
|
||||
|
||||
+-----------------------------------------+
|
||||
| lpad(Utf8("test"),Int64(10),Utf8("ab")) |
|
||||
+-----------------------------------------+
|
||||
| abababtest |
|
||||
+-----------------------------------------+
|
||||
|
||||
SELECT RPAD('test', 10, 'xy');
|
||||
|
||||
+-----------------------------------------+
|
||||
| rpad(Utf8("test"),Int64(10),Utf8("xy")) |
|
||||
+-----------------------------------------+
|
||||
| testxyxyxy |
|
||||
+-----------------------------------------+
|
||||
|
||||
-- Test with table data
|
||||
CREATE TABLE trim_pad_test(s VARCHAR, ts TIMESTAMP TIME INDEX);
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
INSERT INTO trim_pad_test VALUES
|
||||
(' hello ', 1000),
|
||||
('world ', 2000),
|
||||
(' test', 3000),
|
||||
('no-spaces', 4000),
|
||||
('', 5000),
|
||||
(NULL, 6000);
|
||||
|
||||
Affected Rows: 6
|
||||
|
||||
-- Apply TRIM functions to table data
|
||||
SELECT s, TRIM(s), LTRIM(s), RTRIM(s) FROM trim_pad_test ORDER BY ts;
|
||||
|
||||
+-----------+------------------------+------------------------+------------------------+
|
||||
| s | btrim(trim_pad_test.s) | ltrim(trim_pad_test.s) | rtrim(trim_pad_test.s) |
|
||||
+-----------+------------------------+------------------------+------------------------+
|
||||
| hello | hello | hello | hello |
|
||||
| world | world | world | world |
|
||||
| test | test | test | test |
|
||||
| no-spaces | no-spaces | no-spaces | no-spaces |
|
||||
| | | | |
|
||||
| | | | |
|
||||
+-----------+------------------------+------------------------+------------------------+
|
||||
|
||||
-- Apply PAD functions
|
||||
SELECT s, LPAD(TRIM(s), 15, '-'), RPAD(TRIM(s), 15, '+') FROM trim_pad_test WHERE s IS NOT NULL ORDER BY ts;
|
||||
|
||||
+-----------+--------------------------------------------------+--------------------------------------------------+
|
||||
| s | lpad(btrim(trim_pad_test.s),Int64(15),Utf8("-")) | rpad(btrim(trim_pad_test.s),Int64(15),Utf8("+")) |
|
||||
+-----------+--------------------------------------------------+--------------------------------------------------+
|
||||
| hello | ----------hello | hello++++++++++ |
|
||||
| world | ----------world | world++++++++++ |
|
||||
| test | -----------test | test+++++++++++ |
|
||||
| no-spaces | ------no-spaces | no-spaces++++++ |
|
||||
| | --------------- | +++++++++++++++ |
|
||||
+-----------+--------------------------------------------------+--------------------------------------------------+
|
||||
|
||||
-- Test with Unicode characters
|
||||
SELECT TRIM(' 中文测试 ');
|
||||
|
||||
+-----------------------------+
|
||||
| btrim(Utf8(" 中文测试 ")) |
|
||||
+-----------------------------+
|
||||
| 中文测试 |
|
||||
+-----------------------------+
|
||||
|
||||
SELECT LPAD('🚀', 10, '★');
|
||||
|
||||
+--------------------------------------+
|
||||
| lpad(Utf8("🚀"),Int64(10),Utf8("★")) |
|
||||
+--------------------------------------+
|
||||
| ★★★★★★★★★🚀 |
|
||||
+--------------------------------------+
|
||||
|
||||
SELECT RPAD('café', 8, '•');
|
||||
|
||||
+---------------------------------------+
|
||||
| rpad(Utf8("café"),Int64(8),Utf8("•")) |
|
||||
+---------------------------------------+
|
||||
| café•••• |
|
||||
+---------------------------------------+
|
||||
|
||||
-- Edge cases
|
||||
SELECT TRIM('');
|
||||
|
||||
+-----------------+
|
||||
| btrim(Utf8("")) |
|
||||
+-----------------+
|
||||
| |
|
||||
+-----------------+
|
||||
|
||||
SELECT TRIM(NULL);
|
||||
|
||||
+-------------+
|
||||
| btrim(NULL) |
|
||||
+-------------+
|
||||
| |
|
||||
+-------------+
|
||||
|
||||
SELECT LPAD('', 5, '*');
|
||||
|
||||
+-----------------------------------+
|
||||
| lpad(Utf8(""),Int64(5),Utf8("*")) |
|
||||
+-----------------------------------+
|
||||
| ***** |
|
||||
+-----------------------------------+
|
||||
|
||||
SELECT RPAD('', 5, '*');
|
||||
|
||||
+-----------------------------------+
|
||||
| rpad(Utf8(""),Int64(5),Utf8("*")) |
|
||||
+-----------------------------------+
|
||||
| ***** |
|
||||
+-----------------------------------+
|
||||
|
||||
SELECT LPAD('test', 0, '*');
|
||||
|
||||
+---------------------------------------+
|
||||
| lpad(Utf8("test"),Int64(0),Utf8("*")) |
|
||||
+---------------------------------------+
|
||||
| |
|
||||
+---------------------------------------+
|
||||
|
||||
SELECT RPAD('test', 0, '*');
|
||||
|
||||
+---------------------------------------+
|
||||
| rpad(Utf8("test"),Int64(0),Utf8("*")) |
|
||||
+---------------------------------------+
|
||||
| |
|
||||
+---------------------------------------+
|
||||
|
||||
-- TRIM with various whitespace characters
|
||||
SELECT TRIM('\t\nhello\r\n\t');
|
||||
|
||||
+--------------------------------+
|
||||
| btrim(Utf8("\t\nhello\r\n\t")) |
|
||||
+--------------------------------+
|
||||
| \t\nhello\r\n\t |
|
||||
+--------------------------------+
|
||||
|
||||
SELECT LTRIM('\t\nhello world');
|
||||
|
||||
+--------------------------------+
|
||||
| ltrim(Utf8("\t\nhello world")) |
|
||||
+--------------------------------+
|
||||
| \t\nhello world |
|
||||
+--------------------------------+
|
||||
|
||||
SELECT RTRIM('hello world\r\n');
|
||||
|
||||
+--------------------------------+
|
||||
| rtrim(Utf8("hello world\r\n")) |
|
||||
+--------------------------------+
|
||||
| hello world\r\n |
|
||||
+--------------------------------+
|
||||
|
||||
-- Custom TRIM characters
|
||||
CREATE TABLE custom_trim(s VARCHAR, ts TIMESTAMP TIME INDEX);
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
INSERT INTO custom_trim VALUES
|
||||
('***hello***', 1000),
|
||||
('---world---', 2000),
|
||||
('abcTESTabc', 3000);
|
||||
|
||||
Affected Rows: 3
|
||||
|
||||
SELECT s, TRIM('*' FROM s), TRIM('-' FROM s), TRIM('abc' FROM s) FROM custom_trim ORDER BY ts;
|
||||
|
||||
+-------------+--------------------------------+--------------------------------+----------------------------------+
|
||||
| s | btrim(custom_trim.s,Utf8("*")) | btrim(custom_trim.s,Utf8("-")) | btrim(custom_trim.s,Utf8("abc")) |
|
||||
+-------------+--------------------------------+--------------------------------+----------------------------------+
|
||||
| ***hello*** | hello | ***hello*** | ***hello*** |
|
||||
| ---world--- | ---world--- | world | ---world--- |
|
||||
| abcTESTabc | abcTESTabc | abcTESTabc | TEST |
|
||||
+-------------+--------------------------------+--------------------------------+----------------------------------+
|
||||
|
||||
DROP TABLE trim_pad_test;
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
DROP TABLE custom_trim;
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
-- String TRIM and PAD function tests
|
||||
|
||||
-- TRIM functions
|
||||
SELECT TRIM(' hello world ');
|
||||
|
||||
SELECT LTRIM(' hello world ');
|
||||
|
||||
SELECT RTRIM(' hello world ');
|
||||
|
||||
-- TRIM with specific characters
|
||||
SELECT TRIM('x' FROM 'xxxhello worldxxx');
|
||||
|
||||
SELECT LTRIM('hello world', 'hel');
|
||||
|
||||
SELECT RTRIM('hello world', 'dlr');
|
||||
|
||||
-- PAD functions
|
||||
SELECT LPAD('hello', 10, '*');
|
||||
|
||||
SELECT RPAD('hello', 10, '*');
|
||||
|
||||
-- Truncate
|
||||
SELECT LPAD('hello', 3, '*');
|
||||
|
||||
-- Truncate
|
||||
SELECT RPAD('hello', 3, '*');
|
||||
|
||||
-- PAD with multi-character padding
|
||||
SELECT LPAD('test', 10, 'ab');
|
||||
|
||||
SELECT RPAD('test', 10, 'xy');
|
||||
|
||||
-- Test with table data
|
||||
CREATE TABLE trim_pad_test(s VARCHAR, ts TIMESTAMP TIME INDEX);
|
||||
|
||||
INSERT INTO trim_pad_test VALUES
|
||||
(' hello ', 1000),
|
||||
('world ', 2000),
|
||||
(' test', 3000),
|
||||
('no-spaces', 4000),
|
||||
('', 5000),
|
||||
(NULL, 6000);
|
||||
|
||||
-- Apply TRIM functions to table data
|
||||
SELECT s, TRIM(s), LTRIM(s), RTRIM(s) FROM trim_pad_test ORDER BY ts;
|
||||
|
||||
-- Apply PAD functions
|
||||
SELECT s, LPAD(TRIM(s), 15, '-'), RPAD(TRIM(s), 15, '+') FROM trim_pad_test WHERE s IS NOT NULL ORDER BY ts;
|
||||
|
||||
-- Test with Unicode characters
|
||||
SELECT TRIM(' 中文测试 ');
|
||||
|
||||
SELECT LPAD('🚀', 10, '★');
|
||||
|
||||
SELECT RPAD('café', 8, '•');
|
||||
|
||||
-- Edge cases
|
||||
SELECT TRIM('');
|
||||
|
||||
SELECT TRIM(NULL);
|
||||
SELECT LPAD('', 5, '*');
|
||||
|
||||
SELECT RPAD('', 5, '*');
|
||||
|
||||
SELECT LPAD('test', 0, '*');
|
||||
|
||||
SELECT RPAD('test', 0, '*');
|
||||
|
||||
-- TRIM with various whitespace characters
|
||||
SELECT TRIM('\t\nhello\r\n\t');
|
||||
|
||||
SELECT LTRIM('\t\nhello world');
|
||||
|
||||
SELECT RTRIM('hello world\r\n');
|
||||
|
||||
-- Custom TRIM characters
|
||||
CREATE TABLE custom_trim(s VARCHAR, ts TIMESTAMP TIME INDEX);
|
||||
|
||||
INSERT INTO custom_trim VALUES
|
||||
('***hello***', 1000),
|
||||
('---world---', 2000),
|
||||
('abcTESTabc', 3000);
|
||||
|
||||
SELECT s, TRIM('*' FROM s), TRIM('-' FROM s), TRIM('abc' FROM s) FROM custom_trim ORDER BY ts;
|
||||
|
||||
DROP TABLE trim_pad_test;
|
||||
|
||||
DROP TABLE custom_trim;
|
||||
@@ -0,0 +1,291 @@
|
||||
-- String case conversion function tests
|
||||
-- Basic UPPER and LOWER functions
|
||||
SELECT UPPER('hello world');
|
||||
|
||||
+----------------------------+
|
||||
| upper(Utf8("hello world")) |
|
||||
+----------------------------+
|
||||
| HELLO WORLD |
|
||||
+----------------------------+
|
||||
|
||||
SELECT LOWER('HELLO WORLD');
|
||||
|
||||
+----------------------------+
|
||||
| lower(Utf8("HELLO WORLD")) |
|
||||
+----------------------------+
|
||||
| hello world |
|
||||
+----------------------------+
|
||||
|
||||
SELECT UPPER('MiXeD cAsE');
|
||||
|
||||
+---------------------------+
|
||||
| upper(Utf8("MiXeD cAsE")) |
|
||||
+---------------------------+
|
||||
| MIXED CASE |
|
||||
+---------------------------+
|
||||
|
||||
SELECT LOWER('MiXeD cAsE');
|
||||
|
||||
+---------------------------+
|
||||
| lower(Utf8("MiXeD cAsE")) |
|
||||
+---------------------------+
|
||||
| mixed case |
|
||||
+---------------------------+
|
||||
|
||||
-- INITCAP (capitalize first letter of each word)
|
||||
SELECT INITCAP('hello world');
|
||||
|
||||
+------------------------------+
|
||||
| initcap(Utf8("hello world")) |
|
||||
+------------------------------+
|
||||
| Hello World |
|
||||
+------------------------------+
|
||||
|
||||
SELECT INITCAP('HELLO WORLD');
|
||||
|
||||
+------------------------------+
|
||||
| initcap(Utf8("HELLO WORLD")) |
|
||||
+------------------------------+
|
||||
| Hello World |
|
||||
+------------------------------+
|
||||
|
||||
SELECT INITCAP('mIxEd CaSe TeSt');
|
||||
|
||||
+----------------------------------+
|
||||
| initcap(Utf8("mIxEd CaSe TeSt")) |
|
||||
+----------------------------------+
|
||||
| Mixed Case Test |
|
||||
+----------------------------------+
|
||||
|
||||
-- Test with NULL
|
||||
SELECT UPPER(NULL);
|
||||
|
||||
+-------------+
|
||||
| upper(NULL) |
|
||||
+-------------+
|
||||
| |
|
||||
+-------------+
|
||||
|
||||
SELECT LOWER(NULL);
|
||||
|
||||
+-------------+
|
||||
| lower(NULL) |
|
||||
+-------------+
|
||||
| |
|
||||
+-------------+
|
||||
|
||||
SELECT INITCAP(NULL);
|
||||
|
||||
+---------------+
|
||||
| initcap(NULL) |
|
||||
+---------------+
|
||||
| |
|
||||
+---------------+
|
||||
|
||||
-- Test with numbers and special characters
|
||||
SELECT UPPER('hello123!@#');
|
||||
|
||||
+----------------------------+
|
||||
| upper(Utf8("hello123!@#")) |
|
||||
+----------------------------+
|
||||
| HELLO123!@# |
|
||||
+----------------------------+
|
||||
|
||||
SELECT LOWER('HELLO123!@#');
|
||||
|
||||
+----------------------------+
|
||||
| lower(Utf8("HELLO123!@#")) |
|
||||
+----------------------------+
|
||||
| hello123!@# |
|
||||
+----------------------------+
|
||||
|
||||
SELECT INITCAP('hello-world_test');
|
||||
|
||||
+-----------------------------------+
|
||||
| initcap(Utf8("hello-world_test")) |
|
||||
+-----------------------------------+
|
||||
| Hello-World_Test |
|
||||
+-----------------------------------+
|
||||
|
||||
-- Test with table data
|
||||
CREATE TABLE case_test("name" VARCHAR, city VARCHAR, ts TIMESTAMP TIME INDEX);
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
INSERT INTO case_test VALUES
|
||||
('john doe', 'new york', 1000),
|
||||
('JANE SMITH', 'LOS ANGELES', 2000),
|
||||
('Bob Wilson', 'Chicago', 3000),
|
||||
('alice johnson', 'BOSTON', 4000);
|
||||
|
||||
Affected Rows: 4
|
||||
|
||||
-- Apply case functions to table data
|
||||
SELECT "name", UPPER("name"), LOWER("name"), INITCAP("name") FROM case_test ORDER BY ts;
|
||||
|
||||
+---------------+-----------------------+-----------------------+-------------------------+
|
||||
| name | upper(case_test.name) | lower(case_test.name) | initcap(case_test.name) |
|
||||
+---------------+-----------------------+-----------------------+-------------------------+
|
||||
| john doe | JOHN DOE | john doe | John Doe |
|
||||
| JANE SMITH | JANE SMITH | jane smith | Jane Smith |
|
||||
| Bob Wilson | BOB WILSON | bob wilson | Bob Wilson |
|
||||
| alice johnson | ALICE JOHNSON | alice johnson | Alice Johnson |
|
||||
+---------------+-----------------------+-----------------------+-------------------------+
|
||||
|
||||
SELECT city, UPPER(city), LOWER(city), INITCAP(city) FROM case_test ORDER BY ts;
|
||||
|
||||
+-------------+-----------------------+-----------------------+-------------------------+
|
||||
| city | upper(case_test.city) | lower(case_test.city) | initcap(case_test.city) |
|
||||
+-------------+-----------------------+-----------------------+-------------------------+
|
||||
| new york | NEW YORK | new york | New York |
|
||||
| LOS ANGELES | LOS ANGELES | los angeles | Los Angeles |
|
||||
| Chicago | CHICAGO | chicago | Chicago |
|
||||
| BOSTON | BOSTON | boston | Boston |
|
||||
+-------------+-----------------------+-----------------------+-------------------------+
|
||||
|
||||
-- Combined case operations
|
||||
SELECT INITCAP(LOWER("name")) as formatted_name FROM case_test ORDER BY ts;
|
||||
|
||||
+----------------+
|
||||
| formatted_name |
|
||||
+----------------+
|
||||
| John Doe |
|
||||
| Jane Smith |
|
||||
| Bob Wilson |
|
||||
| Alice Johnson |
|
||||
+----------------+
|
||||
|
||||
-- Unicode case conversion
|
||||
SELECT UPPER('café');
|
||||
|
||||
+---------------------+
|
||||
| upper(Utf8("café")) |
|
||||
+---------------------+
|
||||
| CAFÉ |
|
||||
+---------------------+
|
||||
|
||||
SELECT LOWER('CAFÉ');
|
||||
|
||||
+---------------------+
|
||||
| lower(Utf8("CAFÉ")) |
|
||||
+---------------------+
|
||||
| café |
|
||||
+---------------------+
|
||||
|
||||
-- German characters
|
||||
SELECT UPPER('äöüß');
|
||||
|
||||
+---------------------+
|
||||
| upper(Utf8("äöüß")) |
|
||||
+---------------------+
|
||||
| ÄÖÜSS |
|
||||
+---------------------+
|
||||
|
||||
-- German uppercase
|
||||
SELECT LOWER('ÄÖÜ');
|
||||
|
||||
+--------------------+
|
||||
| lower(Utf8("ÄÖÜ")) |
|
||||
+--------------------+
|
||||
| äöü |
|
||||
+--------------------+
|
||||
|
||||
-- Greek letters
|
||||
SELECT UPPER('αβγ');
|
||||
|
||||
+--------------------+
|
||||
| upper(Utf8("αβγ")) |
|
||||
+--------------------+
|
||||
| ΑΒΓ |
|
||||
+--------------------+
|
||||
|
||||
SELECT LOWER('ΑΒΓ');
|
||||
|
||||
+--------------------+
|
||||
| lower(Utf8("ΑΒΓ")) |
|
||||
+--------------------+
|
||||
| αβγ |
|
||||
+--------------------+
|
||||
|
||||
-- Test with empty string
|
||||
SELECT UPPER('');
|
||||
|
||||
+-----------------+
|
||||
| upper(Utf8("")) |
|
||||
+-----------------+
|
||||
| |
|
||||
+-----------------+
|
||||
|
||||
SELECT LOWER('');
|
||||
|
||||
+-----------------+
|
||||
| lower(Utf8("")) |
|
||||
+-----------------+
|
||||
| |
|
||||
+-----------------+
|
||||
|
||||
SELECT INITCAP('');
|
||||
|
||||
+-------------------+
|
||||
| initcap(Utf8("")) |
|
||||
+-------------------+
|
||||
| |
|
||||
+-------------------+
|
||||
|
||||
-- Test with single characters
|
||||
SELECT UPPER('a'), UPPER('A'), UPPER('1'), UPPER(' ');
|
||||
|
||||
+------------------+------------------+------------------+------------------+
|
||||
| upper(Utf8("a")) | upper(Utf8("A")) | upper(Utf8("1")) | upper(Utf8(" ")) |
|
||||
+------------------+------------------+------------------+------------------+
|
||||
| A | A | 1 | |
|
||||
+------------------+------------------+------------------+------------------+
|
||||
|
||||
SELECT LOWER('a'), LOWER('A'), LOWER('1'), LOWER(' ');
|
||||
|
||||
+------------------+------------------+------------------+------------------+
|
||||
| lower(Utf8("a")) | lower(Utf8("A")) | lower(Utf8("1")) | lower(Utf8(" ")) |
|
||||
+------------------+------------------+------------------+------------------+
|
||||
| a | a | 1 | |
|
||||
+------------------+------------------+------------------+------------------+
|
||||
|
||||
SELECT INITCAP('a'), INITCAP('A'), INITCAP('1');
|
||||
|
||||
+--------------------+--------------------+--------------------+
|
||||
| initcap(Utf8("a")) | initcap(Utf8("A")) | initcap(Utf8("1")) |
|
||||
+--------------------+--------------------+--------------------+
|
||||
| A | A | 1 |
|
||||
+--------------------+--------------------+--------------------+
|
||||
|
||||
-- Complex Unicode examples
|
||||
CREATE TABLE unicode_case(s VARCHAR, ts TIMESTAMP TIME INDEX);
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
INSERT INTO unicode_case VALUES
|
||||
('hello 世界', 1000),
|
||||
('HELLO 世界', 2000),
|
||||
('café à paris', 3000),
|
||||
('CAFÉ À PARIS', 4000);
|
||||
|
||||
Affected Rows: 4
|
||||
|
||||
SELECT s, UPPER(s), LOWER(s), INITCAP(s) FROM unicode_case ORDER BY ts;
|
||||
|
||||
+--------------+-----------------------+-----------------------+-------------------------+
|
||||
| s | upper(unicode_case.s) | lower(unicode_case.s) | initcap(unicode_case.s) |
|
||||
+--------------+-----------------------+-----------------------+-------------------------+
|
||||
| hello 世界 | HELLO 世界 | hello 世界 | Hello 世界 |
|
||||
| HELLO 世界 | HELLO 世界 | hello 世界 | Hello 世界 |
|
||||
| café à paris | CAFÉ À PARIS | café à paris | Café À Paris |
|
||||
| CAFÉ À PARIS | CAFÉ À PARIS | café à paris | Café À Paris |
|
||||
+--------------+-----------------------+-----------------------+-------------------------+
|
||||
|
||||
DROP TABLE case_test;
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
DROP TABLE unicode_case;
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
-- String case conversion function tests
|
||||
|
||||
-- Basic UPPER and LOWER functions
|
||||
SELECT UPPER('hello world');
|
||||
|
||||
SELECT LOWER('HELLO WORLD');
|
||||
|
||||
SELECT UPPER('MiXeD cAsE');
|
||||
|
||||
SELECT LOWER('MiXeD cAsE');
|
||||
|
||||
-- INITCAP (capitalize first letter of each word)
|
||||
SELECT INITCAP('hello world');
|
||||
|
||||
SELECT INITCAP('HELLO WORLD');
|
||||
|
||||
SELECT INITCAP('mIxEd CaSe TeSt');
|
||||
|
||||
-- Test with NULL
|
||||
SELECT UPPER(NULL);
|
||||
|
||||
SELECT LOWER(NULL);
|
||||
|
||||
SELECT INITCAP(NULL);
|
||||
|
||||
-- Test with numbers and special characters
|
||||
SELECT UPPER('hello123!@#');
|
||||
|
||||
SELECT LOWER('HELLO123!@#');
|
||||
|
||||
SELECT INITCAP('hello-world_test');
|
||||
|
||||
-- Test with table data
|
||||
CREATE TABLE case_test("name" VARCHAR, city VARCHAR, ts TIMESTAMP TIME INDEX);
|
||||
|
||||
INSERT INTO case_test VALUES
|
||||
('john doe', 'new york', 1000),
|
||||
('JANE SMITH', 'LOS ANGELES', 2000),
|
||||
('Bob Wilson', 'Chicago', 3000),
|
||||
('alice johnson', 'BOSTON', 4000);
|
||||
|
||||
-- Apply case functions to table data
|
||||
SELECT "name", UPPER("name"), LOWER("name"), INITCAP("name") FROM case_test ORDER BY ts;
|
||||
|
||||
SELECT city, UPPER(city), LOWER(city), INITCAP(city) FROM case_test ORDER BY ts;
|
||||
|
||||
-- Combined case operations
|
||||
SELECT INITCAP(LOWER("name")) as formatted_name FROM case_test ORDER BY ts;
|
||||
|
||||
-- Unicode case conversion
|
||||
SELECT UPPER('café');
|
||||
|
||||
SELECT LOWER('CAFÉ');
|
||||
|
||||
-- German characters
|
||||
SELECT UPPER('äöüß');
|
||||
|
||||
-- German uppercase
|
||||
SELECT LOWER('ÄÖÜ');
|
||||
|
||||
-- Greek letters
|
||||
SELECT UPPER('αβγ');
|
||||
|
||||
SELECT LOWER('ΑΒΓ');
|
||||
|
||||
-- Test with empty string
|
||||
SELECT UPPER('');
|
||||
|
||||
SELECT LOWER('');
|
||||
|
||||
SELECT INITCAP('');
|
||||
|
||||
-- Test with single characters
|
||||
SELECT UPPER('a'), UPPER('A'), UPPER('1'), UPPER(' ');
|
||||
|
||||
SELECT LOWER('a'), LOWER('A'), LOWER('1'), LOWER(' ');
|
||||
|
||||
SELECT INITCAP('a'), INITCAP('A'), INITCAP('1');
|
||||
|
||||
-- Complex Unicode examples
|
||||
CREATE TABLE unicode_case(s VARCHAR, ts TIMESTAMP TIME INDEX);
|
||||
|
||||
INSERT INTO unicode_case VALUES
|
||||
('hello 世界', 1000),
|
||||
('HELLO 世界', 2000),
|
||||
('café à paris', 3000),
|
||||
('CAFÉ À PARIS', 4000);
|
||||
|
||||
SELECT s, UPPER(s), LOWER(s), INITCAP(s) FROM unicode_case ORDER BY ts;
|
||||
|
||||
DROP TABLE case_test;
|
||||
|
||||
DROP TABLE unicode_case;
|
||||
Reference in New Issue
Block a user