This repository has been archived by the owner on Aug 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix the bug that output csv files are invalid when csv-delimiter is e…
…mpty (#219) * fix Makefile * fix csv bug * add lightning csv integration test * add separator test * simplify code * fix ci test * tmp * block some tests * fix bug * address comments * fix ut and make check * fix integration test * fix * fix * try to fix * try to fix * Revert "try to fix" This reverts commit ecdbeaa. * try to fix * address comments * address comments
- Loading branch information
Showing
17 changed files
with
290 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# diff Configuration. | ||
|
||
log-level = "info" | ||
|
||
chunk-size = 1000 | ||
|
||
check-thread-count = 4 | ||
|
||
sample-percent = 100 | ||
|
||
use-rowid = false | ||
|
||
use-checksum = true | ||
|
||
fix-sql-file = "fix.sql" | ||
|
||
# tables need to check. | ||
[[check-tables]] | ||
schema = "e2e_csv" | ||
tables = ["escape", "t"] | ||
|
||
[[table-config]] | ||
schema = "e2e_csv" | ||
table = "t" | ||
|
||
[[table-config.source-tables]] | ||
instance-id = "source-1" | ||
schema = "e2e_csv" | ||
table = "t" | ||
|
||
[[table-config]] | ||
schema = "e2e_csv" | ||
table = "escape" | ||
|
||
[[table-config.source-tables]] | ||
instance-id = "source-1" | ||
schema = "e2e_csv" | ||
table = "escape" | ||
|
||
[[source-db]] | ||
host = "127.0.0.1" | ||
port = 3306 | ||
user = "root" | ||
password = "" | ||
instance-id = "source-1" | ||
|
||
[target-db] | ||
host = "127.0.0.1" | ||
port = 4000 | ||
user = "root" | ||
password = "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
### tidb-lightning config | ||
|
||
[lightning] | ||
server-mode = false | ||
level = "error" | ||
check-requirements = false | ||
|
||
[tikv-importer] | ||
backend = "tidb" | ||
on-duplicate = "error" | ||
|
||
[mydumper] | ||
data-source-dir = "/tmp/dumpling_test_result/sql_res.e2e_csv" | ||
|
||
[mydumper.csv] | ||
separator = 'separator-place-holder' | ||
delimiter = "delimiter-place-holder" | ||
header = true | ||
not-null = false | ||
null = '\N' | ||
backslash-escape = backslash-escape-place-holder | ||
trim-last-separator = false | ||
|
||
[tidb] | ||
host = "127.0.0.1" | ||
port = 4000 | ||
user = "root" | ||
password = "" | ||
status-port = 10080 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CREATE DATABASE `e2e_csv` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_bin */ /*!80016 DEFAULT ENCRYPTION='N' */; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../naughty_strings/data/naughty_strings.escape-schema.sql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../naughty_strings/data/naughty_strings.escape.sql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../naughty_strings/data/naughty_strings.t-schema.sql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../naughty_strings/data/naughty_strings.t.sql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright 2020 PingCAP, Inc. Licensed under Apache-2.0. | ||
|
||
set -eu | ||
cur=$(cd `dirname $0`; pwd) | ||
|
||
DB_NAME="e2e_csv" | ||
|
||
# drop database on mysql | ||
export DUMPLING_TEST_PORT=3306 | ||
run_sql "drop database if exists $DB_NAME;" | ||
|
||
run_sql_file "$DUMPLING_BASE_NAME/data/e2e_csv-schema-create.sql" | ||
export DUMPLING_TEST_DATABASE="e2e_csv" | ||
run_sql_file "$DUMPLING_BASE_NAME/data/e2e_csv.escape-schema.sql" | ||
run_sql_file "$DUMPLING_BASE_NAME/data/e2e_csv.escape.sql" | ||
run_sql_file "$DUMPLING_BASE_NAME/data/e2e_csv.t-schema.sql" | ||
|
||
mkdir -p $DUMPLING_TEST_DIR/data | ||
# lightning will omit empty lines without delimiters now, skip these cases | ||
sed "s/('')/-- ('')/g" "$DUMPLING_BASE_NAME/data/e2e_csv.t.sql" | sed "s/(' ')/-- (' ')/g" > $DUMPLING_TEST_DIR/data/e2e_csv.t.sql | ||
run_sql_file "$DUMPLING_TEST_DIR/data/e2e_csv.t.sql" | ||
|
||
run() { | ||
echo "*** running subtest case ***" | ||
echo "escape_backslash is $escape_backslash" | ||
echo "csv_delimiter is $csv_delimiter" | ||
echo "csv_separator is $csv_separator" | ||
|
||
# drop database on tidb | ||
export DUMPLING_TEST_PORT=4000 | ||
export DUMPLING_TEST_DATABASE="" | ||
run_sql "drop database if exists $DB_NAME;" | ||
|
||
# dumping | ||
export DUMPLING_TEST_PORT=3306 | ||
export DUMPLING_TEST_DATABASE=$DB_NAME | ||
run_dumpling --filetype="csv" --escape-backslash=$escape_backslash --csv-delimiter="$csv_delimiter" --csv-separator="$csv_separator" | ||
|
||
# construct lightning configuration | ||
mkdir -p $DUMPLING_TEST_DIR/conf | ||
cp "$cur/conf/lightning.toml" $DUMPLING_TEST_DIR/conf | ||
|
||
sed -i -e "s/separator-place-holder/$csv_separator/g" $DUMPLING_TEST_DIR/conf/lightning.toml | ||
csv_delimiter_holder=$csv_delimiter | ||
if [ "$csv_delimiter" = '"' ]; then | ||
# We want to replace delimiter-place-holder in lightning.toml to \", | ||
# but sed will identify \" as ", so we need to use \\\" here. | ||
csv_delimiter_holder='\\\"' | ||
fi | ||
sed -i -e "s/delimiter-place-holder/$csv_delimiter_holder/g" $DUMPLING_TEST_DIR/conf/lightning.toml | ||
escape_backslash_holder="true" | ||
if [ "$escape_backslash" = "false" ] && [ "$csv_delimiter" != "" ]; then | ||
escape_backslash_holder="false" | ||
fi | ||
sed -i -e "s/backslash-escape-place-holder/$escape_backslash_holder/g" $DUMPLING_TEST_DIR/conf/lightning.toml | ||
|
||
cat "$DUMPLING_TEST_DIR/conf/lightning.toml" | ||
# use lightning import data to tidb | ||
run_lightning $DUMPLING_TEST_DIR/conf/lightning.toml | ||
|
||
# check mysql and tidb data | ||
check_sync_diff $cur/conf/diff_config.toml | ||
} | ||
|
||
escape_backslash_arr="true false" | ||
csv_delimiter_arr="\" '" | ||
csv_separator_arr=', a aa |*|' | ||
|
||
for escape_backslash in $escape_backslash_arr | ||
do | ||
for csv_separator in $csv_separator_arr | ||
do | ||
for csv_delimiter in $csv_delimiter_arr | ||
do | ||
run | ||
done | ||
if [ "$escape_backslash" = "true" ]; then | ||
csv_delimiter="" | ||
run | ||
fi | ||
done | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
CREATE TABLE `escape` ( | ||
`a` text CHARACTER SET utf8mb4 COLLATE utf8mb4_bin | ||
`a` text CHARACTER SET utf8mb4 COLLATE utf8mb4_bin, | ||
`b` varchar(13) DEFAULT NULL | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
/*!40101 SET NAMES binary*/; | ||
INSERT INTO `escape` VALUES | ||
(''''), | ||
('"'), | ||
(''''''), | ||
('""'), | ||
('''"'''), | ||
('"''''''''"''"'), | ||
('"''"''"''''''''"'); | ||
('''', '"'), | ||
('"', ''''''), | ||
('''''', '""'), | ||
('""', '''"'''), | ||
('''"''', '"''''''"''"'), | ||
('"''''''''"''"', '"''"''''''''''"'), | ||
('"''"''"''''''''"', ''), | ||
('a",b,"a', 'a,"c",a'), | ||
('bbaa|*|aabb', 'bba|*|a|*|abb'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
/*!40101 SET NAMES binary*/; | ||
INSERT INTO `escape` VALUES | ||
('\''), | ||
('\"'), | ||
('\'\''), | ||
('\"\"'), | ||
('\'\"\''), | ||
('\"\'\'\'\'\"\'\"'), | ||
('\"\'\"\'\"\'\'\'\'\"'); | ||
('\'','\"'), | ||
('\"','\'\''), | ||
('\'\'','\"\"'), | ||
('\"\"','\'\"\''), | ||
('\'\"\'','\"\'\'\'\"\'\"'), | ||
('\"\'\'\'\'\"\'\"','\"\'\"\'\'\'\'\'\"'), | ||
('\"\'\"\'\"\'\'\'\'\"',''), | ||
('a\",b,\"a','a,\"c\",a'), | ||
('bbaa|*|aabb','bba|*|a|*|abb'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.