From 793dd9d19cffc7a2ab6ea8db5b2c341fcd5625a0 Mon Sep 17 00:00:00 2001 From: zhannngchen Date: Tue, 17 Dec 2024 20:46:24 +0800 Subject: [PATCH] [misc](regression) adjust doc case for unique-update.md (#44854) adjust doc case for unique-update.md --- .../data-operate/update/unique-update.md.out | 6 +- .../update/unique-update.md.groovy | 60 +++++++++++++++---- 2 files changed, 52 insertions(+), 14 deletions(-) diff --git a/regression-test/data/doc/data-operate/update/unique-update.md.out b/regression-test/data/doc/data-operate/update/unique-update.md.out index 7f5f43272d9b5b..65683c5f73b474 100644 --- a/regression-test/data/doc/data-operate/update/unique-update.md.out +++ b/regression-test/data/doc/data-operate/update/unique-update.md.out @@ -1,4 +1,8 @@ -- This file is automatically generated. You should know what you did if you want to edit this -- !sql -- -1 100.000000000 To be shipped +1001 5001 2024-11-24 2024-11-24T14:30 100.00 iPhone 12 New York 100.00 10 false low +1002 5002 2024-11-24 2024-11-24T03:30 120.00 iPhone 12 New York 100.00 15 false medium +1003 5003 2024-11-24 2024-11-24T10:00 150.00 Samsung S21 Los Angeles 100.00 30 false medium +1004 5004 2024-11-24 2024-11-24T16:00 300.00 MacBook Pro high_risk_region1 200.00 5 false high +1005 5005 2024-11-24 2024-11-24T11:00 1100.00 iPad Pro Chicago 200.00 10 false high diff --git a/regression-test/suites/doc/data-operate/update/unique-update.md.groovy b/regression-test/suites/doc/data-operate/update/unique-update.md.groovy index 2cd4f64afce600..582274b053ff84 100644 --- a/regression-test/suites/doc/data-operate/update/unique-update.md.groovy +++ b/regression-test/suites/doc/data-operate/update/unique-update.md.groovy @@ -20,23 +20,57 @@ import org.junit.jupiter.api.Assertions; suite("docs/data-operate/update/unique-update.md") { try { multi_sql """ - DROP TABLE IF EXISTS test_order; - CREATE TABLE IF NOT EXISTS test_order - ( - `order_id` BIGINT NOT NULL, - `order_amount` DECIMAL(27, 9) NOT NULL, - `order_status` VARCHAR(65533) + DROP TABLE IF EXISTS transaction_details; + CREATE TABLE transaction_details ( + transaction_id BIGINT NOT NULL, -- Unique transaction ID + user_id BIGINT NOT NULL, -- User ID + transaction_date DATE NOT NULL, -- Transaction date + transaction_time DATETIME NOT NULL, -- Transaction time + transaction_amount DECIMAL(18, 2), -- Transaction amount + transaction_device STRING, -- Transaction device + transaction_region STRING, -- Transaction region + average_daily_amount DECIMAL(18, 2), -- Average daily transaction amount over the last 3 months + recent_transaction_count INT, -- Number of transactions in the last 7 days + has_dispute_history BOOLEAN, -- Whether there is a dispute history + risk_level STRING -- Risk level ) - UNIQUE KEY(`order_id`) - DISTRIBUTED BY HASH(`order_id`) BUCKETS 1 + UNIQUE KEY(transaction_id) + DISTRIBUTED BY HASH(transaction_id) BUCKETS 10 PROPERTIES ( - "replication_allocation" = "tag.location.default: 1" + "replication_num" = "3", -- Number of replicas, default is 3 + "enable_unique_key_merge_on_write" = "true" -- Enable MOW mode, support merge update ); - INSERT INTO test_order(order_id, order_amount, order_status) VALUES - (1 , 100 , 'Pending' ); + + INSERT INTO transaction_details VALUES + (1001, 5001, '2024-11-24', '2024-11-24 14:30:00', 100.00, 'iPhone 12', 'New York', 100.00, 10, false, NULL), + (1002, 5002, '2024-11-24', '2024-11-24 03:30:00', 120.00, 'iPhone 12', 'New York', 100.00, 15, false, NULL), + (1003, 5003, '2024-11-24', '2024-11-24 10:00:00', 150.00, 'Samsung S21', 'Los Angeles', 100.00, 30, false, NULL), + (1004, 5004, '2024-11-24', '2024-11-24 16:00:00', 300.00, 'MacBook Pro', 'high_risk_region1', 200.00, 5, false, NULL), + (1005, 5005, '2024-11-24', '2024-11-24 11:00:00', 1100.00, 'iPad Pro', 'Chicago', 200.00, 10, false, NULL); + """ + sql """ + UPDATE transaction_details + SET risk_level = CASE + -- Transactions with dispute history or in high-risk regions + WHEN has_dispute_history = TRUE THEN 'high' + WHEN transaction_region IN ('high_risk_region1', 'high_risk_region2') THEN 'high' + + -- Abnormal transaction amount + WHEN transaction_amount > 5 * average_daily_amount THEN 'high' + + -- High transaction frequency in the last 7 days + WHEN recent_transaction_count > 50 THEN 'high' + WHEN recent_transaction_count BETWEEN 20 AND 50 THEN 'medium' + + -- Transactions during non-working hours + WHEN HOUR(transaction_time) BETWEEN 2 AND 4 THEN 'medium' + + -- Default risk + ELSE 'low' + END + WHERE transaction_date = '2024-11-24'; """ - sql """UPDATE test_order SET order_status = 'To be shipped' WHERE order_id = 1;""" - qt_sql "SELECT * FROM test_order" + qt_sql "SELECT * FROM transaction_details order by transaction_id" } catch (Throwable t) { Assertions.fail("examples in docs/data-operate/update/unique-update.md failed to exec, please fix it", t) }