Skip to content

Commit da88f0b

Browse files
committed
connector:issue recommend use arugument
now `--database` and `--table` is obsolete
1 parent 0f9fe12 commit da88f0b

File tree

3 files changed

+65
-12
lines changed

3 files changed

+65
-12
lines changed

lib/td/command/connector.rb

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,28 +104,43 @@ def connector_preview(op)
104104
$stdout.puts cmd_render_table(rows, :fields => fields, :render_format => op.render_format, :resize => false)
105105

106106
$stdout.puts "Update #{config_file} and use '#{$prog} " + Config.cl_options_string + "connector:preview #{config_file}' to preview again."
107-
$stdout.puts "Use '#{$prog} " + Config.cl_options_string + "connector:issue #{config_file}' to run Server-side bulk load."
107+
$stdout.puts "Use '#{$prog} " + Config.cl_options_string + "connector:issue database_name table_name #{config_file}' to run Server-side bulk load."
108108
end
109109

110110
def connector_issue(op)
111-
database = table = nil
112-
time_column = nil
113-
wait = exclude = false
114-
auto_create = false
115-
116-
op.on('--database DB_NAME', "destination database") { |s| database = s }
117-
op.on('--table TABLE_NAME', "destination table") { |s| table = s }
111+
option_database = option_table = nil
112+
time_column = nil
113+
wait = exclude = false
114+
auto_create = false
115+
116+
op.on('--database DB_NAME', "(obsoleted)") { |s|
117+
$stderr.puts '--database is obsolete option'
118+
option_database = s
119+
}
120+
op.on('--table TABLE_NAME', "(obsoleted)") { |s|
121+
$stderr.puts '--table is obsolete option'
122+
option_table = s
123+
}
118124
op.on('--time-column COLUMN_NAME', "data partitioning key") { |s| time_column = s } # unnecessary but for backward compatibility
119125
op.on('-w', '--wait', 'wait for finishing the job', TrueClass) { |b| wait = b }
120126
op.on('-x', '--exclude', 'do not automatically retrieve the job result', TrueClass) { |b| exclude = b }
121127
op.on('--auto-create-table', "Create table and database if doesn't exist", TrueClass) { |b|
122128
auto_create = b
123129
}
124130

125-
config_file = op.cmd_parse
131+
database, table, config_file = nil
132+
args = op.cmd_parse
133+
134+
if args.instance_of? String
135+
config_file = args
136+
database = option_database
137+
table = option_table
138+
else
139+
database, table, config_file = args
140+
end
126141

127-
required('--database', database)
128-
required('--table', table)
142+
required('database', database)
143+
required('table', table)
129144

130145
config = prepare_bulkload_job_config(config_file)
131146
(config['out'] ||= {})['time_column'] = time_column if time_column # TODO will not work once embulk implements multi-job

lib/td/command/list.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ def self.finishup
345345
add_list 'connector:guess', %w[config?], 'Run guess to generate connector config file', ["connector:guess config.yml -o td-bulkload.yml\n\nexample config.yml:#{connector_guess_example_config}"]
346346
add_list 'connector:preview', %w[config], 'Show preview of connector execution', ['connector:preview td-bulkload.yml']
347347

348-
add_list 'connector:issue', %w[config], 'Run one time connector execution', ['connector:issue td-bulkload.yml']
348+
add_list 'connector:issue', %w[config database table], 'Run one time connector execution', ['connector:issue example_db event_logs td-bulkload.yml']
349349

350350
add_list 'connector:list', %w[], 'Show list of connector sessions', ['connector:list']
351351
add_list 'connector:create', %w[name cron database table config], 'Create new connector session', ['connector:create connector1 "0 * * * *" connector_database connector_table td-bulkload.yml']

spec/td/command/connector_spec.rb

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,44 @@ module TreasureData::Command
8080
end
8181
end
8282

83+
describe 'database and table arguments' do
84+
let(:database) { 'database' }
85+
let(:table) { 'table' }
86+
let(:config) { {} }
87+
88+
before do
89+
client = double(:client)
90+
command.stub(:get_client).and_return(client)
91+
command.stub(:create_database_and_table_if_not_exist)
92+
command.stub(:prepare_bulkload_job_config).and_return(config)
93+
client.should_receive(:bulk_load_issue).with(database, table, {config: config}).and_return(1234)
94+
95+
subject
96+
end
97+
98+
context 'set --database and --table' do
99+
let(:option) {
100+
List::CommandParser.new("connector:issue", ["config"], ['database', 'table'], nil, [File.join("spec", "td", "fixture", "bulk_load.yml"), '--database', database, '--table', table], true)
101+
}
102+
103+
it 'show warning' do
104+
expect(stderr_io.string).to include '--database is obsolete option'
105+
expect(stderr_io.string).to include '--table is obsolete option'
106+
end
107+
end
108+
109+
context 'set arguments' do
110+
let(:option) {
111+
List::CommandParser.new("connector:issue", ["config", 'database', 'table'], [], nil, [database, table, File.join("spec", "td", "fixture", "bulk_load.yml")], true)
112+
}
113+
114+
it 'no warning' do
115+
expect(stderr_io.string).not_to include '--database is obsolete option'
116+
expect(stderr_io.string).not_to include '--table is obsolete option'
117+
end
118+
end
119+
end
120+
83121
describe 'queueing job' do
84122
let(:option) {
85123
List::CommandParser.new("connector:issue", ["config"], ['database', 'table'], nil, [File.join("spec", "td", "fixture", "bulk_load.yml"), '--database', 'database', '--table', 'table'], true)

0 commit comments

Comments
 (0)