Sha256: 2f87c84cfb129e26f44d95d585e8d159c4637616b5e715b2fbfd86161c51111a

Contents?: true

Size: 1.35 KB

Versions: 15

Compression:

Stored size: 1.35 KB

Contents

module TreasureData
module Command

  def query(op)
    db_name = nil
    wait = false
    output = nil
    format = 'tsv'

    op.on('-d', '--database DB_NAME', 'use the database (required)') {|s|
      db_name = s
    }
    op.on('-w', '--wait', 'wait for finishing the job', TrueClass) {|b|
      wait = b
    }
    op.on('-o', '--output PATH', 'write result to the file') {|s|
      output = s
    }
    op.on('-f', '--format FORMAT', 'format of the result to write to the file (tsv, csv, json or msgpack)') {|s|
      unless ['tsv', 'csv', 'json', 'msgpack'].include?(s)
        raise "Unknown format #{s.dump}. Supported format: tsv, csv, json, msgpack"
      end
      format = s
    }

    sql = op.cmd_parse

    unless db_name
      $stderr.puts "-d, --database DB_NAME option is required."
      exit 1
    end

    client = get_client

    # local existance check
    get_database(client, db_name)

    job = client.query(db_name, sql)

    $stderr.puts "Job #{job.job_id} is queued."
    $stderr.puts "Use '#{$prog} job:show #{job.job_id}' to show the status."
    $stderr.puts "See #{job.url} to see the progress."

    if wait && !job.finished?
      wait_job(job)
      puts "Status     : #{job.status}"
      if job.success?
        puts "Result     :"
        show_result(job, output, format)
      end
    end
  end

  require 'td/command/job'  # wait_job
end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
td-0.10.4 lib/td/command/query.rb
td-0.10.3 lib/td/command/query.rb
td-0.10.2 lib/td/command/query.rb
td-0.10.1 lib/td/command/query.rb
td-0.10.0 lib/td/command/query.rb
td-0.9.12 lib/td/command/query.rb
td-0.9.11 lib/td/command/query.rb
td-0.9.10 lib/td/command/query.rb
td-0.9.9 lib/td/command/query.rb
td-0.9.8 lib/td/command/query.rb
td-0.9.7 lib/td/command/query.rb
td-0.9.6 lib/td/command/query.rb
td-0.9.5 lib/td/command/query.rb
td-0.9.4 lib/td/command/query.rb
td-0.9.3 lib/td/command/query.rb