diff --git a/lib/TableParser.pm b/lib/TableParser.pm index 9bc53303..1849e007 100644 --- a/lib/TableParser.pm +++ b/lib/TableParser.pm @@ -163,6 +163,12 @@ sub parse { my (%type_for, %is_nullable, %is_numeric, %is_autoinc); foreach my $col ( @cols ) { my $def = $def_for{$col}; + + # Remove literal backticks (``) because they're superfluous for parsing + # the col. + # https://bugs.launchpad.net/percona-toolkit/+bug/1462904 + $def =~ s/``//g; + my ( $type ) = $def =~ m/`[^`]+`\s([a-z]+)/; die "Can't determine column type for $def" unless $type; $type_for{$col} = $type; diff --git a/t/lib/TableParser.t b/t/lib/TableParser.t index 0420c9ac..85c90bb5 100644 --- a/t/lib/TableParser.t +++ b/t/lib/TableParser.t @@ -964,10 +964,44 @@ ok( diag(`$trunk/sandbox/stop-sandbox $master3_port >/dev/null`); +# ############################################################################# +# pt-duplicate-key-checker doesn't support triple quote in column name +# https://bugs.launchpad.net/percona-toolkit/+bug/1462904 +# ############################################################################# + +$tbl = $tp->parse(load_file('t/lib/samples/triple-quoted-col.sql')); +is_deeply( + $tbl, + { + clustered_key => undef, + col_posn => { 'foo' => 0, bar => 1 }, + cols => [ 'foo', 'bar' ], + defs => { + 'foo' => ' `foo` int(11) DEFAULT NULL', + 'bar' => ' ```bar``` int(11) DEFAULT NULL', + }, + engine => 'InnoDB', + is_autoinc => { foo => 0, bar => 0 }, + is_col => { foo => 1, bar => 1 }, + is_nullable => { foo => 1, bar => 1 }, + is_numeric => { foo => 1, bar => 1 }, + name => 't', + null_cols => [ 'foo', 'bar' ], + numeric_cols => [ 'foo', 'bar' ], + type_for => { + foo => 'int', + bar => 'int', + }, + keys => {}, + charset => undef, + }, + 'Literal backticks (bug 1462904)' +); + # ############################################################################# # Done. # ############################################################################# $sb->wipe_clean($dbh) if $dbh; ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); done_testing; -exit; \ No newline at end of file +exit; diff --git a/t/lib/samples/triple-quoted-col.sql b/t/lib/samples/triple-quoted-col.sql new file mode 100644 index 00000000..cd716b8e --- /dev/null +++ b/t/lib/samples/triple-quoted-col.sql @@ -0,0 +1,4 @@ +CREATE TABLE `t` ( + `foo` int(11) DEFAULT NULL, + ```bar``` int(11) DEFAULT NULL +) ENGINE=InnoDB