Signed-off-by: stephen <stephen5217@163.com> Co-authored-by: stephen <91597003+stephen-shelby@users.noreply.github.com>
This commit is contained in:
parent
c0fa924fe2
commit
ba258aee4c
|
|
@ -0,0 +1,277 @@
|
|||
-- name: test_decimal256_partitioned_tables
|
||||
DROP DATABASE IF EXISTS test_decimal256_partition;
|
||||
-- result:
|
||||
-- !result
|
||||
CREATE DATABASE test_decimal256_partition;
|
||||
-- result:
|
||||
-- !result
|
||||
USE test_decimal256_partition;
|
||||
-- result:
|
||||
-- !result
|
||||
CREATE TABLE decimal_range_partition (
|
||||
id BIGINT,
|
||||
transaction_date DATE,
|
||||
amount DECIMAL(50,15),
|
||||
balance DECIMAL(76,20),
|
||||
account_type VARCHAR(20)
|
||||
)
|
||||
DUPLICATE KEY(id, transaction_date)
|
||||
PARTITION BY RANGE(transaction_date) (
|
||||
PARTITION p202401 VALUES [('2024-01-01'), ('2024-02-01')),
|
||||
PARTITION p202402 VALUES [('2024-02-01'), ('2024-03-01')),
|
||||
PARTITION p202403 VALUES [('2024-03-01'), ('2024-04-01')),
|
||||
PARTITION p202404 VALUES [('2024-04-01'), ('2024-05-01'))
|
||||
)
|
||||
DISTRIBUTED BY HASH(id) BUCKETS 3
|
||||
PROPERTIES (
|
||||
"replication_num" = "1"
|
||||
);
|
||||
-- result:
|
||||
-- !result
|
||||
INSERT INTO decimal_range_partition VALUES
|
||||
(1, '2024-01-15', 12345678901234567890123456789012345.123456789012345, 12345678901234567890123456789012345678901234567890123456.12345678901234567890, 'SAVINGS'),
|
||||
(2, '2024-01-20', -55555555555555555555555555555555555.987654321098765, 55555555555555555555555555555555555555555555555555555555.13579246801357924680, 'CHECKING'),
|
||||
(3, '2024-01-25', 98765432109876543210987654321098765.555555555555555, 98765432109876543210987654321098765432109876543210987654.99999999999999999999, 'INVESTMENT'),
|
||||
|
||||
(4, '2024-02-10', 77777777777777777777777777777777777.777777777777777, 77777777777777777777777777777777777777777777777777777777.77777777777777777777, 'SAVINGS'),
|
||||
(5, '2024-02-15', -44444444444444444444444444444444444.111111111111111, 44444444444444444444444444444444444444444444444444444444.66666666666666666666, 'CHECKING'),
|
||||
(6, '2024-02-28', 88888888888888888888888888888888888.999999999999999, 88888888888888888888888888888888888888888888888888888888.65432109876543210987, 'INVESTMENT'),
|
||||
|
||||
(7, '2024-03-05', 11111111111111111111111111111111111.250000000000000, 11111111111111111111111111111111111111111111111111111111.90400000000000000000, 'SAVINGS'),
|
||||
(8, '2024-03-12', -22222222222222222222222222222222222.125000000000000, 22222222222222222222222222222222222222222222222222222222.77900000000000000000, 'CHECKING'),
|
||||
(9, '2024-03-25', 99999888887777766666555554444433333.000000000000001, 99999888887777766666555554444433333222221111100009999988.77900000000000000001, 'INVESTMENT'),
|
||||
|
||||
(10, '2024-04-08', 33333333333333333333333333333333333.888888888888888, 33333333333333333333333333333333333333333333333333333333.66788888888888888889, 'SAVINGS'),
|
||||
(11, '2024-04-15', -66666666666666666666666666666666666.333333333333333, 66666666666666666666666666666666666666666666666666666666.33455555555555555556, 'CHECKING'),
|
||||
(12, '2024-04-30', 77777666665555544444333332222211111.000000000000000, 77777666665555544444333332222211111000009999988888777776.33455555555555555556, 'INVESTMENT');
|
||||
-- result:
|
||||
-- !result
|
||||
SELECT
|
||||
'Test1_PARTITION_BASIC_QUERY' as test_name,
|
||||
DATE_FORMAT(transaction_date, '%Y-%m') as month,
|
||||
COUNT(*) as transaction_count,
|
||||
SUM(amount) as total_amount,
|
||||
AVG(balance) as avg_balance,
|
||||
MAX(amount) as max_amount,
|
||||
MIN(amount) as min_amount
|
||||
FROM decimal_range_partition
|
||||
GROUP BY DATE_FORMAT(transaction_date, '%Y-%m')
|
||||
ORDER BY month;
|
||||
-- result:
|
||||
Test1_PARTITION_BASIC_QUERY 2024-01 3 55555555455555555545555555554555554.691358023469135 55555555522222222218888888888555555555522222222218888888.75308308567530830856 98765432109876543210987654321098765.555555555555555 -55555555555555555555555555555555555.987654321098765
|
||||
Test1_PARTITION_BASIC_QUERY 2024-02 3 122222222222222222222222222222222222.666666666666665 70370370370370370370370370370370370370370370370370370370.36625518106995885143 88888888888888888888888888888888888.999999999999999 -44444444444444444444444444444444444.111111111111111
|
||||
Test1_PARTITION_BASIC_QUERY 2024-03 3 88888777776666655555444443333322222.125000000000001 44444407407037033333296295925922222185184814811114444441.15400000000000000000 99999888887777766666555554444433333.000000000000001 -22222222222222222222222222222222222.125000000000000
|
||||
Test1_PARTITION_BASIC_QUERY 2024-04 3 44444333332222211110999998888877778.555555555555555 59259222221851848148111110740737037000003333329629592592.11233333333333333334 77777666665555544444333332222211111.000000000000000 -66666666666666666666666666666666666.333333333333333
|
||||
-- !result
|
||||
SELECT
|
||||
'Test2_SINGLE_PARTITION_QUERY' as test_name,
|
||||
id,
|
||||
transaction_date,
|
||||
amount,
|
||||
balance,
|
||||
account_type
|
||||
FROM decimal_range_partition
|
||||
WHERE transaction_date >= '2024-02-01' AND transaction_date < '2024-03-01'
|
||||
ORDER BY transaction_date;
|
||||
-- result:
|
||||
Test2_SINGLE_PARTITION_QUERY 4 2024-02-10 77777777777777777777777777777777777.777777777777777 77777777777777777777777777777777777777777777777777777777.77777777777777777777 SAVINGS
|
||||
Test2_SINGLE_PARTITION_QUERY 5 2024-02-15 -44444444444444444444444444444444444.111111111111111 44444444444444444444444444444444444444444444444444444444.66666666666666666666 CHECKING
|
||||
Test2_SINGLE_PARTITION_QUERY 6 2024-02-28 88888888888888888888888888888888888.999999999999999 88888888888888888888888888888888888888888888888888888888.65432109876543210987 INVESTMENT
|
||||
-- !result
|
||||
SELECT
|
||||
'Test3_CROSS_PARTITION_AGGREGATION' as test_name,
|
||||
account_type,
|
||||
COUNT(*) as transaction_count,
|
||||
SUM(amount) as total_amount,
|
||||
AVG(amount) as avg_amount,
|
||||
SUM(CASE WHEN amount > 0 THEN amount ELSE 0 END) as total_deposits,
|
||||
SUM(CASE WHEN amount < 0 THEN ABS(amount) ELSE 0 END) as total_withdrawals
|
||||
FROM decimal_range_partition
|
||||
GROUP BY account_type
|
||||
ORDER BY account_type;
|
||||
-- result:
|
||||
Test3_CROSS_PARTITION_AGGREGATION CHECKING 4 -188888888888888888888888888888888888.557098765543209 -47222222222222222222222222222222222.139274691385802 0E-15 188888888888888888888888888888888888.557098765543209
|
||||
Test3_CROSS_PARTITION_AGGREGATION INVESTMENT 4 365431876552098743210765429876632098.555555555555555 91357969138024685802691357469158024.638888888888889 365431876552098743210765429876632098.555555555555555 0E-15
|
||||
Test3_CROSS_PARTITION_AGGREGATION SAVINGS 4 134567901123456790112345679011234568.040123455679010 33641975280864197528086419752808642.010030863919753 134567901123456790112345679011234568.040123455679010 0E-15
|
||||
-- !result
|
||||
CREATE TABLE decimal_amount_partition (
|
||||
id BIGINT,
|
||||
customer_id INT,
|
||||
amount DECIMAL(50,15),
|
||||
large_amount DECIMAL(76,0),
|
||||
category VARCHAR(20),
|
||||
amount_range STRING
|
||||
)
|
||||
DUPLICATE KEY(id, customer_id)
|
||||
PARTITION BY LIST(amount_range) (
|
||||
PARTITION p_small VALUES IN ('SMALL'),
|
||||
PARTITION p_medium VALUES IN ('MEDIUM'),
|
||||
PARTITION p_large VALUES IN ('LARGE'),
|
||||
PARTITION p_xlarge VALUES IN ('XLARGE')
|
||||
)
|
||||
DISTRIBUTED BY HASH(customer_id) BUCKETS 3
|
||||
PROPERTIES (
|
||||
"replication_num" = "1"
|
||||
);
|
||||
-- result:
|
||||
-- !result
|
||||
INSERT INTO decimal_amount_partition VALUES
|
||||
(1, 101, 12345678901234567890123456789012345.123456789012345, 12345678901234567, 'RETAIL', 'SMALL'),
|
||||
(2, 102, 98765432109876543210987654321098765.987654321098765, 98765432109876543, 'ONLINE', 'SMALL'),
|
||||
(3, 103, 55555555555555555555555555555555555.999999999999999, 55555555555555555, 'RETAIL', 'SMALL'),
|
||||
|
||||
(4, 201, 1234567890123456789012345678901234.555555555555, 1234567890123456789012345678901234567890123456789012345678901234567890, 'WHOLESALE', 'MEDIUM'),
|
||||
(5, 202, 9876543210987654321098765432109876.777777777777, 9876543210987654321098765432109876543210987654321098765432109876543210, 'ENTERPRISE', 'MEDIUM'),
|
||||
(6, 203, 5555555555555555555555555555555555.888888888888, 5555555555555555555555555555555555555555555555555555555555555555555555, 'WHOLESALE', 'MEDIUM'),
|
||||
|
||||
(7, 301, 12345678901234567890123456789012.123456789012345, 123456789012345, 'ENTERPRISE', 'LARGE'),
|
||||
(8, 302, 98765432109876543210987654321098.999999999999999, 987654321098765, 'GOVERNMENT', 'LARGE'),
|
||||
(9, 303, 77777777777777777777777777777777.111111111111111, 777777777777777, 'ENTERPRISE', 'LARGE');
|
||||
-- result:
|
||||
-- !result
|
||||
SELECT
|
||||
'Test4_LIST_PARTITION_AGGREGATION' as test_name,
|
||||
amount_range,
|
||||
category,
|
||||
COUNT(*) as count,
|
||||
SUM(amount) as total_amount,
|
||||
AVG(amount) as avg_amount,
|
||||
MIN(amount) as min_amount,
|
||||
MAX(amount) as max_amount
|
||||
FROM decimal_amount_partition
|
||||
GROUP BY amount_range, category
|
||||
ORDER BY amount_range, category;
|
||||
-- result:
|
||||
Test4_LIST_PARTITION_AGGREGATION LARGE ENTERPRISE 2 90123456679012345667901234566789.234567900123456 45061728339506172833950617283394.617283950061728 12345678901234567890123456789012.123456789012345 77777777777777777777777777777777.111111111111111
|
||||
Test4_LIST_PARTITION_AGGREGATION LARGE GOVERNMENT 1 98765432109876543210987654321098.999999999999999 98765432109876543210987654321098.999999999999999 98765432109876543210987654321098.999999999999999 98765432109876543210987654321098.999999999999999
|
||||
Test4_LIST_PARTITION_AGGREGATION MEDIUM ENTERPRISE 1 9876543210987654321098765432109876.777777777777000 9876543210987654321098765432109876.777777777777000 9876543210987654321098765432109876.777777777777000 9876543210987654321098765432109876.777777777777000
|
||||
Test4_LIST_PARTITION_AGGREGATION MEDIUM WHOLESALE 2 6790123445679012344567901234456790.444444444443000 3395061722839506172283950617228395.222222222221500 1234567890123456789012345678901234.555555555555000 5555555555555555555555555555555555.888888888888000
|
||||
Test4_LIST_PARTITION_AGGREGATION SMALL ONLINE 1 98765432109876543210987654321098765.987654321098765 98765432109876543210987654321098765.987654321098765 98765432109876543210987654321098765.987654321098765 98765432109876543210987654321098765.987654321098765
|
||||
Test4_LIST_PARTITION_AGGREGATION SMALL RETAIL 2 67901234456790123445679012344567901.123456789012344 33950617228395061722839506172283950.561728394506172 12345678901234567890123456789012345.123456789012345 55555555555555555555555555555555555.999999999999999
|
||||
-- !result
|
||||
SELECT
|
||||
'Test5_PARTITION_PRUNING_SPECIFIC' as test_name,
|
||||
id,
|
||||
customer_id,
|
||||
amount,
|
||||
large_amount,
|
||||
category
|
||||
FROM decimal_amount_partition
|
||||
WHERE amount_range = 'LARGE'
|
||||
ORDER BY amount DESC;
|
||||
-- result:
|
||||
Test5_PARTITION_PRUNING_SPECIFIC 8 302 98765432109876543210987654321098.999999999999999 987654321098765 GOVERNMENT
|
||||
Test5_PARTITION_PRUNING_SPECIFIC 9 303 77777777777777777777777777777777.111111111111111 777777777777777 ENTERPRISE
|
||||
Test5_PARTITION_PRUNING_SPECIFIC 7 301 12345678901234567890123456789012.123456789012345 123456789012345 ENTERPRISE
|
||||
-- !result
|
||||
ALTER TABLE decimal_range_partition
|
||||
ADD PARTITION p202405 VALUES [('2024-05-01'), ('2024-06-01'));
|
||||
-- result:
|
||||
-- !result
|
||||
INSERT INTO decimal_range_partition VALUES
|
||||
(13, '2024-05-10', 888887777766666555554444433.123456789012345, 8888877777666665555544444333332222211111.45800234567890123456, 'SAVINGS'),
|
||||
(14, '2024-05-20', -11111222223333344444555556.987654321098765, 1111122222333334444455555666667777788888.47034913469124801235, 'CHECKING'),
|
||||
(15, '2024-05-31', 999999999999999999999999999.000000000000000, 9999999999999999999999999999999999999999.47034913469124801235, 'INVESTMENT');
|
||||
-- result:
|
||||
-- !result
|
||||
SELECT
|
||||
'Test7_ALL_PARTITIONS_INCLUDING_NEW' as test_name,
|
||||
DATE_FORMAT(transaction_date, '%Y-%m') as month,
|
||||
COUNT(*) as transaction_count,
|
||||
SUM(amount) as total_amount,
|
||||
AVG(balance) as avg_balance
|
||||
FROM decimal_range_partition
|
||||
GROUP BY DATE_FORMAT(transaction_date, '%Y-%m')
|
||||
ORDER BY month;
|
||||
-- result:
|
||||
Test7_ALL_PARTITIONS_INCLUDING_NEW 2024-01 3 55555555455555555545555555554555554.691358023469135 55555555522222222218888888888555555555522222222218888888.75308308567530830856
|
||||
Test7_ALL_PARTITIONS_INCLUDING_NEW 2024-02 3 122222222222222222222222222222222222.666666666666665 70370370370370370370370370370370370370370370370370370370.36625518106995885143
|
||||
Test7_ALL_PARTITIONS_INCLUDING_NEW 2024-03 3 88888777776666655555444443333322222.125000000000001 44444407407037033333296295925922222185184814811114444441.15400000000000000000
|
||||
Test7_ALL_PARTITIONS_INCLUDING_NEW 2024-04 3 44444333332222211110999998888877778.555555555555555 59259222221851848148111110740737037000003333329629592592.11233333333333333334
|
||||
Test7_ALL_PARTITIONS_INCLUDING_NEW 2024-05 3 1877776555543333211109888875.135802467913580 6666666666666666666666666666666666666666.46623353835379908642
|
||||
-- !result
|
||||
SELECT
|
||||
'Test8_PARTITION_WINDOW_FUNCTIONS' as test_name,
|
||||
id,
|
||||
transaction_date,
|
||||
amount,
|
||||
balance,
|
||||
account_type,
|
||||
ROW_NUMBER() OVER (PARTITION BY DATE_FORMAT(transaction_date, '%Y-%m') ORDER BY amount DESC) as rank_in_month,
|
||||
SUM(amount) OVER (PARTITION BY account_type ORDER BY transaction_date) as running_total_by_type,
|
||||
LAG(balance, 1) OVER (PARTITION BY account_type ORDER BY transaction_date) as prev_balance
|
||||
FROM decimal_range_partition
|
||||
ORDER BY transaction_date, account_type;
|
||||
-- result:
|
||||
Test8_PARTITION_WINDOW_FUNCTIONS 1 2024-01-15 12345678901234567890123456789012345.123456789012345 12345678901234567890123456789012345678901234567890123456.12345678901234567890 SAVINGS 2 12345678901234567890123456789012345.123456789012345 None
|
||||
Test8_PARTITION_WINDOW_FUNCTIONS 2 2024-01-20 -55555555555555555555555555555555555.987654321098765 55555555555555555555555555555555555555555555555555555555.13579246801357924680 CHECKING 3 -55555555555555555555555555555555555.987654321098765 None
|
||||
Test8_PARTITION_WINDOW_FUNCTIONS 3 2024-01-25 98765432109876543210987654321098765.555555555555555 98765432109876543210987654321098765432109876543210987654.99999999999999999999 INVESTMENT 1 98765432109876543210987654321098765.555555555555555 None
|
||||
Test8_PARTITION_WINDOW_FUNCTIONS 4 2024-02-10 77777777777777777777777777777777777.777777777777777 77777777777777777777777777777777777777777777777777777777.77777777777777777777 SAVINGS 2 90123456679012345667901234566790122.901234566790122 12345678901234567890123456789012345678901234567890123456.12345678901234567890
|
||||
Test8_PARTITION_WINDOW_FUNCTIONS 5 2024-02-15 -44444444444444444444444444444444444.111111111111111 44444444444444444444444444444444444444444444444444444444.66666666666666666666 CHECKING 3 -100000000000000000000000000000000000.098765432209876 55555555555555555555555555555555555555555555555555555555.13579246801357924680
|
||||
Test8_PARTITION_WINDOW_FUNCTIONS 6 2024-02-28 88888888888888888888888888888888888.999999999999999 88888888888888888888888888888888888888888888888888888888.65432109876543210987 INVESTMENT 1 187654320998765432099876543209987654.555555555555554 98765432109876543210987654321098765432109876543210987654.99999999999999999999
|
||||
Test8_PARTITION_WINDOW_FUNCTIONS 7 2024-03-05 11111111111111111111111111111111111.250000000000000 11111111111111111111111111111111111111111111111111111111.90400000000000000000 SAVINGS 2 101234567790123456779012345677901234.151234566790122 77777777777777777777777777777777777777777777777777777777.77777777777777777777
|
||||
Test8_PARTITION_WINDOW_FUNCTIONS 8 2024-03-12 -22222222222222222222222222222222222.125000000000000 22222222222222222222222222222222222222222222222222222222.77900000000000000000 CHECKING 3 -122222222222222222222222222222222222.223765432209876 44444444444444444444444444444444444444444444444444444444.66666666666666666666
|
||||
Test8_PARTITION_WINDOW_FUNCTIONS 9 2024-03-25 99999888887777766666555554444433333.000000000000001 99999888887777766666555554444433333222221111100009999988.77900000000000000001 INVESTMENT 1 287654209886543198766432097654420987.555555555555555 88888888888888888888888888888888888888888888888888888888.65432109876543210987
|
||||
Test8_PARTITION_WINDOW_FUNCTIONS 10 2024-04-08 33333333333333333333333333333333333.888888888888888 33333333333333333333333333333333333333333333333333333333.66788888888888888889 SAVINGS 2 134567901123456790112345679011234568.040123455679010 11111111111111111111111111111111111111111111111111111111.90400000000000000000
|
||||
Test8_PARTITION_WINDOW_FUNCTIONS 11 2024-04-15 -66666666666666666666666666666666666.333333333333333 66666666666666666666666666666666666666666666666666666666.33455555555555555556 CHECKING 3 -188888888888888888888888888888888888.557098765543209 22222222222222222222222222222222222222222222222222222222.77900000000000000000
|
||||
Test8_PARTITION_WINDOW_FUNCTIONS 12 2024-04-30 77777666665555544444333332222211111.000000000000000 77777666665555544444333332222211111000009999988888777776.33455555555555555556 INVESTMENT 1 365431876552098743210765429876632098.555555555555555 99999888887777766666555554444433333222221111100009999988.77900000000000000001
|
||||
Test8_PARTITION_WINDOW_FUNCTIONS 13 2024-05-10 888887777766666555554444433.123456789012345 8888877777666665555544444333332222211111.45800234567890123456 SAVINGS 2 134567902012344567879012234565679001.163580244691355 33333333333333333333333333333333333333333333333333333333.66788888888888888889
|
||||
Test8_PARTITION_WINDOW_FUNCTIONS 14 2024-05-20 -11111222223333344444555556.987654321098765 1111122222333334444455555666667777788888.47034913469124801235 CHECKING 3 -188888888900000111112222233333444445.544753086641974 66666666666666666666666666666666666666666666666666666666.33455555555555555556
|
||||
Test8_PARTITION_WINDOW_FUNCTIONS 15 2024-05-31 999999999999999999999999999.000000000000000 9999999999999999999999999999999999999999.47034913469124801235 INVESTMENT 1 365431877552098743210765429876632097.555555555555555 77777666665555544444333332222211111000009999988888777776.33455555555555555556
|
||||
-- !result
|
||||
WITH monthly_stats AS (
|
||||
SELECT
|
||||
DATE_FORMAT(transaction_date, '%Y-%m') as month,
|
||||
account_type,
|
||||
SUM(amount) as monthly_total,
|
||||
COUNT(*) as monthly_count
|
||||
FROM decimal_range_partition
|
||||
GROUP BY DATE_FORMAT(transaction_date, '%Y-%m'), account_type
|
||||
)
|
||||
SELECT
|
||||
'Test9_CROSS_PARTITION_JOINS' as test_name,
|
||||
dp.transaction_date,
|
||||
dp.amount,
|
||||
dp.account_type,
|
||||
ms.monthly_total,
|
||||
dp.amount / ms.monthly_total * 100 as percent_of_monthly_total
|
||||
FROM decimal_range_partition dp
|
||||
JOIN monthly_stats ms ON DATE_FORMAT(dp.transaction_date, '%Y-%m') = ms.month
|
||||
AND dp.account_type = ms.account_type
|
||||
WHERE ABS(dp.amount) > 1000.000000000000000
|
||||
ORDER BY dp.transaction_date;
|
||||
-- result:
|
||||
Test9_CROSS_PARTITION_JOINS 2024-01-15 12345678901234567890123456789012345.123456789012345 SAVINGS 12345678901234567890123456789012345.123456789012345 100.000000000000000
|
||||
Test9_CROSS_PARTITION_JOINS 2024-01-20 -55555555555555555555555555555555555.987654321098765 CHECKING -55555555555555555555555555555555555.987654321098765 100.000000000000000
|
||||
Test9_CROSS_PARTITION_JOINS 2024-01-25 98765432109876543210987654321098765.555555555555555 INVESTMENT 98765432109876543210987654321098765.555555555555555 100.000000000000000
|
||||
Test9_CROSS_PARTITION_JOINS 2024-02-10 77777777777777777777777777777777777.777777777777777 SAVINGS 77777777777777777777777777777777777.777777777777777 100.000000000000000
|
||||
Test9_CROSS_PARTITION_JOINS 2024-02-15 -44444444444444444444444444444444444.111111111111111 CHECKING -44444444444444444444444444444444444.111111111111111 100.000000000000000
|
||||
Test9_CROSS_PARTITION_JOINS 2024-02-28 88888888888888888888888888888888888.999999999999999 INVESTMENT 88888888888888888888888888888888888.999999999999999 100.000000000000000
|
||||
Test9_CROSS_PARTITION_JOINS 2024-03-05 11111111111111111111111111111111111.250000000000000 SAVINGS 11111111111111111111111111111111111.250000000000000 100.000000000000000
|
||||
Test9_CROSS_PARTITION_JOINS 2024-03-12 -22222222222222222222222222222222222.125000000000000 CHECKING -22222222222222222222222222222222222.125000000000000 100.000000000000000
|
||||
Test9_CROSS_PARTITION_JOINS 2024-03-25 99999888887777766666555554444433333.000000000000001 INVESTMENT 99999888887777766666555554444433333.000000000000001 100.000000000000000
|
||||
Test9_CROSS_PARTITION_JOINS 2024-04-08 33333333333333333333333333333333333.888888888888888 SAVINGS 33333333333333333333333333333333333.888888888888888 100.000000000000000
|
||||
Test9_CROSS_PARTITION_JOINS 2024-04-15 -66666666666666666666666666666666666.333333333333333 CHECKING -66666666666666666666666666666666666.333333333333333 100.000000000000000
|
||||
Test9_CROSS_PARTITION_JOINS 2024-04-30 77777666665555544444333332222211111.000000000000000 INVESTMENT 77777666665555544444333332222211111.000000000000000 100.000000000000000
|
||||
Test9_CROSS_PARTITION_JOINS 2024-05-10 888887777766666555554444433.123456789012345 SAVINGS 888887777766666555554444433.123456789012345 100.000000000000000
|
||||
Test9_CROSS_PARTITION_JOINS 2024-05-20 -11111222223333344444555556.987654321098765 CHECKING -11111222223333344444555556.987654321098765 100.000000000000000
|
||||
Test9_CROSS_PARTITION_JOINS 2024-05-31 999999999999999999999999999.000000000000000 INVESTMENT 999999999999999999999999999.000000000000000 100.000000000000000
|
||||
-- !result
|
||||
SELECT
|
||||
'Test10_PARTITION_INFORMATION' as test_name,
|
||||
DATE_FORMAT(transaction_date, '%Y-%m') as partition_month,
|
||||
COUNT(*) as row_count,
|
||||
SUM(CASE WHEN amount > 0 THEN 1 ELSE 0 END) as positive_transactions,
|
||||
SUM(CASE WHEN amount < 0 THEN 1 ELSE 0 END) as negative_transactions,
|
||||
MIN(balance) as min_balance_in_partition,
|
||||
MAX(balance) as max_balance_in_partition
|
||||
FROM decimal_range_partition
|
||||
GROUP BY DATE_FORMAT(transaction_date, '%Y-%m')
|
||||
ORDER BY partition_month;
|
||||
-- result:
|
||||
Test10_PARTITION_INFORMATION 2024-01 3 2 1 12345678901234567890123456789012345678901234567890123456.12345678901234567890 98765432109876543210987654321098765432109876543210987654.99999999999999999999
|
||||
Test10_PARTITION_INFORMATION 2024-02 3 2 1 44444444444444444444444444444444444444444444444444444444.66666666666666666666 88888888888888888888888888888888888888888888888888888888.65432109876543210987
|
||||
Test10_PARTITION_INFORMATION 2024-03 3 2 1 11111111111111111111111111111111111111111111111111111111.90400000000000000000 99999888887777766666555554444433333222221111100009999988.77900000000000000001
|
||||
Test10_PARTITION_INFORMATION 2024-04 3 2 1 33333333333333333333333333333333333333333333333333333333.66788888888888888889 77777666665555544444333332222211111000009999988888777776.33455555555555555556
|
||||
Test10_PARTITION_INFORMATION 2024-05 3 2 1 1111122222333334444455555666667777788888.47034913469124801235 9999999999999999999999999999999999999999.47034913469124801235
|
||||
-- !result
|
||||
|
|
@ -0,0 +1,193 @@
|
|||
-- name: test_decimal256_string_functions
|
||||
DROP DATABASE IF EXISTS test_decimal256_string;
|
||||
-- result:
|
||||
-- !result
|
||||
CREATE DATABASE test_decimal256_string;
|
||||
-- result:
|
||||
-- !result
|
||||
USE test_decimal256_string;
|
||||
-- result:
|
||||
-- !result
|
||||
CREATE TABLE decimal_string_test (
|
||||
id INT,
|
||||
d50_15 DECIMAL(50,15),
|
||||
d76_20 DECIMAL(76,20),
|
||||
d76_0 DECIMAL(76,0),
|
||||
category VARCHAR(10)
|
||||
) PROPERTIES("replication_num"="1");
|
||||
-- result:
|
||||
-- !result
|
||||
INSERT INTO decimal_string_test VALUES
|
||||
(1, 12345678901234567890123456789012345.123456789012345, 12345678901234567890123456789012345678901234567890123456.12345678901234567890, 1234567890123456789012345678901234567890123456789012345678901234567890123456, 'A'),
|
||||
(2, -98765432109876543210987654321098765.456789012345678, -98765432109876543210987654321098765432109876543210987654.45678901234567890123, -9876543210987654321098765432109876543210987654321098765432109876543210987654, 'B'),
|
||||
(3, 0.000000000000001, 0.00000000000000000001, 0, 'C'),
|
||||
(4, 99999888887777766666555554444433333.999999999999999, 99999888887777766666555554444433333222221111100009999988.99999999999999999999, 9999988888777776666655555444443333322222111110000099999888877776666555544, 'A'),
|
||||
(5, -88888777776666655555444443333322222.888888888888888, -88888777776666655555444443333322222111110000099999888877.88888888888888888888, -8888877777666665555544444333332222211111000009999988888777766665555444433, 'B'),
|
||||
(6, 11111222223333344444555556666677777.111111111111111, 11111222223333344444555556666677777888889999900001111122.11111111111111111111, 1111122222333334444455555666667777788888999990000011111222233334444555566, 'C'),
|
||||
(7, -77777666665555544444333332222211111.777777777777777, -77777666665555544444333332222211111000009999988888777776.77777777777777777777, -7777766666555554444433333222221111100000999998888877777666655554444333322, 'A');
|
||||
-- result:
|
||||
-- !result
|
||||
SELECT
|
||||
'Test1_BASIC_STRING_CONVERSION' as test_name,
|
||||
id,
|
||||
d50_15,
|
||||
CAST(d50_15 AS STRING) as d50_as_string,
|
||||
CONCAT('Value: ', CAST(d50_15 AS STRING)) as formatted_d50,
|
||||
CONCAT('D50=', CAST(d50_15 AS STRING), ', D76=', CAST(d76_20 AS STRING)) as combined_string
|
||||
FROM decimal_string_test
|
||||
ORDER BY id;
|
||||
-- result:
|
||||
Test1_BASIC_STRING_CONVERSION 1 12345678901234567890123456789012345.123456789012345 12345678901234567890123456789012345.123456789012345 Value: 12345678901234567890123456789012345.123456789012345 D50=12345678901234567890123456789012345.123456789012345, D76=12345678901234567890123456789012345678901234567890123456.12345678901234567890
|
||||
Test1_BASIC_STRING_CONVERSION 2 -98765432109876543210987654321098765.456789012345678 -98765432109876543210987654321098765.456789012345678 Value: -98765432109876543210987654321098765.456789012345678 D50=-98765432109876543210987654321098765.456789012345678, D76=-98765432109876543210987654321098765432109876543210987654.45678901234567890123
|
||||
Test1_BASIC_STRING_CONVERSION 3 1E-15 0.000000000000001 Value: 0.000000000000001 D50=0.000000000000001, D76=0.00000000000000000001
|
||||
Test1_BASIC_STRING_CONVERSION 4 99999888887777766666555554444433333.999999999999999 99999888887777766666555554444433333.999999999999999 Value: 99999888887777766666555554444433333.999999999999999 D50=99999888887777766666555554444433333.999999999999999, D76=99999888887777766666555554444433333222221111100009999988.99999999999999999999
|
||||
Test1_BASIC_STRING_CONVERSION 5 -88888777776666655555444443333322222.888888888888888 -88888777776666655555444443333322222.888888888888888 Value: -88888777776666655555444443333322222.888888888888888 D50=-88888777776666655555444443333322222.888888888888888, D76=-88888777776666655555444443333322222111110000099999888877.88888888888888888888
|
||||
Test1_BASIC_STRING_CONVERSION 6 11111222223333344444555556666677777.111111111111111 11111222223333344444555556666677777.111111111111111 Value: 11111222223333344444555556666677777.111111111111111 D50=11111222223333344444555556666677777.111111111111111, D76=11111222223333344444555556666677777888889999900001111122.11111111111111111111
|
||||
Test1_BASIC_STRING_CONVERSION 7 -77777666665555544444333332222211111.777777777777777 -77777666665555544444333332222211111.777777777777777 Value: -77777666665555544444333332222211111.777777777777777 D50=-77777666665555544444333332222211111.777777777777777, D76=-77777666665555544444333332222211111000009999988888777776.77777777777777777777
|
||||
-- !result
|
||||
SELECT
|
||||
'Test2_STRING_LENGTH_TRUNCATION' as test_name,
|
||||
id,
|
||||
d76_0,
|
||||
CAST(d76_0 AS STRING) as d76_string,
|
||||
LENGTH(CAST(d76_0 AS STRING)) as string_length,
|
||||
LEFT(CAST(d76_0 AS STRING), 10) as left_10_chars,
|
||||
RIGHT(CAST(d76_0 AS STRING), 10) as right_10_chars,
|
||||
SUBSTR(CAST(d76_0 AS STRING), 1, 20) as first_20_chars
|
||||
FROM decimal_string_test
|
||||
ORDER BY id;
|
||||
-- result:
|
||||
Test2_STRING_LENGTH_TRUNCATION 1 1234567890123456789012345678901234567890123456789012345678901234567890123456 1234567890123456789012345678901234567890123456789012345678901234567890123456 76 1234567890 7890123456 12345678901234567890
|
||||
Test2_STRING_LENGTH_TRUNCATION 2 -9876543210987654321098765432109876543210987654321098765432109876543210987654 -9876543210987654321098765432109876543210987654321098765432109876543210987654 77 -987654321 3210987654 -9876543210987654321
|
||||
Test2_STRING_LENGTH_TRUNCATION 3 0 0 1 0 0 0
|
||||
Test2_STRING_LENGTH_TRUNCATION 4 9999988888777776666655555444443333322222111110000099999888877776666555544 9999988888777776666655555444443333322222111110000099999888877776666555544 73 9999988888 6666555544 99999888887777766666
|
||||
Test2_STRING_LENGTH_TRUNCATION 5 -8888877777666665555544444333332222211111000009999988888777766665555444433 -8888877777666665555544444333332222211111000009999988888777766665555444433 74 -888887777 5555444433 -8888877777666665555
|
||||
Test2_STRING_LENGTH_TRUNCATION 6 1111122222333334444455555666667777788888999990000011111222233334444555566 1111122222333334444455555666667777788888999990000011111222233334444555566 73 1111122222 4444555566 11111222223333344444
|
||||
Test2_STRING_LENGTH_TRUNCATION 7 -7777766666555554444433333222221111100000999998888877777666655554444333322 -7777766666555554444433333222221111100000999998888877777666655554444333322 74 -777776666 4444333322 -7777766666555554444
|
||||
-- !result
|
||||
SELECT
|
||||
'Test3_STRING_PATTERN_MATCHING' as test_name,
|
||||
id,
|
||||
d50_15,
|
||||
CAST(d50_15 AS STRING) as decimal_string,
|
||||
LOCATE('.', CAST(d50_15 AS STRING)) as decimal_point_position,
|
||||
LOCATE('-', CAST(d50_15 AS STRING)) as negative_sign_position,
|
||||
CASE WHEN CAST(d50_15 AS STRING) LIKE '%-%.%' THEN 'NEGATIVE_DECIMAL'
|
||||
WHEN CAST(d50_15 AS STRING) LIKE '%.%' THEN 'POSITIVE_DECIMAL'
|
||||
WHEN CAST(d50_15 AS STRING) LIKE '-%' THEN 'NEGATIVE_INTEGER'
|
||||
ELSE 'POSITIVE_INTEGER'
|
||||
END as number_type
|
||||
FROM decimal_string_test
|
||||
ORDER BY id;
|
||||
-- result:
|
||||
Test3_STRING_PATTERN_MATCHING 1 12345678901234567890123456789012345.123456789012345 12345678901234567890123456789012345.123456789012345 36 0 POSITIVE_DECIMAL
|
||||
Test3_STRING_PATTERN_MATCHING 2 -98765432109876543210987654321098765.456789012345678 -98765432109876543210987654321098765.456789012345678 37 1 NEGATIVE_DECIMAL
|
||||
Test3_STRING_PATTERN_MATCHING 3 1E-15 0.000000000000001 2 0 POSITIVE_DECIMAL
|
||||
Test3_STRING_PATTERN_MATCHING 4 99999888887777766666555554444433333.999999999999999 99999888887777766666555554444433333.999999999999999 36 0 POSITIVE_DECIMAL
|
||||
Test3_STRING_PATTERN_MATCHING 5 -88888777776666655555444443333322222.888888888888888 -88888777776666655555444443333322222.888888888888888 37 1 NEGATIVE_DECIMAL
|
||||
Test3_STRING_PATTERN_MATCHING 6 11111222223333344444555556666677777.111111111111111 11111222223333344444555556666677777.111111111111111 36 0 POSITIVE_DECIMAL
|
||||
Test3_STRING_PATTERN_MATCHING 7 -77777666665555544444333332222211111.777777777777777 -77777666665555544444333332222211111.777777777777777 37 1 NEGATIVE_DECIMAL
|
||||
-- !result
|
||||
SELECT
|
||||
'Test4_REGEX_OPERATIONS' as test_name,
|
||||
id,
|
||||
d76_20,
|
||||
CAST(d76_20 AS STRING) as decimal_string,
|
||||
REGEXP_EXTRACT(CAST(d76_20 AS STRING), '^(-?[0-9]+)', 1) as integer_part,
|
||||
REGEXP_EXTRACT(CAST(d76_20 AS STRING), '\\.([0-9]+)$', 1) as decimal_part,
|
||||
REGEXP_REPLACE(CAST(d76_20 AS STRING), '0+$', '') as trimmed_trailing_zeros,
|
||||
REGEXP_EXTRACT(CAST(d76_20 AS STRING), '^(-?[0-9]+\\.[0-9]{0,5})', 1) as first_5_decimal_places
|
||||
FROM decimal_string_test
|
||||
WHERE d76_20 != 0
|
||||
ORDER BY id;
|
||||
-- result:
|
||||
Test4_REGEX_OPERATIONS 1 12345678901234567890123456789012345678901234567890123456.12345678901234567890 12345678901234567890123456789012345678901234567890123456.12345678901234567890 12345678901234567890123456789012345678901234567890123456 12345678901234567890 12345678901234567890123456789012345678901234567890123456.1234567890123456789 12345678901234567890123456789012345678901234567890123456.12345
|
||||
Test4_REGEX_OPERATIONS 2 -98765432109876543210987654321098765432109876543210987654.45678901234567890123 -98765432109876543210987654321098765432109876543210987654.45678901234567890123 -98765432109876543210987654321098765432109876543210987654 45678901234567890123 -98765432109876543210987654321098765432109876543210987654.45678901234567890123 -98765432109876543210987654321098765432109876543210987654.45678
|
||||
Test4_REGEX_OPERATIONS 3 1E-20 0.00000000000000000001 0 00000000000000000001 0.00000000000000000001 0.00000
|
||||
Test4_REGEX_OPERATIONS 4 99999888887777766666555554444433333222221111100009999988.99999999999999999999 99999888887777766666555554444433333222221111100009999988.99999999999999999999 99999888887777766666555554444433333222221111100009999988 99999999999999999999 99999888887777766666555554444433333222221111100009999988.99999999999999999999 99999888887777766666555554444433333222221111100009999988.99999
|
||||
Test4_REGEX_OPERATIONS 5 -88888777776666655555444443333322222111110000099999888877.88888888888888888888 -88888777776666655555444443333322222111110000099999888877.88888888888888888888 -88888777776666655555444443333322222111110000099999888877 88888888888888888888 -88888777776666655555444443333322222111110000099999888877.88888888888888888888 -88888777776666655555444443333322222111110000099999888877.88888
|
||||
Test4_REGEX_OPERATIONS 6 11111222223333344444555556666677777888889999900001111122.11111111111111111111 11111222223333344444555556666677777888889999900001111122.11111111111111111111 11111222223333344444555556666677777888889999900001111122 11111111111111111111 11111222223333344444555556666677777888889999900001111122.11111111111111111111 11111222223333344444555556666677777888889999900001111122.11111
|
||||
Test4_REGEX_OPERATIONS 7 -77777666665555544444333332222211111000009999988888777776.77777777777777777777 -77777666665555544444333332222211111000009999988888777776.77777777777777777777 -77777666665555544444333332222211111000009999988888777776 77777777777777777777 -77777666665555544444333332222211111000009999988888777776.77777777777777777777 -77777666665555544444333332222211111000009999988888777776.77777
|
||||
-- !result
|
||||
SELECT
|
||||
'Test5_STRING_SPLITTING' as test_name,
|
||||
id,
|
||||
d50_15,
|
||||
CAST(d50_15 AS STRING) as original_string,
|
||||
SPLIT_PART(CAST(ABS(d50_15) AS STRING), '.', 1) as integer_part_split,
|
||||
SPLIT_PART(CAST(ABS(d50_15) AS STRING), '.', 2) as decimal_part_split,
|
||||
CASE WHEN d50_15 < 0 THEN '-' ELSE '+' END as sign_part
|
||||
FROM decimal_string_test
|
||||
ORDER BY id;
|
||||
-- result:
|
||||
Test5_STRING_SPLITTING 1 12345678901234567890123456789012345.123456789012345 12345678901234567890123456789012345.123456789012345 12345678901234567890123456789012345 123456789012345 +
|
||||
Test5_STRING_SPLITTING 2 -98765432109876543210987654321098765.456789012345678 -98765432109876543210987654321098765.456789012345678 98765432109876543210987654321098765 456789012345678 -
|
||||
Test5_STRING_SPLITTING 3 1E-15 0.000000000000001 0 000000000000001 +
|
||||
Test5_STRING_SPLITTING 4 99999888887777766666555554444433333.999999999999999 99999888887777766666555554444433333.999999999999999 99999888887777766666555554444433333 999999999999999 +
|
||||
Test5_STRING_SPLITTING 5 -88888777776666655555444443333322222.888888888888888 -88888777776666655555444443333322222.888888888888888 88888777776666655555444443333322222 888888888888888 -
|
||||
Test5_STRING_SPLITTING 6 11111222223333344444555556666677777.111111111111111 11111222223333344444555556666677777.111111111111111 11111222223333344444555556666677777 111111111111111 +
|
||||
Test5_STRING_SPLITTING 7 -77777666665555544444333332222211111.777777777777777 -77777666665555544444333332222211111.777777777777777 77777666665555544444333332222211111 777777777777777 -
|
||||
-- !result
|
||||
SELECT
|
||||
'Test6_STRING_FORMATTING' as test_name,
|
||||
id,
|
||||
d76_0,
|
||||
CAST(d76_0 AS STRING) as original_string,
|
||||
LPAD(CAST(ABS(d76_0) AS STRING), 80, '0') as zero_padded,
|
||||
RPAD(CAST(d76_0 AS STRING), 20, ' ') as space_padded
|
||||
FROM decimal_string_test
|
||||
ORDER BY id;
|
||||
-- result:
|
||||
Test6_STRING_FORMATTING 1 1234567890123456789012345678901234567890123456789012345678901234567890123456 1234567890123456789012345678901234567890123456789012345678901234567890123456 00001234567890123456789012345678901234567890123456789012345678901234567890123456 12345678901234567890
|
||||
Test6_STRING_FORMATTING 2 -9876543210987654321098765432109876543210987654321098765432109876543210987654 -9876543210987654321098765432109876543210987654321098765432109876543210987654 00009876543210987654321098765432109876543210987654321098765432109876543210987654 -9876543210987654321
|
||||
Test6_STRING_FORMATTING 3 0 0 00000000000000000000000000000000000000000000000000000000000000000000000000000000 0
|
||||
Test6_STRING_FORMATTING 4 9999988888777776666655555444443333322222111110000099999888877776666555544 9999988888777776666655555444443333322222111110000099999888877776666555544 00000009999988888777776666655555444443333322222111110000099999888877776666555544 99999888887777766666
|
||||
Test6_STRING_FORMATTING 5 -8888877777666665555544444333332222211111000009999988888777766665555444433 -8888877777666665555544444333332222211111000009999988888777766665555444433 00000008888877777666665555544444333332222211111000009999988888777766665555444433 -8888877777666665555
|
||||
Test6_STRING_FORMATTING 6 1111122222333334444455555666667777788888999990000011111222233334444555566 1111122222333334444455555666667777788888999990000011111222233334444555566 00000001111122222333334444455555666667777788888999990000011111222233334444555566 11111222223333344444
|
||||
Test6_STRING_FORMATTING 7 -7777766666555554444433333222221111100000999998888877777666655554444333322 -7777766666555554444433333222221111100000999998888877777666655554444333322 00000007777766666555554444433333222221111100000999998888877777666655554444333322 -7777766666555554444
|
||||
-- !result
|
||||
SELECT
|
||||
'Test7_CASE_SPECIAL_FORMATTING' as test_name,
|
||||
id,
|
||||
category,
|
||||
d50_15,
|
||||
UPPER(CONCAT(category, '_', CAST(d50_15 AS STRING))) as upper_formatted,
|
||||
LOWER(CONCAT(category, '_', CAST(d50_15 AS STRING))) as lower_formatted
|
||||
FROM decimal_string_test
|
||||
ORDER BY id;
|
||||
-- result:
|
||||
Test7_CASE_SPECIAL_FORMATTING 1 A 12345678901234567890123456789012345.123456789012345 A_12345678901234567890123456789012345.123456789012345 a_12345678901234567890123456789012345.123456789012345
|
||||
Test7_CASE_SPECIAL_FORMATTING 2 B -98765432109876543210987654321098765.456789012345678 B_-98765432109876543210987654321098765.456789012345678 b_-98765432109876543210987654321098765.456789012345678
|
||||
Test7_CASE_SPECIAL_FORMATTING 3 C 1E-15 C_0.000000000000001 c_0.000000000000001
|
||||
Test7_CASE_SPECIAL_FORMATTING 4 A 99999888887777766666555554444433333.999999999999999 A_99999888887777766666555554444433333.999999999999999 a_99999888887777766666555554444433333.999999999999999
|
||||
Test7_CASE_SPECIAL_FORMATTING 5 B -88888777776666655555444443333322222.888888888888888 B_-88888777776666655555444443333322222.888888888888888 b_-88888777776666655555444443333322222.888888888888888
|
||||
Test7_CASE_SPECIAL_FORMATTING 6 C 11111222223333344444555556666677777.111111111111111 C_11111222223333344444555556666677777.111111111111111 c_11111222223333344444555556666677777.111111111111111
|
||||
Test7_CASE_SPECIAL_FORMATTING 7 A -77777666665555544444333332222211111.777777777777777 A_-77777666665555544444333332222211111.777777777777777 a_-77777666665555544444333332222211111.777777777777777
|
||||
-- !result
|
||||
SELECT
|
||||
'Test8_COMPLEX_STRING_OPERATIONS' as test_name,
|
||||
id,
|
||||
d50_15,
|
||||
d76_20,
|
||||
d76_0,
|
||||
CONCAT_WS(' | ',
|
||||
CONCAT('D50: ', CAST(d50_15 AS STRING)),
|
||||
CONCAT('D76_20: ', CAST(d76_20 AS STRING)),
|
||||
CONCAT('D76_0: ', CAST(d76_0 AS STRING))
|
||||
) as pipe_separated,
|
||||
REPLACE(
|
||||
REPLACE(CAST(d50_15 AS STRING), '.', '_DOT_'),
|
||||
'-', '_MINUS_'
|
||||
) as symbol_replaced,
|
||||
REVERSE(CAST(ABS(d50_15) AS STRING)) as reversed_string
|
||||
FROM decimal_string_test
|
||||
ORDER BY id;
|
||||
-- result:
|
||||
Test8_COMPLEX_STRING_OPERATIONS 1 12345678901234567890123456789012345.123456789012345 12345678901234567890123456789012345678901234567890123456.12345678901234567890 1234567890123456789012345678901234567890123456789012345678901234567890123456 D50: 12345678901234567890123456789012345.123456789012345 | D76_20: 12345678901234567890123456789012345678901234567890123456.12345678901234567890 | D76_0: 1234567890123456789012345678901234567890123456789012345678901234567890123456 12345678901234567890123456789012345_DOT_123456789012345 543210987654321.54321098765432109876543210987654321
|
||||
Test8_COMPLEX_STRING_OPERATIONS 2 -98765432109876543210987654321098765.456789012345678 -98765432109876543210987654321098765432109876543210987654.45678901234567890123 -9876543210987654321098765432109876543210987654321098765432109876543210987654 D50: -98765432109876543210987654321098765.456789012345678 | D76_20: -98765432109876543210987654321098765432109876543210987654.45678901234567890123 | D76_0: -9876543210987654321098765432109876543210987654321098765432109876543210987654 _MINUS_98765432109876543210987654321098765_DOT_456789012345678 876543210987654.56789012345678901234567890123456789
|
||||
Test8_COMPLEX_STRING_OPERATIONS 3 1E-15 1E-20 0 D50: 0.000000000000001 | D76_20: 0.00000000000000000001 | D76_0: 0 0_DOT_000000000000001 100000000000000.0
|
||||
Test8_COMPLEX_STRING_OPERATIONS 4 99999888887777766666555554444433333.999999999999999 99999888887777766666555554444433333222221111100009999988.99999999999999999999 9999988888777776666655555444443333322222111110000099999888877776666555544 D50: 99999888887777766666555554444433333.999999999999999 | D76_20: 99999888887777766666555554444433333222221111100009999988.99999999999999999999 | D76_0: 9999988888777776666655555444443333322222111110000099999888877776666555544 99999888887777766666555554444433333_DOT_999999999999999 999999999999999.33333444445555566666777778888899999
|
||||
Test8_COMPLEX_STRING_OPERATIONS 5 -88888777776666655555444443333322222.888888888888888 -88888777776666655555444443333322222111110000099999888877.88888888888888888888 -8888877777666665555544444333332222211111000009999988888777766665555444433 D50: -88888777776666655555444443333322222.888888888888888 | D76_20: -88888777776666655555444443333322222111110000099999888877.88888888888888888888 | D76_0: -8888877777666665555544444333332222211111000009999988888777766665555444433 _MINUS_88888777776666655555444443333322222_DOT_888888888888888 888888888888888.22222333334444455555666667777788888
|
||||
Test8_COMPLEX_STRING_OPERATIONS 6 11111222223333344444555556666677777.111111111111111 11111222223333344444555556666677777888889999900001111122.11111111111111111111 1111122222333334444455555666667777788888999990000011111222233334444555566 D50: 11111222223333344444555556666677777.111111111111111 | D76_20: 11111222223333344444555556666677777888889999900001111122.11111111111111111111 | D76_0: 1111122222333334444455555666667777788888999990000011111222233334444555566 11111222223333344444555556666677777_DOT_111111111111111 111111111111111.77777666665555544444333332222211111
|
||||
Test8_COMPLEX_STRING_OPERATIONS 7 -77777666665555544444333332222211111.777777777777777 -77777666665555544444333332222211111000009999988888777776.77777777777777777777 -7777766666555554444433333222221111100000999998888877777666655554444333322 D50: -77777666665555544444333332222211111.777777777777777 | D76_20: -77777666665555544444333332222211111000009999988888777776.77777777777777777777 | D76_0: -7777766666555554444433333222221111100000999998888877777666655554444333322 _MINUS_77777666665555544444333332222211111_DOT_777777777777777 777777777777777.11111222223333344444555556666677777
|
||||
-- !result
|
||||
|
|
@ -0,0 +1,185 @@
|
|||
-- name: test_decimal256_subquery_cte
|
||||
DROP DATABASE IF EXISTS test_decimal256_subquery;
|
||||
-- result:
|
||||
-- !result
|
||||
CREATE DATABASE test_decimal256_subquery;
|
||||
-- result:
|
||||
-- !result
|
||||
USE test_decimal256_subquery;
|
||||
-- result:
|
||||
-- !result
|
||||
CREATE TABLE decimal_main_test (
|
||||
id INT,
|
||||
category VARCHAR(10),
|
||||
d50_15 DECIMAL(50,15),
|
||||
d76_20 DECIMAL(76,20)
|
||||
) PROPERTIES("replication_num"="1");
|
||||
-- result:
|
||||
-- !result
|
||||
CREATE TABLE decimal_secondary_test (
|
||||
id INT,
|
||||
ref_category VARCHAR(10),
|
||||
threshold_d50 DECIMAL(50,15),
|
||||
threshold_d76 DECIMAL(76,20)
|
||||
) PROPERTIES("replication_num"="1");
|
||||
-- result:
|
||||
-- !result
|
||||
INSERT INTO decimal_main_test VALUES
|
||||
(1, 'A', 12345678901234567890123456789012345.123456789012345, 12345678901234567890123456789012345678901234567890123456.12345678901234567890),
|
||||
(2, 'A', 98765432109876543210987654321098765.456789012345678, 98765432109876543210987654321098765432109876543210987654.45678901234567890123),
|
||||
(3, 'B', 55555555555555555555555555555555555.789012345678901, 55555555555555555555555555555555555555555555555555555555.78901234567890123456),
|
||||
(4, 'B', 77777777777777777777777777777777777.012345678901234, 77777777777777777777777777777777777777777777777777777777.01234567890123456789),
|
||||
(5, 'C', 44444444444444444444444444444444444.567890123456789, 44444444444444444444444444444444444444444444444444444444.56789012345678901234),
|
||||
(6, 'C', 88888888888888888888888888888888888.901234567890123, 88888888888888888888888888888888888888888888888888888888.90123456789012345678),
|
||||
(7, 'A', 11111111111111111111111111111111111.234567890123456, 11111111111111111111111111111111111111111111111111111111.23456789012345678901),
|
||||
(8, 'B', 22222222222222222222222222222222222.678901234567890, 22222222222222222222222222222222222222222222222222222222.67890123456789012345),
|
||||
(9, 'C', 99999999999999999999999999999999999.345678901234567, 99999999999999999999999999999999999999999999999999999999.34567890123456789012),
|
||||
(10, 'A', 66666666666666666666666666666666666.111111111111111, 66666666666666666666666666666666666666666666666666666666.11111111111111111111);
|
||||
-- result:
|
||||
-- !result
|
||||
INSERT INTO decimal_secondary_test VALUES
|
||||
(1, 'A', 50000000000000000000000000000000000.000000000000000, 50000000000000000000000000000000000000000000000000000000.00000000000000000000),
|
||||
(2, 'B', 60000000000000000000000000000000000.000000000000000, 60000000000000000000000000000000000000000000000000000000.00000000000000000000),
|
||||
(3, 'C', 70000000000000000000000000000000000.000000000000000, 70000000000000000000000000000000000000000000000000000000.00000000000000000000);
|
||||
-- result:
|
||||
-- !result
|
||||
SELECT
|
||||
'Test1_SCALAR_SUBQUERY_SELECT' as test_name,
|
||||
id,
|
||||
category,
|
||||
d50_15,
|
||||
(SELECT AVG(d50_15) FROM decimal_main_test) as overall_avg,
|
||||
d50_15 - (SELECT AVG(d50_15) FROM decimal_main_test) as diff_from_avg
|
||||
FROM decimal_main_test
|
||||
ORDER BY id;
|
||||
-- result:
|
||||
Test1_SCALAR_SUBQUERY_SELECT 1 A 12345678901234567890123456789012345.123456789012345 57777777767777777776777777777677777.622098765432209 -45432098866543209886654320988665432.498641976419864
|
||||
Test1_SCALAR_SUBQUERY_SELECT 2 A 98765432109876543210987654321098765.456789012345678 57777777767777777776777777777677777.622098765432209 40987654342098765434209876543420987.834690246913469
|
||||
Test1_SCALAR_SUBQUERY_SELECT 3 B 55555555555555555555555555555555555.789012345678901 57777777767777777776777777777677777.622098765432209 -2222222212222222221222222222122221.833086419753308
|
||||
Test1_SCALAR_SUBQUERY_SELECT 4 B 77777777777777777777777777777777777.012345678901234 57777777767777777776777777777677777.622098765432209 20000000010000000001000000000099999.390246913469025
|
||||
Test1_SCALAR_SUBQUERY_SELECT 5 C 44444444444444444444444444444444444.567890123456789 57777777767777777776777777777677777.622098765432209 -13333333323333333332333333333233333.054208641975420
|
||||
Test1_SCALAR_SUBQUERY_SELECT 6 C 88888888888888888888888888888888888.901234567890123 57777777767777777776777777777677777.622098765432209 31111111121111111112111111111211111.279135802457914
|
||||
Test1_SCALAR_SUBQUERY_SELECT 7 A 11111111111111111111111111111111111.234567890123456 57777777767777777776777777777677777.622098765432209 -46666666656666666665666666666566666.387530875308753
|
||||
Test1_SCALAR_SUBQUERY_SELECT 8 B 22222222222222222222222222222222222.678901234567890 57777777767777777776777777777677777.622098765432209 -35555555545555555554555555555455554.943197530864319
|
||||
Test1_SCALAR_SUBQUERY_SELECT 9 C 99999999999999999999999999999999999.345678901234567 57777777767777777776777777777677777.622098765432209 42222222232222222223222222222322221.723580135802358
|
||||
Test1_SCALAR_SUBQUERY_SELECT 10 A 66666666666666666666666666666666666.111111111111111 57777777767777777776777777777677777.622098765432209 8888888898888888889888888888988888.489012345678902
|
||||
-- !result
|
||||
SELECT
|
||||
'Test2_SCALAR_SUBQUERY_WHERE' as test_name,
|
||||
id,
|
||||
category,
|
||||
d50_15,
|
||||
d76_20
|
||||
FROM decimal_main_test
|
||||
WHERE d50_15 > (SELECT AVG(d50_15) FROM decimal_main_test)
|
||||
ORDER BY d50_15;
|
||||
-- result:
|
||||
Test2_SCALAR_SUBQUERY_WHERE 10 A 66666666666666666666666666666666666.111111111111111 66666666666666666666666666666666666666666666666666666666.11111111111111111111
|
||||
Test2_SCALAR_SUBQUERY_WHERE 4 B 77777777777777777777777777777777777.012345678901234 77777777777777777777777777777777777777777777777777777777.01234567890123456789
|
||||
Test2_SCALAR_SUBQUERY_WHERE 6 C 88888888888888888888888888888888888.901234567890123 88888888888888888888888888888888888888888888888888888888.90123456789012345678
|
||||
Test2_SCALAR_SUBQUERY_WHERE 2 A 98765432109876543210987654321098765.456789012345678 98765432109876543210987654321098765432109876543210987654.45678901234567890123
|
||||
Test2_SCALAR_SUBQUERY_WHERE 9 C 99999999999999999999999999999999999.345678901234567 99999999999999999999999999999999999999999999999999999999.34567890123456789012
|
||||
-- !result
|
||||
SELECT
|
||||
'Test3_EXISTS_SUBQUERY' as test_name,
|
||||
mt.id,
|
||||
mt.category,
|
||||
mt.d50_15
|
||||
FROM decimal_main_test mt
|
||||
WHERE EXISTS (
|
||||
SELECT 1 FROM decimal_secondary_test st
|
||||
WHERE st.ref_category = mt.category
|
||||
AND mt.d50_15 > st.threshold_d50
|
||||
)
|
||||
ORDER BY mt.id;
|
||||
-- result:
|
||||
Test3_EXISTS_SUBQUERY 2 A 98765432109876543210987654321098765.456789012345678
|
||||
Test3_EXISTS_SUBQUERY 4 B 77777777777777777777777777777777777.012345678901234
|
||||
Test3_EXISTS_SUBQUERY 6 C 88888888888888888888888888888888888.901234567890123
|
||||
Test3_EXISTS_SUBQUERY 9 C 99999999999999999999999999999999999.345678901234567
|
||||
Test3_EXISTS_SUBQUERY 10 A 66666666666666666666666666666666666.111111111111111
|
||||
-- !result
|
||||
SELECT
|
||||
'Test4_IN_SUBQUERY' as test_name,
|
||||
id,
|
||||
category,
|
||||
d76_20
|
||||
FROM decimal_main_test
|
||||
WHERE d76_20 IN (
|
||||
SELECT d76_20 FROM decimal_main_test
|
||||
WHERE category = 'A'
|
||||
AND d76_20 > 100.00000000000000000000
|
||||
)
|
||||
ORDER BY d76_20;
|
||||
-- result:
|
||||
Test4_IN_SUBQUERY 7 A 11111111111111111111111111111111111111111111111111111111.23456789012345678901
|
||||
Test4_IN_SUBQUERY 1 A 12345678901234567890123456789012345678901234567890123456.12345678901234567890
|
||||
Test4_IN_SUBQUERY 10 A 66666666666666666666666666666666666666666666666666666666.11111111111111111111
|
||||
Test4_IN_SUBQUERY 2 A 98765432109876543210987654321098765432109876543210987654.45678901234567890123
|
||||
-- !result
|
||||
WITH decimal_stats AS (
|
||||
SELECT
|
||||
category,
|
||||
AVG(d50_15) as avg_d50,
|
||||
AVG(d76_20) as avg_d76,
|
||||
COUNT(*) as cnt
|
||||
FROM decimal_main_test
|
||||
GROUP BY category
|
||||
)
|
||||
SELECT
|
||||
'Test6_BASIC_CTE' as test_name,
|
||||
ds.category,
|
||||
ds.avg_d50,
|
||||
ds.avg_d76,
|
||||
ds.cnt,
|
||||
mt.d50_15,
|
||||
mt.d50_15 - ds.avg_d50 as diff_from_cat_avg
|
||||
FROM decimal_stats ds
|
||||
JOIN decimal_main_test mt ON ds.category = mt.category
|
||||
ORDER BY ds.category, mt.d50_15;
|
||||
-- result:
|
||||
Test6_BASIC_CTE A 47222222197222222219722222221972221.981481200648148 47222222197222222219722222221972222222197222222219722221.98148120064814812006 4 11111111111111111111111111111111111.234567890123456 -36111111086111111108611111110861110.746913310524692
|
||||
Test6_BASIC_CTE A 47222222197222222219722222221972221.981481200648148 47222222197222222219722222221972222222197222222219722221.98148120064814812006 4 12345678901234567890123456789012345.123456789012345 -34876543295987654329598765432959876.858024411635803
|
||||
Test6_BASIC_CTE A 47222222197222222219722222221972221.981481200648148 47222222197222222219722222221972222222197222222219722221.98148120064814812006 4 66666666666666666666666666666666666.111111111111111 19444444469444444446944444444694444.129629910462963
|
||||
Test6_BASIC_CTE A 47222222197222222219722222221972221.981481200648148 47222222197222222219722222221972222222197222222219722221.98148120064814812006 4 98765432109876543210987654321098765.456789012345678 51543209912654320991265432099126543.475307811697530
|
||||
Test6_BASIC_CTE B 51851851851851851851851851851851851.826753086382675 51851851851851851851851851851851851851851851851851851851.82675308638267530863 3 22222222222222222222222222222222222.678901234567890 -29629629629629629629629629629629629.147851851814785
|
||||
Test6_BASIC_CTE B 51851851851851851851851851851851851.826753086382675 51851851851851851851851851851851851851851851851851851851.82675308638267530863 3 55555555555555555555555555555555555.789012345678901 3703703703703703703703703703703703.962259259296226
|
||||
Test6_BASIC_CTE B 51851851851851851851851851851851851.826753086382675 51851851851851851851851851851851851851851851851851851851.82675308638267530863 3 77777777777777777777777777777777777.012345678901234 25925925925925925925925925925925925.185592592518559
|
||||
Test6_BASIC_CTE C 77777777777777777777777777777777777.604934530860493 77777777777777777777777777777777777777777777777777777777.60493453086049345308 3 44444444444444444444444444444444444.567890123456789 -33333333333333333333333333333333333.037044407403704
|
||||
Test6_BASIC_CTE C 77777777777777777777777777777777777.604934530860493 77777777777777777777777777777777777777777777777777777777.60493453086049345308 3 88888888888888888888888888888888888.901234567890123 11111111111111111111111111111111111.296300037029630
|
||||
Test6_BASIC_CTE C 77777777777777777777777777777777777.604934530860493 77777777777777777777777777777777777777777777777777777777.60493453086049345308 3 99999999999999999999999999999999999.345678901234567 22222222222222222222222222222222221.740744370374074
|
||||
-- !result
|
||||
WITH category_stats AS (
|
||||
SELECT
|
||||
category,
|
||||
SUM(d50_15) as total_d50,
|
||||
MAX(d76_20) as max_d76
|
||||
FROM decimal_main_test
|
||||
GROUP BY category
|
||||
),
|
||||
threshold_data AS (
|
||||
SELECT
|
||||
ref_category,
|
||||
AVG(threshold_d50) as avg_threshold
|
||||
FROM decimal_secondary_test
|
||||
GROUP BY ref_category
|
||||
)
|
||||
SELECT
|
||||
'Test8_MULTIPLE_CTE' as test_name,
|
||||
cs.category,
|
||||
cs.total_d50,
|
||||
cs.max_d76,
|
||||
td.avg_threshold,
|
||||
CASE
|
||||
WHEN cs.total_d50 > td.avg_threshold * 3 THEN 'HIGH'
|
||||
WHEN cs.total_d50 > td.avg_threshold THEN 'MEDIUM'
|
||||
ELSE 'LOW'
|
||||
END as performance_level
|
||||
FROM category_stats cs
|
||||
LEFT JOIN threshold_data td ON cs.category = td.ref_category
|
||||
ORDER BY cs.category;
|
||||
-- result:
|
||||
Test8_MULTIPLE_CTE A 188888888788888888878888888887888887.925924802592590 98765432109876543210987654321098765432109876543210987654.45678901234567890123 50000000000000000000000000000000000.000000000000000 HIGH
|
||||
Test8_MULTIPLE_CTE B 155555555555555555555555555555555555.480259259148025 77777777777777777777777777777777777777777777777777777777.01234567890123456789 60000000000000000000000000000000000.000000000000000 MEDIUM
|
||||
Test8_MULTIPLE_CTE C 233333333333333333333333333333333332.814803592581479 99999999999999999999999999999999999999999999999999999999.34567890123456789012 70000000000000000000000000000000000.000000000000000 HIGH
|
||||
-- !result
|
||||
|
|
@ -0,0 +1,181 @@
|
|||
-- name: test_decimal256_window_functions
|
||||
DROP DATABASE IF EXISTS test_decimal256_window;
|
||||
-- result:
|
||||
-- !result
|
||||
CREATE DATABASE test_decimal256_window;
|
||||
-- result:
|
||||
-- !result
|
||||
USE test_decimal256_window;
|
||||
-- result:
|
||||
-- !result
|
||||
CREATE TABLE decimal_window_test (
|
||||
id INT,
|
||||
category VARCHAR(10),
|
||||
d50_15 DECIMAL(50,15), -- 35 integer digits + 15 decimal digits
|
||||
d76_20 DECIMAL(76,20), -- 56 integer digits + 20 decimal digits
|
||||
d76_0 DECIMAL(76,0) -- 76 integer digits + 0 decimal digits
|
||||
) PROPERTIES("replication_num"="1");
|
||||
-- result:
|
||||
-- !result
|
||||
INSERT INTO decimal_window_test VALUES
|
||||
(1, 'A', 12345678901234567890123456789012345.123456789012345, 12345678901234567890123456789012345678901234567890123456.12345678901234567890, 1234567890123456789012345678901234567890123456789012345678901234567890123456),
|
||||
(2, 'A', 98765432109876543210987654321098765.456789012345678, 98765432109876543210987654321098765432109876543210987654.45678901234567890123, 9876543210987654321098765432109876543210987654321098765432109876543210987654),
|
||||
(3, 'A', 55555555555555555555555555555555555.789012345678901, 55555555555555555555555555555555555555555555555555555555.78901234567890123456, 5555555555555555555555555555555555555555555555555555555555555555555555555555),
|
||||
(4, 'A', 66666666666666666666666666666666666.111111111111111, 66666666666666666666666666666666666666666666666666666666.11111111111111111111, 6666666666666666666666666666666666666666666666666666666666666666666666666666),
|
||||
|
||||
(5, 'B', 77777777777777777777777777777777777.012345678901234, 77777777777777777777777777777777777777777777777777777777.01234567890123456789, 7777777777777777777777777777777777777777777777777777777777777777777777777777),
|
||||
(6, 'B', 44444444444444444444444444444444444.567890123456789, 44444444444444444444444444444444444444444444444444444444.56789012345678901234, 4444444444444444444444444444444444444444444444444444444444444444444444444444),
|
||||
(7, 'B', 88888888888888888888888888888888888.901234567890123, 88888888888888888888888888888888888888888888888888888888.90123456789012345678, 8888888888888888888888888888888888888888888888888888888888888888888888888888),
|
||||
(8, 'B', 33333333333333333333333333333333333.222222222222222, 33333333333333333333333333333333333333333333333333333333.22222222222222222222, 3333333333333333333333333333333333333333333333333333333333333333333333333333),
|
||||
|
||||
(9, 'C', 11111111111111111111111111111111111.234567890123456, 11111111111111111111111111111111111111111111111111111111.23456789012345678901, 1111111111111111111111111111111111111111111111111111111111111111111111111111),
|
||||
(10, 'C', 22222222222222222222222222222222222.678901234567890, 22222222222222222222222222222222222222222222222222222222.67890123456789012345, 2222222222222222222222222222222222222222222222222222222222222222222222222222),
|
||||
(11, 'C', 99999888887777766666555554444433333.345678901234567, 99999888887777766666555554444433333222221111100009999988.34567890123456789012, 9999988888777776666655555444443333322222111110000099999888877776666555544),
|
||||
(12, 'C', 77777666665555544444333332222211111.777777777777777, 77777666665555544444333332222211111000009999988888777776.77777777777777777777, 7777766666555554444433333222221111100000999998888877777666655554444333322);
|
||||
-- result:
|
||||
-- !result
|
||||
SELECT
|
||||
'Test1_RANKING_FUNCTIONS' as test_name,
|
||||
id,
|
||||
category,
|
||||
d50_15,
|
||||
ROW_NUMBER() OVER (ORDER BY d50_15) as row_num,
|
||||
RANK() OVER (ORDER BY d50_15) as rank_val,
|
||||
DENSE_RANK() OVER (ORDER BY d50_15) as dense_rank_val
|
||||
FROM decimal_window_test
|
||||
ORDER BY d50_15;
|
||||
-- result:
|
||||
Test1_RANKING_FUNCTIONS 9 C 11111111111111111111111111111111111.234567890123456 1 1 1
|
||||
Test1_RANKING_FUNCTIONS 1 A 12345678901234567890123456789012345.123456789012345 2 2 2
|
||||
Test1_RANKING_FUNCTIONS 10 C 22222222222222222222222222222222222.678901234567890 3 3 3
|
||||
Test1_RANKING_FUNCTIONS 8 B 33333333333333333333333333333333333.222222222222222 4 4 4
|
||||
Test1_RANKING_FUNCTIONS 6 B 44444444444444444444444444444444444.567890123456789 5 5 5
|
||||
Test1_RANKING_FUNCTIONS 3 A 55555555555555555555555555555555555.789012345678901 6 6 6
|
||||
Test1_RANKING_FUNCTIONS 4 A 66666666666666666666666666666666666.111111111111111 7 7 7
|
||||
Test1_RANKING_FUNCTIONS 12 C 77777666665555544444333332222211111.777777777777777 8 8 8
|
||||
Test1_RANKING_FUNCTIONS 5 B 77777777777777777777777777777777777.012345678901234 9 9 9
|
||||
Test1_RANKING_FUNCTIONS 7 B 88888888888888888888888888888888888.901234567890123 10 10 10
|
||||
Test1_RANKING_FUNCTIONS 2 A 98765432109876543210987654321098765.456789012345678 11 11 11
|
||||
Test1_RANKING_FUNCTIONS 11 C 99999888887777766666555554444433333.345678901234567 12 12 12
|
||||
-- !result
|
||||
SELECT
|
||||
'Test2_PARTITION_RANKING' as test_name,
|
||||
id,
|
||||
category,
|
||||
d76_20,
|
||||
ROW_NUMBER() OVER (PARTITION BY category ORDER BY d76_20) as row_num_by_cat,
|
||||
RANK() OVER (PARTITION BY category ORDER BY d76_20) as rank_by_cat
|
||||
FROM decimal_window_test
|
||||
ORDER BY category, d76_20;
|
||||
-- result:
|
||||
Test2_PARTITION_RANKING 1 A 12345678901234567890123456789012345678901234567890123456.12345678901234567890 1 1
|
||||
Test2_PARTITION_RANKING 3 A 55555555555555555555555555555555555555555555555555555555.78901234567890123456 2 2
|
||||
Test2_PARTITION_RANKING 4 A 66666666666666666666666666666666666666666666666666666666.11111111111111111111 3 3
|
||||
Test2_PARTITION_RANKING 2 A 98765432109876543210987654321098765432109876543210987654.45678901234567890123 4 4
|
||||
Test2_PARTITION_RANKING 8 B 33333333333333333333333333333333333333333333333333333333.22222222222222222222 1 1
|
||||
Test2_PARTITION_RANKING 6 B 44444444444444444444444444444444444444444444444444444444.56789012345678901234 2 2
|
||||
Test2_PARTITION_RANKING 5 B 77777777777777777777777777777777777777777777777777777777.01234567890123456789 3 3
|
||||
Test2_PARTITION_RANKING 7 B 88888888888888888888888888888888888888888888888888888888.90123456789012345678 4 4
|
||||
Test2_PARTITION_RANKING 9 C 11111111111111111111111111111111111111111111111111111111.23456789012345678901 1 1
|
||||
Test2_PARTITION_RANKING 10 C 22222222222222222222222222222222222222222222222222222222.67890123456789012345 2 2
|
||||
Test2_PARTITION_RANKING 12 C 77777666665555544444333332222211111000009999988888777776.77777777777777777777 3 3
|
||||
Test2_PARTITION_RANKING 11 C 99999888887777766666555554444433333222221111100009999988.34567890123456789012 4 4
|
||||
-- !result
|
||||
SELECT
|
||||
'Test3_WINDOW_AGGREGATES' as test_name,
|
||||
id,
|
||||
category,
|
||||
d50_15,
|
||||
SUM(d50_15) OVER (ORDER BY id ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) as moving_sum,
|
||||
AVG(d50_15) OVER (PARTITION BY category ORDER BY id) as running_avg_by_cat,
|
||||
COUNT(*) OVER (PARTITION BY category) as count_by_cat,
|
||||
MAX(d76_0) OVER (PARTITION BY category ORDER BY id ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) as running_max
|
||||
FROM decimal_window_test
|
||||
ORDER BY id;
|
||||
-- result:
|
||||
Test3_WINDOW_AGGREGATES 1 A 12345678901234567890123456789012345.123456789012345 111111111011111111101111111110111110.580245801358023 12345678901234567890123456789012345.123456789012345 4 1234567890123456789012345678901234567890123456789012345678901234567890123456
|
||||
Test3_WINDOW_AGGREGATES 2 A 98765432109876543210987654321098765.456789012345678 166666666566666666656666666665666666.369258147036924 55555555505555555550555555555055555.290122900679012 4 9876543210987654321098765432109876543210987654321098765432109876543210987654
|
||||
Test3_WINDOW_AGGREGATES 3 A 55555555555555555555555555555555555.789012345678901 220987654332098765433209876543320987.356912469135690 55555555522222222218888888888555555.456419382345641 4 9876543210987654321098765432109876543210987654321098765432109876543210987654
|
||||
Test3_WINDOW_AGGREGATES 4 A 66666666666666666666666666666666666.111111111111111 199999999999999999999999999999999998.912469135691246 58333333308333333330833333333083333.120092314537009 4 9876543210987654321098765432109876543210987654321098765432109876543210987654
|
||||
Test3_WINDOW_AGGREGATES 5 B 77777777777777777777777777777777777.012345678901234 188888888888888888888888888888888887.691346913469134 77777777777777777777777777777777777.012345678901234 4 7777777777777777777777777777777777777777777777777777777777777777777777777777
|
||||
Test3_WINDOW_AGGREGATES 6 B 44444444444444444444444444444444444.567890123456789 211111111111111111111111111111111110.481470370248146 61111111111111111111111111111111110.790117901179012 4 7777777777777777777777777777777777777777777777777777777777777777777777777777
|
||||
Test3_WINDOW_AGGREGATES 7 B 88888888888888888888888888888888888.901234567890123 166666666666666666666666666666666666.691346913569134 70370370370370370370370370370370370.160490123416049 4 8888888888888888888888888888888888888888888888888888888888888888888888888888
|
||||
Test3_WINDOW_AGGREGATES 8 B 33333333333333333333333333333333333.222222222222222 133333333333333333333333333333333333.358024680235801 61111111111111111111111111111111110.925923148117592 4 8888888888888888888888888888888888888888888888888888888888888888888888888888
|
||||
Test3_WINDOW_AGGREGATES 9 C 11111111111111111111111111111111111.234567890123456 66666666666666666666666666666666667.135691346913568 11111111111111111111111111111111111.234567890123456 4 1111111111111111111111111111111111111111111111111111111111111111111111111111
|
||||
Test3_WINDOW_AGGREGATES 10 C 22222222222222222222222222222222222.678901234567890 133333222221111099999888887777766667.259148025925913 16666666666666666666666666666666666.956734562345673 4 2222222222222222222222222222222222222222222222222222222222222222222222222222
|
||||
Test3_WINDOW_AGGREGATES 11 C 99999888887777766666555554444433333.345678901234567 199999777775555533333111108888866667.802357913580234 44444407407037033333296295925922222.419716008641971 4 2222222222222222222222222222222222222222222222222222222222222222222222222222
|
||||
Test3_WINDOW_AGGREGATES 12 C 77777666665555544444333332222211111.777777777777777 177777555553333311110888886666644445.123456679012344 52777722221666661111055554999994444.759231450925923 4 2222222222222222222222222222222222222222222222222222222222222222222222222222
|
||||
-- !result
|
||||
SELECT
|
||||
'Test4_LEAD_LAG' as test_name,
|
||||
id,
|
||||
category,
|
||||
d76_20,
|
||||
LAG(d76_20, 1) OVER (ORDER BY d76_20) as prev_val,
|
||||
LEAD(d76_20, 1) OVER (ORDER BY d76_20) as next_val,
|
||||
LAG(d76_20, 1, 0.0) OVER (PARTITION BY category ORDER BY d76_20) as prev_val_by_cat,
|
||||
LEAD(d76_20, 1, 0.0) OVER (PARTITION BY category ORDER BY d76_20) as next_val_by_cat
|
||||
FROM decimal_window_test
|
||||
ORDER BY d76_20;
|
||||
-- result:
|
||||
Test4_LEAD_LAG 9 C 11111111111111111111111111111111111111111111111111111111.23456789012345678901 None 12345678901234567890123456789012345678901234567890123456.12345678901234567890 0E-20 22222222222222222222222222222222222222222222222222222222.67890123456789012345
|
||||
Test4_LEAD_LAG 1 A 12345678901234567890123456789012345678901234567890123456.12345678901234567890 11111111111111111111111111111111111111111111111111111111.23456789012345678901 22222222222222222222222222222222222222222222222222222222.67890123456789012345 0E-20 55555555555555555555555555555555555555555555555555555555.78901234567890123456
|
||||
Test4_LEAD_LAG 10 C 22222222222222222222222222222222222222222222222222222222.67890123456789012345 12345678901234567890123456789012345678901234567890123456.12345678901234567890 33333333333333333333333333333333333333333333333333333333.22222222222222222222 11111111111111111111111111111111111111111111111111111111.23456789012345678901 77777666665555544444333332222211111000009999988888777776.77777777777777777777
|
||||
Test4_LEAD_LAG 8 B 33333333333333333333333333333333333333333333333333333333.22222222222222222222 22222222222222222222222222222222222222222222222222222222.67890123456789012345 44444444444444444444444444444444444444444444444444444444.56789012345678901234 0E-20 44444444444444444444444444444444444444444444444444444444.56789012345678901234
|
||||
Test4_LEAD_LAG 6 B 44444444444444444444444444444444444444444444444444444444.56789012345678901234 33333333333333333333333333333333333333333333333333333333.22222222222222222222 55555555555555555555555555555555555555555555555555555555.78901234567890123456 33333333333333333333333333333333333333333333333333333333.22222222222222222222 77777777777777777777777777777777777777777777777777777777.01234567890123456789
|
||||
Test4_LEAD_LAG 3 A 55555555555555555555555555555555555555555555555555555555.78901234567890123456 44444444444444444444444444444444444444444444444444444444.56789012345678901234 66666666666666666666666666666666666666666666666666666666.11111111111111111111 12345678901234567890123456789012345678901234567890123456.12345678901234567890 66666666666666666666666666666666666666666666666666666666.11111111111111111111
|
||||
Test4_LEAD_LAG 4 A 66666666666666666666666666666666666666666666666666666666.11111111111111111111 55555555555555555555555555555555555555555555555555555555.78901234567890123456 77777666665555544444333332222211111000009999988888777776.77777777777777777777 55555555555555555555555555555555555555555555555555555555.78901234567890123456 98765432109876543210987654321098765432109876543210987654.45678901234567890123
|
||||
Test4_LEAD_LAG 12 C 77777666665555544444333332222211111000009999988888777776.77777777777777777777 66666666666666666666666666666666666666666666666666666666.11111111111111111111 77777777777777777777777777777777777777777777777777777777.01234567890123456789 22222222222222222222222222222222222222222222222222222222.67890123456789012345 99999888887777766666555554444433333222221111100009999988.34567890123456789012
|
||||
Test4_LEAD_LAG 5 B 77777777777777777777777777777777777777777777777777777777.01234567890123456789 77777666665555544444333332222211111000009999988888777776.77777777777777777777 88888888888888888888888888888888888888888888888888888888.90123456789012345678 44444444444444444444444444444444444444444444444444444444.56789012345678901234 88888888888888888888888888888888888888888888888888888888.90123456789012345678
|
||||
Test4_LEAD_LAG 7 B 88888888888888888888888888888888888888888888888888888888.90123456789012345678 77777777777777777777777777777777777777777777777777777777.01234567890123456789 98765432109876543210987654321098765432109876543210987654.45678901234567890123 77777777777777777777777777777777777777777777777777777777.01234567890123456789 0E-20
|
||||
Test4_LEAD_LAG 2 A 98765432109876543210987654321098765432109876543210987654.45678901234567890123 88888888888888888888888888888888888888888888888888888888.90123456789012345678 99999888887777766666555554444433333222221111100009999988.34567890123456789012 66666666666666666666666666666666666666666666666666666666.11111111111111111111 0E-20
|
||||
Test4_LEAD_LAG 11 C 99999888887777766666555554444433333222221111100009999988.34567890123456789012 98765432109876543210987654321098765432109876543210987654.45678901234567890123 None 77777666665555544444333332222211111000009999988888777776.77777777777777777777 0E-20
|
||||
-- !result
|
||||
SELECT
|
||||
'Test5_FIRST_LAST_VALUE' as test_name,
|
||||
id,
|
||||
category,
|
||||
d76_0,
|
||||
FIRST_VALUE(d76_0) OVER (PARTITION BY category ORDER BY d76_0) as first_val_by_cat,
|
||||
LAST_VALUE(d76_0) OVER (PARTITION BY category ORDER BY d76_0 ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) as last_val_by_cat,
|
||||
FIRST_VALUE(d50_15) OVER (ORDER BY id ROWS BETWEEN CURRENT ROW AND 2 FOLLOWING) as first_val_window
|
||||
FROM decimal_window_test
|
||||
ORDER BY category, d76_0;
|
||||
-- result:
|
||||
Test5_FIRST_LAST_VALUE 1 A 1234567890123456789012345678901234567890123456789012345678901234567890123456 1234567890123456789012345678901234567890123456789012345678901234567890123456 9876543210987654321098765432109876543210987654321098765432109876543210987654 12345678901234567890123456789012345.123456789012345
|
||||
Test5_FIRST_LAST_VALUE 3 A 5555555555555555555555555555555555555555555555555555555555555555555555555555 1234567890123456789012345678901234567890123456789012345678901234567890123456 9876543210987654321098765432109876543210987654321098765432109876543210987654 55555555555555555555555555555555555.789012345678901
|
||||
Test5_FIRST_LAST_VALUE 4 A 6666666666666666666666666666666666666666666666666666666666666666666666666666 1234567890123456789012345678901234567890123456789012345678901234567890123456 9876543210987654321098765432109876543210987654321098765432109876543210987654 66666666666666666666666666666666666.111111111111111
|
||||
Test5_FIRST_LAST_VALUE 2 A 9876543210987654321098765432109876543210987654321098765432109876543210987654 1234567890123456789012345678901234567890123456789012345678901234567890123456 9876543210987654321098765432109876543210987654321098765432109876543210987654 98765432109876543210987654321098765.456789012345678
|
||||
Test5_FIRST_LAST_VALUE 8 B 3333333333333333333333333333333333333333333333333333333333333333333333333333 3333333333333333333333333333333333333333333333333333333333333333333333333333 8888888888888888888888888888888888888888888888888888888888888888888888888888 33333333333333333333333333333333333.222222222222222
|
||||
Test5_FIRST_LAST_VALUE 6 B 4444444444444444444444444444444444444444444444444444444444444444444444444444 3333333333333333333333333333333333333333333333333333333333333333333333333333 8888888888888888888888888888888888888888888888888888888888888888888888888888 44444444444444444444444444444444444.567890123456789
|
||||
Test5_FIRST_LAST_VALUE 5 B 7777777777777777777777777777777777777777777777777777777777777777777777777777 3333333333333333333333333333333333333333333333333333333333333333333333333333 8888888888888888888888888888888888888888888888888888888888888888888888888888 77777777777777777777777777777777777.012345678901234
|
||||
Test5_FIRST_LAST_VALUE 7 B 8888888888888888888888888888888888888888888888888888888888888888888888888888 3333333333333333333333333333333333333333333333333333333333333333333333333333 8888888888888888888888888888888888888888888888888888888888888888888888888888 88888888888888888888888888888888888.901234567890123
|
||||
Test5_FIRST_LAST_VALUE 12 C 7777766666555554444433333222221111100000999998888877777666655554444333322 7777766666555554444433333222221111100000999998888877777666655554444333322 2222222222222222222222222222222222222222222222222222222222222222222222222222 77777666665555544444333332222211111.777777777777777
|
||||
Test5_FIRST_LAST_VALUE 11 C 9999988888777776666655555444443333322222111110000099999888877776666555544 7777766666555554444433333222221111100000999998888877777666655554444333322 2222222222222222222222222222222222222222222222222222222222222222222222222222 99999888887777766666555554444433333.345678901234567
|
||||
Test5_FIRST_LAST_VALUE 9 C 1111111111111111111111111111111111111111111111111111111111111111111111111111 7777766666555554444433333222221111100000999998888877777666655554444333322 2222222222222222222222222222222222222222222222222222222222222222222222222222 11111111111111111111111111111111111.234567890123456
|
||||
Test5_FIRST_LAST_VALUE 10 C 2222222222222222222222222222222222222222222222222222222222222222222222222222 7777766666555554444433333222221111100000999998888877777666655554444333322 2222222222222222222222222222222222222222222222222222222222222222222222222222 22222222222222222222222222222222222.678901234567890
|
||||
-- !result
|
||||
SELECT
|
||||
'Test6_COMPLEX_WINDOW' as test_name,
|
||||
id,
|
||||
category,
|
||||
d50_15,
|
||||
d76_20,
|
||||
SUM(d50_15 * d76_20) OVER (PARTITION BY category ORDER BY id) as running_product_sum,
|
||||
AVG(d50_15 + d76_20) OVER (ORDER BY id ROWS BETWEEN 2 PRECEDING AND 2 FOLLOWING) as moving_sum_avg
|
||||
FROM decimal_window_test
|
||||
ORDER BY id;
|
||||
-- result:
|
||||
Test6_COMPLEX_WINDOW 1 A 12345678901234567890123456789012345.123456789012345 12345678901234567890123456789012345678901234567890123456.12345678901234567890 None 55555555522222222218944444444077777777741111111107444444.24617209802461660490
|
||||
Test6_COMPLEX_WINDOW 2 A 98765432109876543210987654321098765.456789012345678 98765432109876543210987654321098765432109876543210987654.45678901234567890123 None 58333333308333333330891666666391666666639166666663916666.24018462907401798145
|
||||
Test6_COMPLEX_WINDOW 3 A 55555555555555555555555555555555555.789012345678901 55555555555555555555555555555555555555555555555555555555.78901234567890123456 None 62222222202222222220284444444224444444422444444442244443.79708597481970809874
|
||||
Test6_COMPLEX_WINDOW 4 A 66666666666666666666666666666666666.111111111111111 66666666666666666666666666666666666666666666666666666666.11111111111111111111 None 68641975310864197531155061728419506172841950617284195061.37485930859748556543
|
||||
Test6_COMPLEX_WINDOW 5 B 77777777777777777777777777777777777.012345678901234 77777777777777777777777777777777777777777777777777777777.01234567890123456789 None 66666666666666666666733333333333333333333333333333333332.95263753081526347654
|
||||
Test6_COMPLEX_WINDOW 6 B 44444444444444444444444444444444444.567890123456789 44444444444444444444444444444444444444444444444444444444.56789012345678901234 None 62222222222222222222284444444444444444444444444444444443.92592148143259187407
|
||||
Test6_COMPLEX_WINDOW 7 B 88888888888888888888888888888888888.901234567890123 88888888888888888888888888888888888888888888888888888888.90123456789012345678 None 51111111111111111111162222222222222222222222222222222221.97530419303753000965
|
||||
Test6_COMPLEX_WINDOW 8 B 33333333333333333333333333333333333.222222222222222 33333333333333333333333333333333333333333333333333333333.22222222222222222222 None 40000000000000000000040000000000000000000000000000000000.24192641530419232076
|
||||
Test6_COMPLEX_WINDOW 9 C 11111111111111111111111111111111111.234567890123456 11111111111111111111111111111111111111111111111111111111.23456789012345678901 None 51111088888666664444473333088886444419999755553113108886.75304192641530369632
|
||||
Test6_COMPLEX_WINDOW 10 C 22222222222222222222222222222222222.678901234567890 22222222222222222222222222222222222222222222222222222222.67890123456789012345 None 48888844443999995555559999511106222173335066661779751108.90365921037036536051
|
||||
Test6_COMPLEX_WINDOW 11 C 99999888887777766666555554444433333.345678901234567 99999888887777766666555554444433333222221111100009999988.34567890123456789012 None 52777722221666661111108332722216111050002166660558022219.51846290185184564509
|
||||
Test6_COMPLEX_WINDOW 12 C 77777666665555544444333332222211111.777777777777777 77777666665555544444333332222211111000009999988888777776.77777777777777777777 None 66666592591851844444437036222214073992595481473336622218.53490527572015659711
|
||||
-- !result
|
||||
|
|
@ -0,0 +1,232 @@
|
|||
-- name: test_decimal256_partitioned_tables
|
||||
DROP DATABASE IF EXISTS test_decimal256_partition;
|
||||
CREATE DATABASE test_decimal256_partition;
|
||||
USE test_decimal256_partition;
|
||||
|
||||
-- =============================================================================
|
||||
-- Part 1: Range partitioned table with decimal256
|
||||
-- =============================================================================
|
||||
|
||||
-- Create range partitioned table using decimal256 column
|
||||
CREATE TABLE decimal_range_partition (
|
||||
id BIGINT,
|
||||
transaction_date DATE,
|
||||
amount DECIMAL(50,15),
|
||||
balance DECIMAL(76,20),
|
||||
account_type VARCHAR(20)
|
||||
)
|
||||
DUPLICATE KEY(id, transaction_date)
|
||||
PARTITION BY RANGE(transaction_date) (
|
||||
PARTITION p202401 VALUES [('2024-01-01'), ('2024-02-01')),
|
||||
PARTITION p202402 VALUES [('2024-02-01'), ('2024-03-01')),
|
||||
PARTITION p202403 VALUES [('2024-03-01'), ('2024-04-01')),
|
||||
PARTITION p202404 VALUES [('2024-04-01'), ('2024-05-01'))
|
||||
)
|
||||
DISTRIBUTED BY HASH(id) BUCKETS 3
|
||||
PROPERTIES (
|
||||
"replication_num" = "1"
|
||||
);
|
||||
|
||||
-- Insert test data across different partitions - using decimal256 values beyond decimal128 range
|
||||
INSERT INTO decimal_range_partition VALUES
|
||||
-- Partition p202401
|
||||
(1, '2024-01-15', 12345678901234567890123456789012345.123456789012345, 12345678901234567890123456789012345678901234567890123456.12345678901234567890, 'SAVINGS'),
|
||||
(2, '2024-01-20', -55555555555555555555555555555555555.987654321098765, 55555555555555555555555555555555555555555555555555555555.13579246801357924680, 'CHECKING'),
|
||||
(3, '2024-01-25', 98765432109876543210987654321098765.555555555555555, 98765432109876543210987654321098765432109876543210987654.99999999999999999999, 'INVESTMENT'),
|
||||
|
||||
-- Partition p202402
|
||||
(4, '2024-02-10', 77777777777777777777777777777777777.777777777777777, 77777777777777777777777777777777777777777777777777777777.77777777777777777777, 'SAVINGS'),
|
||||
(5, '2024-02-15', -44444444444444444444444444444444444.111111111111111, 44444444444444444444444444444444444444444444444444444444.66666666666666666666, 'CHECKING'),
|
||||
(6, '2024-02-28', 88888888888888888888888888888888888.999999999999999, 88888888888888888888888888888888888888888888888888888888.65432109876543210987, 'INVESTMENT'),
|
||||
|
||||
-- Partition p202403
|
||||
(7, '2024-03-05', 11111111111111111111111111111111111.250000000000000, 11111111111111111111111111111111111111111111111111111111.90400000000000000000, 'SAVINGS'),
|
||||
(8, '2024-03-12', -22222222222222222222222222222222222.125000000000000, 22222222222222222222222222222222222222222222222222222222.77900000000000000000, 'CHECKING'),
|
||||
(9, '2024-03-25', 99999888887777766666555554444433333.000000000000001, 99999888887777766666555554444433333222221111100009999988.77900000000000000001, 'INVESTMENT'),
|
||||
|
||||
-- Partition p202404
|
||||
(10, '2024-04-08', 33333333333333333333333333333333333.888888888888888, 33333333333333333333333333333333333333333333333333333333.66788888888888888889, 'SAVINGS'),
|
||||
(11, '2024-04-15', -66666666666666666666666666666666666.333333333333333, 66666666666666666666666666666666666666666666666666666666.33455555555555555556, 'CHECKING'),
|
||||
(12, '2024-04-30', 77777666665555544444333332222211111.000000000000000, 77777666665555544444333332222211111000009999988888777776.33455555555555555556, 'INVESTMENT');
|
||||
|
||||
-- Test 1: Basic partition-wise queries
|
||||
SELECT
|
||||
'Test1_PARTITION_BASIC_QUERY' as test_name,
|
||||
DATE_FORMAT(transaction_date, '%Y-%m') as month,
|
||||
COUNT(*) as transaction_count,
|
||||
SUM(amount) as total_amount,
|
||||
AVG(balance) as avg_balance,
|
||||
MAX(amount) as max_amount,
|
||||
MIN(amount) as min_amount
|
||||
FROM decimal_range_partition
|
||||
GROUP BY DATE_FORMAT(transaction_date, '%Y-%m')
|
||||
ORDER BY month;
|
||||
|
||||
-- Test 2: Partition pruning test - single partition
|
||||
SELECT
|
||||
'Test2_SINGLE_PARTITION_QUERY' as test_name,
|
||||
id,
|
||||
transaction_date,
|
||||
amount,
|
||||
balance,
|
||||
account_type
|
||||
FROM decimal_range_partition
|
||||
WHERE transaction_date >= '2024-02-01' AND transaction_date < '2024-03-01'
|
||||
ORDER BY transaction_date;
|
||||
|
||||
-- Test 3: Cross-partition aggregation by account type
|
||||
SELECT
|
||||
'Test3_CROSS_PARTITION_AGGREGATION' as test_name,
|
||||
account_type,
|
||||
COUNT(*) as transaction_count,
|
||||
SUM(amount) as total_amount,
|
||||
AVG(amount) as avg_amount,
|
||||
SUM(CASE WHEN amount > 0 THEN amount ELSE 0 END) as total_deposits,
|
||||
SUM(CASE WHEN amount < 0 THEN ABS(amount) ELSE 0 END) as total_withdrawals
|
||||
FROM decimal_range_partition
|
||||
GROUP BY account_type
|
||||
ORDER BY account_type;
|
||||
|
||||
-- =============================================================================
|
||||
-- Part 2: List partitioned table with decimal256 ranges
|
||||
-- =============================================================================
|
||||
|
||||
-- Create list partitioned table using decimal256 ranges
|
||||
CREATE TABLE decimal_amount_partition (
|
||||
id BIGINT,
|
||||
customer_id INT,
|
||||
amount DECIMAL(50,15),
|
||||
large_amount DECIMAL(76,0),
|
||||
category VARCHAR(20),
|
||||
amount_range STRING
|
||||
)
|
||||
DUPLICATE KEY(id, customer_id)
|
||||
PARTITION BY LIST(amount_range) (
|
||||
PARTITION p_small VALUES IN ('SMALL'),
|
||||
PARTITION p_medium VALUES IN ('MEDIUM'),
|
||||
PARTITION p_large VALUES IN ('LARGE'),
|
||||
PARTITION p_xlarge VALUES IN ('XLARGE')
|
||||
)
|
||||
DISTRIBUTED BY HASH(customer_id) BUCKETS 3
|
||||
PROPERTIES (
|
||||
"replication_num" = "1"
|
||||
);
|
||||
|
||||
-- Insert test data with different amount ranges - using decimal256 values beyond decimal128 range
|
||||
INSERT INTO decimal_amount_partition VALUES
|
||||
-- Small amounts (< 40 digits)
|
||||
(1, 101, 12345678901234567890123456789012345.123456789012345, 12345678901234567, 'RETAIL', 'SMALL'),
|
||||
(2, 102, 98765432109876543210987654321098765.987654321098765, 98765432109876543, 'ONLINE', 'SMALL'),
|
||||
(3, 103, 55555555555555555555555555555555555.999999999999999, 55555555555555555, 'RETAIL', 'SMALL'),
|
||||
|
||||
-- Medium amounts (40-50 digits)
|
||||
(4, 201, 1234567890123456789012345678901234.555555555555, 1234567890123456789012345678901234567890123456789012345678901234567890, 'WHOLESALE', 'MEDIUM'),
|
||||
(5, 202, 9876543210987654321098765432109876.777777777777, 9876543210987654321098765432109876543210987654321098765432109876543210, 'ENTERPRISE', 'MEDIUM'),
|
||||
(6, 203, 5555555555555555555555555555555555.888888888888, 5555555555555555555555555555555555555555555555555555555555555555555555, 'WHOLESALE', 'MEDIUM'),
|
||||
|
||||
-- Large amounts (50-60 digits)
|
||||
(7, 301, 12345678901234567890123456789012.123456789012345, 123456789012345, 'ENTERPRISE', 'LARGE'),
|
||||
(8, 302, 98765432109876543210987654321098.999999999999999, 987654321098765, 'GOVERNMENT', 'LARGE'),
|
||||
(9, 303, 77777777777777777777777777777777.111111111111111, 777777777777777, 'ENTERPRISE', 'LARGE');
|
||||
|
||||
|
||||
-- Test 4: List partition aggregation
|
||||
SELECT
|
||||
'Test4_LIST_PARTITION_AGGREGATION' as test_name,
|
||||
amount_range,
|
||||
category,
|
||||
COUNT(*) as count,
|
||||
SUM(amount) as total_amount,
|
||||
AVG(amount) as avg_amount,
|
||||
MIN(amount) as min_amount,
|
||||
MAX(amount) as max_amount
|
||||
FROM decimal_amount_partition
|
||||
GROUP BY amount_range, category
|
||||
ORDER BY amount_range, category;
|
||||
|
||||
-- Test 5: Partition pruning with specific range
|
||||
SELECT
|
||||
'Test5_PARTITION_PRUNING_SPECIFIC' as test_name,
|
||||
id,
|
||||
customer_id,
|
||||
amount,
|
||||
large_amount,
|
||||
category
|
||||
FROM decimal_amount_partition
|
||||
WHERE amount_range = 'LARGE'
|
||||
ORDER BY amount DESC;
|
||||
|
||||
-- =============================================================================
|
||||
-- Part 3: Partition maintenance operations
|
||||
-- =============================================================================
|
||||
|
||||
-- Test 6: Add new partition with decimal256 data
|
||||
ALTER TABLE decimal_range_partition
|
||||
ADD PARTITION p202405 VALUES [('2024-05-01'), ('2024-06-01'));
|
||||
|
||||
-- Insert data into new partition - using decimal256 values beyond decimal128 range
|
||||
INSERT INTO decimal_range_partition VALUES
|
||||
(13, '2024-05-10', 888887777766666555554444433.123456789012345, 8888877777666665555544444333332222211111.45800234567890123456, 'SAVINGS'),
|
||||
(14, '2024-05-20', -11111222223333344444555556.987654321098765, 1111122222333334444455555666667777788888.47034913469124801235, 'CHECKING'),
|
||||
(15, '2024-05-31', 999999999999999999999999999.000000000000000, 9999999999999999999999999999999999999999.47034913469124801235, 'INVESTMENT');
|
||||
|
||||
-- Test 7: Query across all partitions including new one
|
||||
SELECT
|
||||
'Test7_ALL_PARTITIONS_INCLUDING_NEW' as test_name,
|
||||
DATE_FORMAT(transaction_date, '%Y-%m') as month,
|
||||
COUNT(*) as transaction_count,
|
||||
SUM(amount) as total_amount,
|
||||
AVG(balance) as avg_balance
|
||||
FROM decimal_range_partition
|
||||
GROUP BY DATE_FORMAT(transaction_date, '%Y-%m')
|
||||
ORDER BY month;
|
||||
|
||||
-- Test 8: Partition-wise window functions
|
||||
SELECT
|
||||
'Test8_PARTITION_WINDOW_FUNCTIONS' as test_name,
|
||||
id,
|
||||
transaction_date,
|
||||
amount,
|
||||
balance,
|
||||
account_type,
|
||||
ROW_NUMBER() OVER (PARTITION BY DATE_FORMAT(transaction_date, '%Y-%m') ORDER BY amount DESC) as rank_in_month,
|
||||
SUM(amount) OVER (PARTITION BY account_type ORDER BY transaction_date) as running_total_by_type,
|
||||
LAG(balance, 1) OVER (PARTITION BY account_type ORDER BY transaction_date) as prev_balance
|
||||
FROM decimal_range_partition
|
||||
ORDER BY transaction_date, account_type;
|
||||
|
||||
-- Test 9: Cross-partition joins
|
||||
WITH monthly_stats AS (
|
||||
SELECT
|
||||
DATE_FORMAT(transaction_date, '%Y-%m') as month,
|
||||
account_type,
|
||||
SUM(amount) as monthly_total,
|
||||
COUNT(*) as monthly_count
|
||||
FROM decimal_range_partition
|
||||
GROUP BY DATE_FORMAT(transaction_date, '%Y-%m'), account_type
|
||||
)
|
||||
SELECT
|
||||
'Test9_CROSS_PARTITION_JOINS' as test_name,
|
||||
dp.transaction_date,
|
||||
dp.amount,
|
||||
dp.account_type,
|
||||
ms.monthly_total,
|
||||
dp.amount / ms.monthly_total * 100 as percent_of_monthly_total
|
||||
FROM decimal_range_partition dp
|
||||
JOIN monthly_stats ms ON DATE_FORMAT(dp.transaction_date, '%Y-%m') = ms.month
|
||||
AND dp.account_type = ms.account_type
|
||||
WHERE ABS(dp.amount) > 1000.000000000000000
|
||||
ORDER BY dp.transaction_date;
|
||||
|
||||
-- Test 10: Partition information query
|
||||
SELECT
|
||||
'Test10_PARTITION_INFORMATION' as test_name,
|
||||
DATE_FORMAT(transaction_date, '%Y-%m') as partition_month,
|
||||
COUNT(*) as row_count,
|
||||
SUM(CASE WHEN amount > 0 THEN 1 ELSE 0 END) as positive_transactions,
|
||||
SUM(CASE WHEN amount < 0 THEN 1 ELSE 0 END) as negative_transactions,
|
||||
MIN(balance) as min_balance_in_partition,
|
||||
MAX(balance) as max_balance_in_partition
|
||||
FROM decimal_range_partition
|
||||
GROUP BY DATE_FORMAT(transaction_date, '%Y-%m')
|
||||
ORDER BY partition_month;
|
||||
|
|
@ -0,0 +1,131 @@
|
|||
-- name: test_decimal256_string_functions
|
||||
DROP DATABASE IF EXISTS test_decimal256_string;
|
||||
CREATE DATABASE test_decimal256_string;
|
||||
USE test_decimal256_string;
|
||||
|
||||
-- Create test table with decimal256 types
|
||||
CREATE TABLE decimal_string_test (
|
||||
id INT,
|
||||
d50_15 DECIMAL(50,15),
|
||||
d76_20 DECIMAL(76,20),
|
||||
d76_0 DECIMAL(76,0),
|
||||
category VARCHAR(10)
|
||||
) PROPERTIES("replication_num"="1");
|
||||
|
||||
-- Insert test data with various decimal patterns - using values that exceed decimal128 range
|
||||
INSERT INTO decimal_string_test VALUES
|
||||
(1, 12345678901234567890123456789012345.123456789012345, 12345678901234567890123456789012345678901234567890123456.12345678901234567890, 1234567890123456789012345678901234567890123456789012345678901234567890123456, 'A'),
|
||||
(2, -98765432109876543210987654321098765.456789012345678, -98765432109876543210987654321098765432109876543210987654.45678901234567890123, -9876543210987654321098765432109876543210987654321098765432109876543210987654, 'B'),
|
||||
(3, 0.000000000000001, 0.00000000000000000001, 0, 'C'),
|
||||
(4, 99999888887777766666555554444433333.999999999999999, 99999888887777766666555554444433333222221111100009999988.99999999999999999999, 9999988888777776666655555444443333322222111110000099999888877776666555544, 'A'),
|
||||
(5, -88888777776666655555444443333322222.888888888888888, -88888777776666655555444443333322222111110000099999888877.88888888888888888888, -8888877777666665555544444333332222211111000009999988888777766665555444433, 'B'),
|
||||
(6, 11111222223333344444555556666677777.111111111111111, 11111222223333344444555556666677777888889999900001111122.11111111111111111111, 1111122222333334444455555666667777788888999990000011111222233334444555566, 'C'),
|
||||
(7, -77777666665555544444333332222211111.777777777777777, -77777666665555544444333332222211111000009999988888777776.77777777777777777777, -7777766666555554444433333222221111100000999998888877777666655554444333322, 'A');
|
||||
|
||||
-- Test 1: Basic string conversion and manipulation
|
||||
SELECT
|
||||
'Test1_BASIC_STRING_CONVERSION' as test_name,
|
||||
id,
|
||||
d50_15,
|
||||
CAST(d50_15 AS STRING) as d50_as_string,
|
||||
CONCAT('Value: ', CAST(d50_15 AS STRING)) as formatted_d50,
|
||||
CONCAT('D50=', CAST(d50_15 AS STRING), ', D76=', CAST(d76_20 AS STRING)) as combined_string
|
||||
FROM decimal_string_test
|
||||
ORDER BY id;
|
||||
|
||||
-- Test 2: String length and truncation operations
|
||||
SELECT
|
||||
'Test2_STRING_LENGTH_TRUNCATION' as test_name,
|
||||
id,
|
||||
d76_0,
|
||||
CAST(d76_0 AS STRING) as d76_string,
|
||||
LENGTH(CAST(d76_0 AS STRING)) as string_length,
|
||||
LEFT(CAST(d76_0 AS STRING), 10) as left_10_chars,
|
||||
RIGHT(CAST(d76_0 AS STRING), 10) as right_10_chars,
|
||||
SUBSTR(CAST(d76_0 AS STRING), 1, 20) as first_20_chars
|
||||
FROM decimal_string_test
|
||||
ORDER BY id;
|
||||
|
||||
-- Test 3: String pattern matching and search
|
||||
SELECT
|
||||
'Test3_STRING_PATTERN_MATCHING' as test_name,
|
||||
id,
|
||||
d50_15,
|
||||
CAST(d50_15 AS STRING) as decimal_string,
|
||||
LOCATE('.', CAST(d50_15 AS STRING)) as decimal_point_position,
|
||||
LOCATE('-', CAST(d50_15 AS STRING)) as negative_sign_position,
|
||||
CASE WHEN CAST(d50_15 AS STRING) LIKE '%-%.%' THEN 'NEGATIVE_DECIMAL'
|
||||
WHEN CAST(d50_15 AS STRING) LIKE '%.%' THEN 'POSITIVE_DECIMAL'
|
||||
WHEN CAST(d50_15 AS STRING) LIKE '-%' THEN 'NEGATIVE_INTEGER'
|
||||
ELSE 'POSITIVE_INTEGER'
|
||||
END as number_type
|
||||
FROM decimal_string_test
|
||||
ORDER BY id;
|
||||
|
||||
-- Test 4: Regular expression operations
|
||||
SELECT
|
||||
'Test4_REGEX_OPERATIONS' as test_name,
|
||||
id,
|
||||
d76_20,
|
||||
CAST(d76_20 AS STRING) as decimal_string,
|
||||
REGEXP_EXTRACT(CAST(d76_20 AS STRING), '^(-?[0-9]+)', 1) as integer_part,
|
||||
REGEXP_EXTRACT(CAST(d76_20 AS STRING), '\\.([0-9]+)$', 1) as decimal_part,
|
||||
REGEXP_REPLACE(CAST(d76_20 AS STRING), '0+$', '') as trimmed_trailing_zeros,
|
||||
REGEXP_EXTRACT(CAST(d76_20 AS STRING), '^(-?[0-9]+\\.[0-9]{0,5})', 1) as first_5_decimal_places
|
||||
FROM decimal_string_test
|
||||
WHERE d76_20 != 0
|
||||
ORDER BY id;
|
||||
|
||||
-- Test 5: String splitting and parsing
|
||||
SELECT
|
||||
'Test5_STRING_SPLITTING' as test_name,
|
||||
id,
|
||||
d50_15,
|
||||
CAST(d50_15 AS STRING) as original_string,
|
||||
SPLIT_PART(CAST(ABS(d50_15) AS STRING), '.', 1) as integer_part_split,
|
||||
SPLIT_PART(CAST(ABS(d50_15) AS STRING), '.', 2) as decimal_part_split,
|
||||
CASE WHEN d50_15 < 0 THEN '-' ELSE '+' END as sign_part
|
||||
FROM decimal_string_test
|
||||
ORDER BY id;
|
||||
|
||||
-- Test 6: String formatting and padding
|
||||
SELECT
|
||||
'Test6_STRING_FORMATTING' as test_name,
|
||||
id,
|
||||
d76_0,
|
||||
CAST(d76_0 AS STRING) as original_string,
|
||||
LPAD(CAST(ABS(d76_0) AS STRING), 80, '0') as zero_padded,
|
||||
RPAD(CAST(d76_0 AS STRING), 20, ' ') as space_padded
|
||||
FROM decimal_string_test
|
||||
ORDER BY id;
|
||||
|
||||
-- Test 7: Case conversion and special formatting
|
||||
SELECT
|
||||
'Test7_CASE_SPECIAL_FORMATTING' as test_name,
|
||||
id,
|
||||
category,
|
||||
d50_15,
|
||||
UPPER(CONCAT(category, '_', CAST(d50_15 AS STRING))) as upper_formatted,
|
||||
LOWER(CONCAT(category, '_', CAST(d50_15 AS STRING))) as lower_formatted
|
||||
FROM decimal_string_test
|
||||
ORDER BY id;
|
||||
|
||||
-- Test 8: Complex string operations with multiple decimals
|
||||
SELECT
|
||||
'Test8_COMPLEX_STRING_OPERATIONS' as test_name,
|
||||
id,
|
||||
d50_15,
|
||||
d76_20,
|
||||
d76_0,
|
||||
CONCAT_WS(' | ',
|
||||
CONCAT('D50: ', CAST(d50_15 AS STRING)),
|
||||
CONCAT('D76_20: ', CAST(d76_20 AS STRING)),
|
||||
CONCAT('D76_0: ', CAST(d76_0 AS STRING))
|
||||
) as pipe_separated,
|
||||
REPLACE(
|
||||
REPLACE(CAST(d50_15 AS STRING), '.', '_DOT_'),
|
||||
'-', '_MINUS_'
|
||||
) as symbol_replaced,
|
||||
REVERSE(CAST(ABS(d50_15) AS STRING)) as reversed_string
|
||||
FROM decimal_string_test
|
||||
ORDER BY id;
|
||||
|
|
@ -0,0 +1,144 @@
|
|||
-- name: test_decimal256_subquery_cte
|
||||
DROP DATABASE IF EXISTS test_decimal256_subquery;
|
||||
CREATE DATABASE test_decimal256_subquery;
|
||||
USE test_decimal256_subquery;
|
||||
|
||||
-- Create main test table
|
||||
CREATE TABLE decimal_main_test (
|
||||
id INT,
|
||||
category VARCHAR(10),
|
||||
d50_15 DECIMAL(50,15),
|
||||
d76_20 DECIMAL(76,20)
|
||||
) PROPERTIES("replication_num"="1");
|
||||
|
||||
-- Create secondary test table for joins
|
||||
CREATE TABLE decimal_secondary_test (
|
||||
id INT,
|
||||
ref_category VARCHAR(10),
|
||||
threshold_d50 DECIMAL(50,15),
|
||||
threshold_d76 DECIMAL(76,20)
|
||||
) PROPERTIES("replication_num"="1");
|
||||
|
||||
-- Insert test data into main table - using decimal256 values beyond decimal128 range
|
||||
INSERT INTO decimal_main_test VALUES
|
||||
(1, 'A', 12345678901234567890123456789012345.123456789012345, 12345678901234567890123456789012345678901234567890123456.12345678901234567890),
|
||||
(2, 'A', 98765432109876543210987654321098765.456789012345678, 98765432109876543210987654321098765432109876543210987654.45678901234567890123),
|
||||
(3, 'B', 55555555555555555555555555555555555.789012345678901, 55555555555555555555555555555555555555555555555555555555.78901234567890123456),
|
||||
(4, 'B', 77777777777777777777777777777777777.012345678901234, 77777777777777777777777777777777777777777777777777777777.01234567890123456789),
|
||||
(5, 'C', 44444444444444444444444444444444444.567890123456789, 44444444444444444444444444444444444444444444444444444444.56789012345678901234),
|
||||
(6, 'C', 88888888888888888888888888888888888.901234567890123, 88888888888888888888888888888888888888888888888888888888.90123456789012345678),
|
||||
(7, 'A', 11111111111111111111111111111111111.234567890123456, 11111111111111111111111111111111111111111111111111111111.23456789012345678901),
|
||||
(8, 'B', 22222222222222222222222222222222222.678901234567890, 22222222222222222222222222222222222222222222222222222222.67890123456789012345),
|
||||
(9, 'C', 99999999999999999999999999999999999.345678901234567, 99999999999999999999999999999999999999999999999999999999.34567890123456789012),
|
||||
(10, 'A', 66666666666666666666666666666666666.111111111111111, 66666666666666666666666666666666666666666666666666666666.11111111111111111111);
|
||||
|
||||
-- Insert test data into secondary table - using large threshold values
|
||||
INSERT INTO decimal_secondary_test VALUES
|
||||
(1, 'A', 50000000000000000000000000000000000.000000000000000, 50000000000000000000000000000000000000000000000000000000.00000000000000000000),
|
||||
(2, 'B', 60000000000000000000000000000000000.000000000000000, 60000000000000000000000000000000000000000000000000000000.00000000000000000000),
|
||||
(3, 'C', 70000000000000000000000000000000000.000000000000000, 70000000000000000000000000000000000000000000000000000000.00000000000000000000);
|
||||
|
||||
-- Test 1: Scalar subquery in SELECT
|
||||
SELECT
|
||||
'Test1_SCALAR_SUBQUERY_SELECT' as test_name,
|
||||
id,
|
||||
category,
|
||||
d50_15,
|
||||
(SELECT AVG(d50_15) FROM decimal_main_test) as overall_avg,
|
||||
d50_15 - (SELECT AVG(d50_15) FROM decimal_main_test) as diff_from_avg
|
||||
FROM decimal_main_test
|
||||
ORDER BY id;
|
||||
|
||||
-- Test 2: Scalar subquery in WHERE
|
||||
SELECT
|
||||
'Test2_SCALAR_SUBQUERY_WHERE' as test_name,
|
||||
id,
|
||||
category,
|
||||
d50_15,
|
||||
d76_20
|
||||
FROM decimal_main_test
|
||||
WHERE d50_15 > (SELECT AVG(d50_15) FROM decimal_main_test)
|
||||
ORDER BY d50_15;
|
||||
|
||||
-- Test 3: EXISTS subquery
|
||||
SELECT
|
||||
'Test3_EXISTS_SUBQUERY' as test_name,
|
||||
mt.id,
|
||||
mt.category,
|
||||
mt.d50_15
|
||||
FROM decimal_main_test mt
|
||||
WHERE EXISTS (
|
||||
SELECT 1 FROM decimal_secondary_test st
|
||||
WHERE st.ref_category = mt.category
|
||||
AND mt.d50_15 > st.threshold_d50
|
||||
)
|
||||
ORDER BY mt.id;
|
||||
|
||||
-- Test 4: IN subquery with decimal values
|
||||
SELECT
|
||||
'Test4_IN_SUBQUERY' as test_name,
|
||||
id,
|
||||
category,
|
||||
d76_20
|
||||
FROM decimal_main_test
|
||||
WHERE d76_20 IN (
|
||||
SELECT d76_20 FROM decimal_main_test
|
||||
WHERE category = 'A'
|
||||
AND d76_20 > 100.00000000000000000000
|
||||
)
|
||||
ORDER BY d76_20;
|
||||
|
||||
|
||||
-- Test 5: Basic CTE
|
||||
WITH decimal_stats AS (
|
||||
SELECT
|
||||
category,
|
||||
AVG(d50_15) as avg_d50,
|
||||
AVG(d76_20) as avg_d76,
|
||||
COUNT(*) as cnt
|
||||
FROM decimal_main_test
|
||||
GROUP BY category
|
||||
)
|
||||
SELECT
|
||||
'Test6_BASIC_CTE' as test_name,
|
||||
ds.category,
|
||||
ds.avg_d50,
|
||||
ds.avg_d76,
|
||||
ds.cnt,
|
||||
mt.d50_15,
|
||||
mt.d50_15 - ds.avg_d50 as diff_from_cat_avg
|
||||
FROM decimal_stats ds
|
||||
JOIN decimal_main_test mt ON ds.category = mt.category
|
||||
ORDER BY ds.category, mt.d50_15;
|
||||
|
||||
|
||||
-- Test 6: Multiple CTEs
|
||||
WITH category_stats AS (
|
||||
SELECT
|
||||
category,
|
||||
SUM(d50_15) as total_d50,
|
||||
MAX(d76_20) as max_d76
|
||||
FROM decimal_main_test
|
||||
GROUP BY category
|
||||
),
|
||||
threshold_data AS (
|
||||
SELECT
|
||||
ref_category,
|
||||
AVG(threshold_d50) as avg_threshold
|
||||
FROM decimal_secondary_test
|
||||
GROUP BY ref_category
|
||||
)
|
||||
SELECT
|
||||
'Test8_MULTIPLE_CTE' as test_name,
|
||||
cs.category,
|
||||
cs.total_d50,
|
||||
cs.max_d76,
|
||||
td.avg_threshold,
|
||||
CASE
|
||||
WHEN cs.total_d50 > td.avg_threshold * 3 THEN 'HIGH'
|
||||
WHEN cs.total_d50 > td.avg_threshold THEN 'MEDIUM'
|
||||
ELSE 'LOW'
|
||||
END as performance_level
|
||||
FROM category_stats cs
|
||||
LEFT JOIN threshold_data td ON cs.category = td.ref_category
|
||||
ORDER BY cs.category;
|
||||
|
|
@ -0,0 +1,107 @@
|
|||
-- name: test_decimal256_window_functions
|
||||
DROP DATABASE IF EXISTS test_decimal256_window;
|
||||
CREATE DATABASE test_decimal256_window;
|
||||
USE test_decimal256_window;
|
||||
|
||||
-- Create test table with decimal256 types
|
||||
CREATE TABLE decimal_window_test (
|
||||
id INT,
|
||||
category VARCHAR(10),
|
||||
d50_15 DECIMAL(50,15), -- 35 integer digits + 15 decimal digits
|
||||
d76_20 DECIMAL(76,20), -- 56 integer digits + 20 decimal digits
|
||||
d76_0 DECIMAL(76,0) -- 76 integer digits + 0 decimal digits
|
||||
) PROPERTIES("replication_num"="1");
|
||||
|
||||
-- Insert test data - using values beyond decimal128 range (>38 digits)
|
||||
-- Each category has multiple rows for proper window function testing
|
||||
INSERT INTO decimal_window_test VALUES
|
||||
-- Category A (4 rows)
|
||||
(1, 'A', 12345678901234567890123456789012345.123456789012345, 12345678901234567890123456789012345678901234567890123456.12345678901234567890, 1234567890123456789012345678901234567890123456789012345678901234567890123456),
|
||||
(2, 'A', 98765432109876543210987654321098765.456789012345678, 98765432109876543210987654321098765432109876543210987654.45678901234567890123, 9876543210987654321098765432109876543210987654321098765432109876543210987654),
|
||||
(3, 'A', 55555555555555555555555555555555555.789012345678901, 55555555555555555555555555555555555555555555555555555555.78901234567890123456, 5555555555555555555555555555555555555555555555555555555555555555555555555555),
|
||||
(4, 'A', 66666666666666666666666666666666666.111111111111111, 66666666666666666666666666666666666666666666666666666666.11111111111111111111, 6666666666666666666666666666666666666666666666666666666666666666666666666666),
|
||||
|
||||
-- Category B (4 rows)
|
||||
(5, 'B', 77777777777777777777777777777777777.012345678901234, 77777777777777777777777777777777777777777777777777777777.01234567890123456789, 7777777777777777777777777777777777777777777777777777777777777777777777777777),
|
||||
(6, 'B', 44444444444444444444444444444444444.567890123456789, 44444444444444444444444444444444444444444444444444444444.56789012345678901234, 4444444444444444444444444444444444444444444444444444444444444444444444444444),
|
||||
(7, 'B', 88888888888888888888888888888888888.901234567890123, 88888888888888888888888888888888888888888888888888888888.90123456789012345678, 8888888888888888888888888888888888888888888888888888888888888888888888888888),
|
||||
(8, 'B', 33333333333333333333333333333333333.222222222222222, 33333333333333333333333333333333333333333333333333333333.22222222222222222222, 3333333333333333333333333333333333333333333333333333333333333333333333333333),
|
||||
|
||||
-- Category C (4 rows)
|
||||
(9, 'C', 11111111111111111111111111111111111.234567890123456, 11111111111111111111111111111111111111111111111111111111.23456789012345678901, 1111111111111111111111111111111111111111111111111111111111111111111111111111),
|
||||
(10, 'C', 22222222222222222222222222222222222.678901234567890, 22222222222222222222222222222222222222222222222222222222.67890123456789012345, 2222222222222222222222222222222222222222222222222222222222222222222222222222),
|
||||
(11, 'C', 99999888887777766666555554444433333.345678901234567, 99999888887777766666555554444433333222221111100009999988.34567890123456789012, 9999988888777776666655555444443333322222111110000099999888877776666555544),
|
||||
(12, 'C', 77777666665555544444333332222211111.777777777777777, 77777666665555544444333332222211111000009999988888777776.77777777777777777777, 7777766666555554444433333222221111100000999998888877777666655554444333322);
|
||||
|
||||
-- Test 1: Basic ranking functions
|
||||
SELECT
|
||||
'Test1_RANKING_FUNCTIONS' as test_name,
|
||||
id,
|
||||
category,
|
||||
d50_15,
|
||||
ROW_NUMBER() OVER (ORDER BY d50_15) as row_num,
|
||||
RANK() OVER (ORDER BY d50_15) as rank_val,
|
||||
DENSE_RANK() OVER (ORDER BY d50_15) as dense_rank_val
|
||||
FROM decimal_window_test
|
||||
ORDER BY d50_15;
|
||||
|
||||
-- Test 2: Partition by category ranking
|
||||
SELECT
|
||||
'Test2_PARTITION_RANKING' as test_name,
|
||||
id,
|
||||
category,
|
||||
d76_20,
|
||||
ROW_NUMBER() OVER (PARTITION BY category ORDER BY d76_20) as row_num_by_cat,
|
||||
RANK() OVER (PARTITION BY category ORDER BY d76_20) as rank_by_cat
|
||||
FROM decimal_window_test
|
||||
ORDER BY category, d76_20;
|
||||
|
||||
-- Test 3: Window aggregate functions
|
||||
SELECT
|
||||
'Test3_WINDOW_AGGREGATES' as test_name,
|
||||
id,
|
||||
category,
|
||||
d50_15,
|
||||
SUM(d50_15) OVER (ORDER BY id ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) as moving_sum,
|
||||
AVG(d50_15) OVER (PARTITION BY category ORDER BY id) as running_avg_by_cat,
|
||||
COUNT(*) OVER (PARTITION BY category) as count_by_cat,
|
||||
MAX(d76_0) OVER (PARTITION BY category ORDER BY id ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) as running_max
|
||||
FROM decimal_window_test
|
||||
ORDER BY id;
|
||||
|
||||
-- Test 4: LEAD and LAG functions
|
||||
SELECT
|
||||
'Test4_LEAD_LAG' as test_name,
|
||||
id,
|
||||
category,
|
||||
d76_20,
|
||||
LAG(d76_20, 1) OVER (ORDER BY d76_20) as prev_val,
|
||||
LEAD(d76_20, 1) OVER (ORDER BY d76_20) as next_val,
|
||||
LAG(d76_20, 1, 0.0) OVER (PARTITION BY category ORDER BY d76_20) as prev_val_by_cat,
|
||||
LEAD(d76_20, 1, 0.0) OVER (PARTITION BY category ORDER BY d76_20) as next_val_by_cat
|
||||
FROM decimal_window_test
|
||||
ORDER BY d76_20;
|
||||
|
||||
-- Test 5: FIRST_VALUE and LAST_VALUE
|
||||
SELECT
|
||||
'Test5_FIRST_LAST_VALUE' as test_name,
|
||||
id,
|
||||
category,
|
||||
d76_0,
|
||||
FIRST_VALUE(d76_0) OVER (PARTITION BY category ORDER BY d76_0) as first_val_by_cat,
|
||||
LAST_VALUE(d76_0) OVER (PARTITION BY category ORDER BY d76_0 ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) as last_val_by_cat,
|
||||
FIRST_VALUE(d50_15) OVER (ORDER BY id ROWS BETWEEN CURRENT ROW AND 2 FOLLOWING) as first_val_window
|
||||
FROM decimal_window_test
|
||||
ORDER BY category, d76_0;
|
||||
|
||||
-- Test 6: Complex window expressions
|
||||
SELECT
|
||||
'Test6_COMPLEX_WINDOW' as test_name,
|
||||
id,
|
||||
category,
|
||||
d50_15,
|
||||
d76_20,
|
||||
SUM(d50_15 * d76_20) OVER (PARTITION BY category ORDER BY id) as running_product_sum,
|
||||
AVG(d50_15 + d76_20) OVER (ORDER BY id ROWS BETWEEN 2 PRECEDING AND 2 FOLLOWING) as moving_sum_avg
|
||||
FROM decimal_window_test
|
||||
ORDER BY id;
|
||||
Loading…
Reference in New Issue