Skip to content

Commit

Permalink
mysql generate embulk.conf
Browse files Browse the repository at this point in the history
  • Loading branch information
takkanm committed Aug 25, 2015
1 parent 1c72b5e commit 0d98317
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
23 changes: 13 additions & 10 deletions lib/td/command/import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ def generate_seed_confing(format, arg, options)
end
when 'mysql'
arg = arg[1] unless arg.class == String
{'in' => parse_mysql_args(arg, options), 'out' => {'mode' => 'append'}}
generate_mysql_config(arg, options)
else
# NOOP
end
Expand Down Expand Up @@ -433,30 +433,33 @@ def normalize_path_prefix(path)
path.gsub(/\*.*/, '')
end

def parse_mysql_args(arg, options)
def generate_mysql_config(arg, options)
mysql_url_regexp = Regexp.new("[jdbc:]*mysql://(?<host>[^:/]*)[:]*(?<port>[^/]*)/(?<db_name>.*)")

config = if (match = mysql_url_regexp.match(options['db_url']))
{
'type' => 'mysql',
'host' => match['host'],
'port' => match['port'] == '' ? 3306 : match['port'].to_i,
'database' => match['db_name'],
}
else
{
'type' => 'mysql',
'host' => '',
'port' => 3306,
'database' => '',
}
end

config.merge(
'user' => options['db_user'],
'password' => options['db_password'],
'table' => arg,
'select' => '*',
)
{
'in' => config.merge(
'type' => 'mysql',
'user' => options['db_user'],
'password' => options['db_password'],
'table' => arg,
'select' => '*',
),
'out' => td_output_config,
}
end

end
Expand Down
21 changes: 11 additions & 10 deletions spec/td/command/import_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,15 @@ module TreasureData::Command
end

context 'support format' do
let(:td_output_config) {
{
'type' => 'td',
'endpoint' => Config.endpoint,
'apikey' => Config.apikey,
'database' => '',
'table' => '',
}
}
before do
command.import_config(option)
end
Expand All @@ -224,13 +233,7 @@ module TreasureData::Command
'decorders' => [{'type' => 'gzip'}],
'path_prefix' => path_prefix,
},
'out' => {
'type' => 'td',
'endpoint' => Config.endpoint,
'apikey' => Config.apikey,
'database' => '',
'table' => '',
}
'out' => td_output_config
})
end
end
Expand Down Expand Up @@ -281,9 +284,7 @@ module TreasureData::Command
'table' => table,
'select' => "*",
},
'out' => {
'mode' => 'append'
}
'out' => td_output_config
}
}

Expand Down

0 comments on commit 0d98317

Please sign in to comment.