Class: Zillabyte::API::Queries

Inherits:
Base
  • Object
show all
Defined in:
lib/zillabyte/api/queries.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize, #request

Constructor Details

This class inherits a constructor from Zillabyte::API::Base

Instance Method Details

#agnostic(expression, options = {}) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/zillabyte/api/queries.rb', line 57

def agnostic(expression, options = {})
  case expression
  when Array
    res = sxp(expression, :post, options)
  when String
    res = sql(expression, :post, options)
    col_aliases = res["column_aliases"] #save the column aliases
  else
    throw "unknown expression type: #{expression}"
  end

  options[:job_id] = res["job_id"]
  res = {'status' => nil}
  while(res['status'] != 'completed')
    res = sql(expression, :get, options)
  end
  res["return"]["column_aliases"] = col_aliases if col_aliases #send the column aliases back too
  res["return"]
end

#pull_to_s3(query, options) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/zillabyte/api/queries.rb', line 22

def pull_to_s3(query, options)
  options = {
    'query' => query
  }.merge(options)

  res = @api.request(
    :expects => 200,
    :method  => :post,
    :path    => "/query_pull_to_s3",
    :body    => options.to_json
  )
  res.body
end

#sql(expression, method, options = {}) ⇒ Object

GET /sql



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/zillabyte/api/queries.rb', line 38

def sql(expression, method, options = {})

  options = {
    'sql' => expression
  }.merge(options)
  
  res = request(
    :expects  => 200,
    :method   => method,
    :path     => "/query_sql",
    :body     => options.to_json
  )
  
  res.body

end

#sxp(expression, method, options = {}) ⇒ Object

GET /sxp



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/zillabyte/api/queries.rb', line 5

def sxp(expression, method, options = {})

  options = {
    'sxp' => expression
  }.merge(options)
  
  res = request(
    :expects  => 200,
    :method   => method,
    :path     => "/query_sxp",
    :body     => options.to_json
  )
  
  res.body

end