Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(dm): add test for json #7022

Merged
merged 8 commits into from
Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions dm/tests/all_mode/data/db3.increment.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use all_mode;

insert into t_extract(j)values ('{"a":1, "b": {"a":1}}');
insert into t_extract(j)values ('{"a":1, "b": [1,2,3]}');
insert into t_extract(j)values ('[1,2]');
insert into t_extract(j)values ('true');
insert into t_extract(j)values ('false');
insert into t_extract(j)values (null);
insert into t_extract(j)values ('"string"');
insert into t_extract(j)values ('1');
insert into t_extract(j)values ('3.14');
insert into t_extract(j)values ('{"a":1, "b": {"a":1}, "c": "string"}');

alter table t_extract add column alt_a int as (j ->> '$.a');
alter table t_extract add column alt_b char(10) as (j ->> '$.b');
alter table t_extract add column alt_j1 json as (json_search(j, 'one', '1'));
alter table t_extract add column alt_j2 json as (json_array(j ->> '$.a', j ->> '$.b'));
alter table t_extract add column alt_j3 json as (json_object('a', j ->> '$.a', 'b', j ->> '$.b'));
alter table t_extract add column alt_j4 json as (json_merge_preserve(b, '{"k": "v"}'));
alter table t_extract add column alt_j5 json as (json_merge_patch(b, '{"k": "v"}'));
alter table t_extract add column alt_j7 json as (json_set(b, '$.k', 'v'));
alter table t_extract add column alt_j8 json as (json_insert(b, '$.k', 'v'));
alter table t_extract add column alt_j9 json as (json_replace(b, '$.k', 'v'));
alter table t_extract add column alt_j10 json as (json_remove(b, '$.k'));
alter table t_extract add column alt_j11 int as (json_contains(b, '{"k": "v"}'));
alter table t_extract add column alt_j12 int as (json_contains_path(b, 'one', '$.k'));
alter table t_extract add column alt_j13 json as (json_array_append(b, '$[0]', 'v'));
alter table t_extract add column alt_j14 json as (json_array_insert(j3, '$[0]', 'v'));

insert into t_extract(j)values ('{"a":1, "b": {"a":1}}');
insert into t_extract(j)values ('{"a":1, "b": [1,2,3]}');
insert into t_extract(j)values ('[1,2]');
insert into t_extract(j)values ('true');
insert into t_extract(j)values ('false');
insert into t_extract(j)values (null);
insert into t_extract(j)values ('"string"');
insert into t_extract(j)values ('1');
insert into t_extract(j)values ('3.14');
insert into t_extract(j)values ('{"a":1, "b": {"a":1}, "c": "string"}');
35 changes: 35 additions & 0 deletions dm/tests/all_mode/data/db3.prepare.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
drop database if exists `all_mode`;
create database `all_mode`;
use `all_mode`;

create table t_extract
lance6716 marked this conversation as resolved.
Show resolved Hide resolved
(
id int primary key auto_increment,
j json,
a int as (j ->> '$.a'),
b char(10) as (j ->> '$.b'),
j1 json as (json_search(j, 'one', '1')),
j2 json as (json_array(j ->> '$.a', j ->> '$.b')),
j3 json as (json_object('a', j ->> '$.a', 'b', j ->> '$.b')),
j4 json as (json_merge_preserve(b, '{"k": "v"}')),
j5 json as (json_merge_patch(b, '{"k": "v"}')),
j7 json as (json_set(b, '$.k', 'v')),
j8 json as (json_insert(b, '$.k', 'v')),
j9 json as (json_replace(b, '$.k', 'v')),
j10 json as (json_remove(b, '$.k')),
j11 int as (json_contains(b, '{"k": "v"}')),
j12 int as (json_contains_path(b, 'one', '$.k')),
j13 json as (json_array_append(b, '$[0]', 'v')),
j14 json as (json_array_insert(j3, '$[0]', 'v'))
);

insert into t_extract(j)values ('{"a":1, "b": {"a":1}}');
insert into t_extract(j)values ('{"a":1, "b": [1,2,3]}');
insert into t_extract(j)values ('[1,2]');
insert into t_extract(j)values ('true');
insert into t_extract(j)values ('false');
insert into t_extract(j)values (null);
insert into t_extract(j)values ('"string"');
insert into t_extract(j)values ('1');
insert into t_extract(j)values ('3.14');
insert into t_extract(j)values ('{"a":1, "b": {"a":1}, "c": "string"}');
33 changes: 33 additions & 0 deletions dm/tests/all_mode/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -375,11 +375,44 @@ function test_regexpr_router() {
echo "[$(date)] <<<<<< finish test_regexpr_router $1 >>>>>>"
}

function test_json_expression() {
lance6716 marked this conversation as resolved.
Show resolved Hide resolved
echo "[$(date)] <<<<<< start test_json_expression >>>>>>"
run_sql_file $cur/data/db3.prepare.sql $MYSQL_HOST1 $MYSQL_PORT1 $MYSQL_PASSWORD1

# start DM worker and master
run_dm_master $WORK_DIR/master $MASTER_PORT $cur/conf/dm-master.toml
check_rpc_alive $cur/../bin/check_master_online 127.0.0.1:$MASTER_PORT
run_dm_worker $WORK_DIR/worker1 $WORKER1_PORT $cur/conf/dm-worker1.toml
check_rpc_alive $cur/../bin/check_worker_online 127.0.0.1:$WORKER1_PORT
run_dm_worker $WORK_DIR/worker2 $WORKER2_PORT $cur/conf/dm-worker2.toml
check_rpc_alive $cur/../bin/check_worker_online 127.0.0.1:$WORKER2_PORT

# operate mysql config to worker
cp $cur/conf/source1.yaml $WORK_DIR/source1.yaml
cp $cur/conf/source2.yaml $WORK_DIR/source2.yaml
sed -i "/relay-binlog-name/i\relay-dir: $WORK_DIR/worker1/relay_log" $WORK_DIR/source1.yaml
sed -i "s/enable-gtid: true/enable-gtid: false/g" $WORK_DIR/source1.yaml
sed -i "/relay-binlog-name/i\relay-dir: $WORK_DIR/worker2/relay_log" $WORK_DIR/source2.yaml
dmctl_operate_source create $WORK_DIR/source1.yaml $SOURCE_ID1
dmctl_operate_source create $WORK_DIR/source2.yaml $SOURCE_ID2

dmctl_start_task "$cur/conf/dm-task-expression-filter.yaml" "--remove-meta"

run_sql_file $cur/data/db3.increment.sql $MYSQL_HOST1 $MYSQL_PORT1 $MYSQL_PASSWORD1

check_sync_diff $WORK_DIR $cur/conf/diff_config.toml

cleanup_process
cleanup_data all_mode
echo "[$(date)] <<<<<< finish test_json_expression >>>>>>"
}

function run() {
run_sql_both_source "SET @@GLOBAL.SQL_MODE='ANSI_QUOTES,NO_AUTO_VALUE_ON_ZERO'"
run_sql_source1 "SET @@global.time_zone = '+01:00';"
run_sql_source2 "SET @@global.time_zone = '+02:00';"
test_expression_filter
test_json_expression
test_fail_job_between_event
test_session_config
test_query_timeout
Expand Down