Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

removed ResultSet and added result features

  • Loading branch information...
commit b9a1f0b9e046707fa994e57265dc0c6706760056 1 parent d038431
@frsyuki frsyuki authored
Showing with 63 additions and 107 deletions.
  1. +25 −37 lib/td/client.rb
  2. +27 −37 lib/td/client/api.rb
  3. +11 −33 lib/td/client/model.rb
View
62 lib/td/client.rb
@@ -104,33 +104,30 @@ def tail(db_name, table_name, count, to=nil, from=nil, &block)
end
# => Job
- def query(db_name, q, rset=nil)
- job_id = @api.hive_query(q, db_name, rset)
- Job.new(self, job_id, :hive, q) # TODO url
+ def query(db_name, q, result_url=nil)
+ job_id = @api.hive_query(q, db_name, result_url)
+ Job.new(self, job_id, :hive, q)
end
# => [Job]
def jobs(from=nil, to=nil)
result = @api.list_jobs(from, to)
- result.map {|job_id,type,status,query,start_at,end_at,rset|
- rset = ResultSet.new(self, rset) if rset
- Job.new(self, job_id, type, query, status, nil, nil, start_at, end_at, nil, rset)
+ result.map {|job_id,type,status,query,start_at,end_at,result_url|
+ Job.new(self, job_id, type, query, status, nil, nil, start_at, end_at, nil, result_url)
}
end
# => Job
def job(job_id)
job_id = job_id.to_s
- type, query, status, url, debug, start_at, end_at, rset, hive_result_schema = @api.show_job(job_id)
- rset = ResultSet.new(self, rset) if rset
- Job.new(self, job_id, type, query, status, url, debug, start_at, end_at, nil, rset, hive_result_schema)
+ type, query, status, url, debug, start_at, end_at, result_url, hive_result_schema = @api.show_job(job_id)
+ Job.new(self, job_id, type, query, status, url, debug, start_at, end_at, nil, result_url, hive_result_schema)
end
# => type:Symbol, url:String
def job_status(job_id)
- type, query, status, url, debug, start_at, end_at, rset, hive_result_schema = @api.show_job(job_id)
- rset = ResultSet.new(self, rset) if rset
- return query, status, url, debug, start_at, end_at, rset, hive_result_schema
+ type, query, status, url, debug, start_at, end_at, result_url, hive_result_schema = @api.show_job(job_id)
+ return query, status, url, debug, start_at, end_at, result_url, hive_result_schema
end
# => result:[{column:String=>value:Object]
@@ -154,8 +151,8 @@ def kill(job_id)
end
# => Job
- def export(db_name, tbl_name, storage_type, opts={})
- job_id = @api.export(db_name, tbl_name, storage_type, opts)
+ def export(db_name, table_name, storage_type, opts={})
+ job_id = @api.export(db_name, table_name, storage_type, opts)
Job.new(self, job_id, :export, nil)
end
@@ -175,9 +172,8 @@ def delete_schedule(name)
# [Schedule]
def schedules
result = @api.list_schedules
- result.map {|name,cron,query,database,rset,timezone,delay,next_time|
- rset = ResultSet.new(self, rset) if rset
- Schedule.new(self, name, cron, query, database, rset, timezone, delay, next_time)
+ result.map {|name,cron,query,database,result_url,timezone,delay,next_time|
+ Schedule.new(self, name, cron, query, database, result_url, timezone, delay, next_time)
}
end
@@ -189,9 +185,8 @@ def update_schedule(name, params)
# [ScheduledJob]
def history(name, from=nil, to=nil)
result = @api.history(name, from, to)
- result.map {|scheduled_at,job_id,type,status,query,start_at,end_at,rset|
- rset = ResultSet.new(self, rset) if rset
- ScheduledJob.new(self, scheduled_at, job_id, type, query, status, nil, nil, start_at, end_at, nil, rset)
+ result.map {|scheduled_at,job_id,type,status,query,start_at,end_at,result_url|
+ ScheduledJob.new(self, scheduled_at, job_id, type, query, status, nil, nil, start_at, end_at, nil, result_url)
}
end
@@ -208,30 +203,23 @@ def import(db_name, table_name, format, stream, size)
@api.import(db_name, table_name, format, stream, size)
end
- # => [ResultSet]
- def result_sets
- info, names = @api.list_result_set
- sets = names.map {|name|
- ResultSet.new(self, name)
+ # => [Result]
+ def results
+ results = @api.list_result
+ rs = results.map {|name,url|
+ Result.new(self, name, url)
}
- return sets
- end
-
- # => ResultSetInfo
- def result_set_info
- info, names = @api.list_result_set
- info = ResultSetInfo.new(self, *info)
- return info
+ return rs
end
# => true
- def create_result_set(name)
- @api.create_result_set(name)
+ def create_result(name, url)
+ @api.create_result(name, url)
end
# => true
- def delete_result_set(name)
- @api.delete_result_set(name)
+ def delete_result(name)
+ @api.delete_result(name)
end
# => [AggregationSchema]
View
64 lib/td/client/api.rb
@@ -270,7 +270,7 @@ def tail(db, table, count, to, from, &block)
## Job API
##
- # => [(jobId:String, type:Symbol, status:String, start_at:String, end_at:String, rset:String)]
+ # => [(jobId:String, type:Symbol, status:String, start_at:String, end_at:String, result_url:String)]
def list_jobs(from=0, to=nil)
params = {}
params['from'] = from.to_s if from
@@ -288,8 +288,8 @@ def list_jobs(from=0, to=nil)
query = m['query']
start_at = m['start_at']
end_at = m['end_at']
- rset = m['result']
- result << [job_id, type, status, query, start_at, end_at, rset]
+ result_url = m['result']
+ result << [job_id, type, status, query, start_at, end_at, result_url]
}
return result
end
@@ -374,9 +374,9 @@ def kill(job_id)
end
# => jobId:String
- def hive_query(q, db=nil, rset=nil)
+ def hive_query(q, db=nil, result_url=nil)
params = {'query' => q}
- params['result'] = rset if rset
+ params['result'] = result_url if result_url
code, body, res = post("/v3/job/issue/hive/#{e db}", params)
if code != "200"
raise_error("Query failed", res)
@@ -390,10 +390,10 @@ def hive_query(q, db=nil, rset=nil)
##
# => jobId:String
- def export(db, tbl, storage_type, opts={})
+ def export(db, table, storage_type, opts={})
params = opts.dup
params['storage_type'] = storage_type
- code, body, res = post("/v3/export/run/#{e db}/#{e tbl}", params)
+ code, body, res = post("/v3/export/run/#{e db}/#{e table}", params)
if code != "200"
raise_error("Export failed", res)
end
@@ -426,7 +426,7 @@ def delete_schedule(name)
return js['cron'], js["query"]
end
- # => [(name:String, cron:String, query:String, database:String, rset:String)]
+ # => [(name:String, cron:String, query:String, database:String, result_url:String)]
def list_schedules
code, body, res = get("/v3/schedule/list")
if code != "200"
@@ -439,11 +439,11 @@ def list_schedules
cron = m['cron']
query = m['query']
database = m['database']
- rset = m['result']
+ result_url = m['result']
timezone = m['timezone']
delay = m['delay']
next_time = m['next_time']
- result << [name, cron, query, database, rset, timezone, delay, next_time]
+ result << [name, cron, query, database, result_url, timezone, delay, next_time]
}
return result
end
@@ -474,8 +474,8 @@ def history(name, from=0, to=nil)
start_at = m['start_at']
end_at = m['end_at']
scheduled_at = m['scheduled_at']
- rset = m['result']
- result << [scheduled_at, job_id, type, status, query, start_at, end_at, rset]
+ result_url = m['result']
+ result << [scheduled_at, job_id, type, status, query, start_at, end_at, result_url]
}
return result
end
@@ -515,46 +515,36 @@ def import(db, table, format, stream, size)
####
- ## Result set API
+ ## Result API
##
- # => (
- # info:(type:String, host:String, port:Integer, database:String, user:String, pass:String)
- # entries:[name:String]
- # )
- def list_result_set
+ def list_result
code, body, res = get("/v3/result/list")
if code != "200"
- raise_error("List result set failed", res)
- end
- js = checked_json(body, %w[host port user pass])
- type = (js["type"] || 'unknown').to_s
- host = js["host"].to_s
- port = js["port"].to_i
- database = js["database"].to_s
- user = js["user"].to_s
- pass = js["pass"].to_s
- names = (js["results"] || []).map {|rsets|
- rsets['name'].to_s
+ raise_error("List result table failed", res)
+ end
+ js = checked_json(body, %w[results])
+ result = []
+ js['results'].map {|m|
+ result << [m['name'], m['url']]
}
- info = [type, host, port, database, user, pass]
- return info, names
+ return result
end
# => true
- def create_result_set(db)
- code, body, res = post("/v3/result/create/#{e db}")
+ def create_result(name, url)
+ code, body, res = post("/v3/result/create/#{e name}", {'url'=>url})
if code != "200"
- raise_error("Create result set failed", res)
+ raise_error("Create result table failed", res)
end
return true
end
# => true
- def delete_result_set(db)
- code, body, res = post("/v3/result/delete/#{e db}")
+ def delete_result(name)
+ code, body, res = post("/v3/result/delete/#{e name}")
if code != "200"
- raise_error("Delete result set failed", res)
+ raise_error("Delete result table failed", res)
end
return true
end
View
44 lib/td/client/model.rb
@@ -175,7 +175,7 @@ class Job < Model
STATUS_KILLED = "killed"
FINISHED_STATUS = [STATUS_SUCCESS, STATUS_ERROR, STATUS_KILLED]
- def initialize(client, job_id, type, query, status=nil, url=nil, debug=nil, start_at=nil, end_at=nil, result=nil, rset=nil, hive_result_schema=nil)
+ def initialize(client, job_id, type, query, status=nil, url=nil, debug=nil, start_at=nil, end_at=nil, result=nil, result_url=nil, hive_result_schema=nil)
super(client)
@job_id = job_id
@type = type
@@ -186,11 +186,11 @@ def initialize(client, job_id, type, query, status=nil, url=nil, debug=nil, star
@start_at = start_at
@end_at = end_at
@result = result
- @rset = rset
+ @result_url = result_url
@hive_result_schema = hive_result_schema
end
- attr_reader :job_id, :type, :rset
+ attr_reader :job_id, :type, :result_url
attr_reader :hive_result_schema
def wait(timeout=nil)
@@ -231,10 +231,6 @@ def end_at
@end_at && !@end_at.empty? ? Time.parse(@end_at) : nil
end
- def rset_name
- @rset ? @rset.name : nil
- end
-
def result
unless @result
return nil unless finished?
@@ -286,7 +282,7 @@ def killed?
end
def update_status!
- query, status, url, debug, start_at, end_at, rset, hive_result_schema = @client.job_status(@job_id)
+ query, status, url, debug, start_at, end_at, result_url, hive_result_schema = @client.job_status(@job_id)
@query = query
@status = status
@url = url
@@ -312,23 +308,19 @@ def scheduled_at
class Schedule < Model
- def initialize(client, name, cron, query, database=nil, rset=nil, timezone=nil, delay=nil, next_time=nil)
+ def initialize(client, name, cron, query, database=nil, result_url=nil, timezone=nil, delay=nil, next_time=nil)
super(client)
@name = name
@cron = cron
@query = query
@database = database
- @rset = rset
+ @result_url = result_url
@timezone = timezone
@delay = delay
@next_time = next_time
end
- def rset_name
- @rset ? @rset.name : nil
- end
-
- attr_reader :name, :cron, :query, :database, :rset, :timezone, :delay
+ attr_reader :name, :cron, :query, :database, :result_url, :timezone, :delay
def next_time
@next_time ? Time.parse(@next_time) : nil
@@ -340,28 +332,14 @@ def run(time, num)
end
-class ResultSetInfo < Model
- def initialize(client, type, host, port, database, user, password)
- super(client)
- @type = type
- @host = host
- @port = port
- @database = database
- @user = user
- @password = password
- end
-
- attr_reader :type, :host, :port, :database, :user, :password
-end
-
-
-class ResultSet < Model
- def initialize(client, name)
+class Result < Model
+ def initialize(client, name, url)
super(client)
@name = name
+ @url = url
end
- attr_reader :name
+ attr_reader :name, :url
end
Please sign in to comment.
Something went wrong with that request. Please try again.