Skip to content

Commit 44a01d3

Browse files
Pekka NousiainenPiotr Obrzut
authored andcommitted
wl#7614 opts-check1.diff
check --input-type and --output-type (cherry picked from commit a2350e14f9e61431bdac0eef62d73ffc47da1fdd)
1 parent 8135b5c commit 44a01d3

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

mysql-test/suite/ndb/r/ndb_import0.result

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ b int
88
) engine=ndb;
99
# csv file does not exist
1010
# bad state dir
11+
# normal import
12+
select count(*) from t1;
13+
count(*)
14+
1000
15+
# invalid --input-type
16+
# invalid --output-type
1117
# simple utf8 test
1218
create table t2 (
1319
a int primary key,

mysql-test/suite/ndb/t/ndb_import0.test

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ create table t1 (
2929
exec $NDB_IMPORT --state-dir=$MYSQLTEST_VARDIR/tmp
3030
test '/foo/data/t1.csv' >> $NDB_TOOLS_OUTPUT 2>&1;
3131

32-
--echo # bad state dir
33-
3432
perl;
3533
use strict;
3634
use Symbol;
@@ -40,15 +38,37 @@ my $file = "$vardir/tmp/t1.csv";
4038
my $fh = gensym();
4139
open($fh, ">$file")
4240
or die "$file: open for write failed: $!";
41+
for my $i (0..999) {
42+
print $fh $i, "\t", $i*10, "\n";
43+
}
4344
close($fh)
4445
or die "$file: close after write failed: $!";
4546
exit(0)
4647
EOF
4748

49+
--echo # bad state dir
4850
--error 1
4951
exec $NDB_IMPORT --state-dir=/foo/state
5052
test MYSQLTEST_VARDIR/tmp/t1.csv >> $NDB_TOOLS_OUTPUT 2>&1;
5153

54+
--echo # normal import
55+
exec $NDB_IMPORT --state-dir=$MYSQLTEST_VARDIR/tmp
56+
--input-type=csv --output-type=ndb
57+
test $MYSQLTEST_VARDIR/tmp/t1.csv >> $NDB_TOOLS_OUTPUT 2>&1;
58+
select count(*) from t1;
59+
60+
--echo # invalid --input-type
61+
--error 1
62+
exec $NDB_IMPORT --state-dir=$MYSQLTEST_VARDIR/tmp
63+
--input-type=xxx --output-type=ndb
64+
test $MYSQLTEST_VARDIR/tmp/t1.csv >> $NDB_TOOLS_OUTPUT 2>&1;
65+
66+
--echo # invalid --output-type
67+
--error 1
68+
exec $NDB_IMPORT --state-dir=$MYSQLTEST_VARDIR/tmp
69+
--input-type=csv --output-type=xxx
70+
test $MYSQLTEST_VARDIR/tmp/t1.csv >> $NDB_TOOLS_OUTPUT 2>&1;
71+
5272
--echo # simple utf8 test
5373

5474
perl;

storage/ndb/tools/NdbImport.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,19 @@ NdbImport::set_opt(const Opt& opt)
102102
{
103103
NdbImportUtil& util = m_impl.m_util;
104104
NdbImportCsv& csv = m_impl.m_csv;
105+
// XXX clean this up (map strings to enums)
105106
if (opt.m_input_type != 0)
106107
{
108+
const char* valid[] = { "csv", "random", 0 };
109+
const char** p = valid;
110+
while (*p != 0 && strcmp(*p, opt.m_input_type) != 0)
111+
p++;
112+
if (*p == 0)
113+
{
114+
util.set_error_usage(util.c_error, __LINE__,
115+
"invalid input-type %s", opt.m_input_type);
116+
return -1;
117+
}
107118
if (opt.m_input_workers < 1)
108119
{
109120
util.set_error_usage(util.c_error, __LINE__,
@@ -127,6 +138,16 @@ NdbImport::set_opt(const Opt& opt)
127138
}
128139
if (opt.m_output_type != 0)
129140
{
141+
const char* valid[] = { "ndb", "null", 0 };
142+
const char** p = valid;
143+
while (*p != 0 && strcmp(*p, opt.m_output_type) != 0)
144+
p++;
145+
if (*p == 0)
146+
{
147+
util.set_error_usage(util.c_error, __LINE__,
148+
"invalid output-type %s", opt.m_output_type);
149+
return -1;
150+
}
130151
if (opt.m_output_workers < 1)
131152
{
132153
util.set_error_usage(util.c_error, __LINE__,

0 commit comments

Comments
 (0)