Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions lib/td/command/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def job_show(op)
format = 'tsv'
render_opts = {}
exclude = false
batch = false

op.on('-v', '--verbose', 'show logs', TrueClass) {|b|
verbose = b
Expand All @@ -110,6 +111,9 @@ def job_show(op)
op.on('-x', '--exclude', 'do not automatically retrieve the job result', TrueClass) {|b|
exclude = b
}
op.on('-B', '--batch', 'print results using tab as the column separator, with each row on a new line.', TrueClass) {|b|
batch = b
}

job_id = op.cmd_parse

Expand All @@ -132,13 +136,13 @@ def job_show(op)
wait_job(job)
if job.success? && [:hive, :pig, :impala].include?(job.type) && !exclude
puts "Result :"
show_result(job, output, format, render_opts)
show_result(job, output, format, render_opts, batch)
end

else
if job.success? && [:hive, :pig, :impala].include?(job.type) && !exclude
puts "Result :"
show_result(job, output, format, render_opts)
show_result(job, output, format, render_opts, batch)
end

if verbose
Expand Down Expand Up @@ -213,8 +217,23 @@ def wait_job(job)
end
end

def show_result(job, output, format, render_opts={})
if output
def show_result(job, output, format, render_opts={}, batch = nil)
if batch
print "\n"
job.result_each {|row|
first = true
row.each {|col|
if first
first = false
else
print "\t"
end
print dump_column(col)
}
print "\n"
}
print "\n"
elsif output
write_result(job, output, format)
puts "written to #{output} in #{format} format"
else
Expand Down
6 changes: 5 additions & 1 deletion lib/td/command/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def query(op)
sampling_all = nil
type = nil
exclude = false
batch = false

op.on('-g', '--org ORGANIZATION', "issue the query under this organization") {|s|
org = s
Expand Down Expand Up @@ -70,6 +71,9 @@ def query(op)
op.on('-x', '--exclude', 'do not automatically retrieve the job result', TrueClass) {|b|
exclude = b
}
op.on('-B', '--batch', 'print results using tab as the column separator, with each row on a new line.', TrueClass) {|b|
batch = b
}

sql = op.cmd_parse

Expand Down Expand Up @@ -114,7 +118,7 @@ def query(op)
puts "Status : #{job.status}"
if job.success? && !exclude
puts "Result :"
show_result(job, output, format, render_opts)
show_result(job, output, format, render_opts, batch)
end
end
end
Expand Down