Class: Teapot::TempestDB::TempestClient

Inherits:
Object
  • Object
show all
Defined in:
lib/tempest_db.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server, port) ⇒ TempestClient

Returns a new instance of TempestClient.

Parameters:

  • server (String)
  • port (Integer)


40
41
42
# File 'lib/tempest_db.rb', line 40

def initialize(server, port)
  @thrift_client = Teapot::TempestDB::TempestThriftClient.new(server, port)
end

Class Method Details

.jsonToValue(json_attribute) ⇒ Object

Parameters:

  • json_attribute (String)

Returns:

  • (Object)


46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/tempest_db.rb', line 46

def TempestClient.jsonToValue(json_attribute)
  if json_attribute[0] == '"'
    json_attribute[1...-1]
  elsif json_attribute == "true"
    true
  elsif json_attribute == "false"
    false
  elsif json_attribute == "null"
    nil
  else
    # If this isn't an int, the server made a mistake, and there isn't much the client can do.
    json_attribute.to_i
  end
end

Instance Method Details

#add_edge(edge_type, source_node, target_node) ⇒ Object

Parameters:



251
252
253
# File 'lib/tempest_db.rb', line 251

def add_edge(edge_type, source_node, target_node)
  add_edges(edge_type, [source_node], [target_node])
end

#add_edges(edge_type, source_nodes, target_nodes) ⇒ Object

Parameters:



242
243
244
245
246
# File 'lib/tempest_db.rb', line 242

def add_edges(edge_type, source_nodes, target_nodes)
  @thrift_client.with_retries { |executor|
    executor.addEdges(edge_type, source_nodes, target_nodes)
  }
end

#add_node(node) ⇒ Object

Parameters:



224
225
226
227
228
# File 'lib/tempest_db.rb', line 224

def add_node(node)
  @thrift_client.with_retries { |executor|
    executor.addNode(node)
  }
end

#connected_component(source, edge_types, max_size = (1 << 31) - 1) ⇒ Array<Teapot::TempestDB::Node>

Parameters:

Returns:



208
209
210
211
212
# File 'lib/tempest_db.rb', line 208

def connected_component(source, edge_types, max_size = (1 << 31) - 1)
  @thrift_client.with_retries { |executor|
    executor.connectedComponent(source, edge_types, max_size)
  }
end

#edge_count(edge_type) ⇒ Integer

Parameters:

  • edge_type (String)

Returns:

  • (Integer)


187
188
189
190
191
# File 'lib/tempest_db.rb', line 187

def edge_count(edge_type)
  @thrift_client.with_retries { |executor|
    executor.edgeCount(edge_type)
  }
end

#get_multi_node_attribute(nodes, attribute_name) ⇒ Hash

Parameters:

Returns:

  • (Hash)


64
65
66
67
68
69
# File 'lib/tempest_db.rb', line 64

def get_multi_node_attribute(nodes, attribute_name)
  node_to_json = @thrift_client.with_retries { |executor|
    executor.getMultiNodeAttributeAsJSON(nodes, attribute_name)
  }
  Hash[node_to_json.map{ |k,v| [k, TempestClient.jsonToValue(v)] }]
end

#get_node_attribute(node, attribute_name) ⇒ String

Parameters:

Returns:

  • (String)


74
75
76
# File 'lib/tempest_db.rb', line 74

def get_node_attribute(node, attribute_name)
  self.get_multi_node_attribute([node], attribute_name)[node]
end

#in_degree(edge_type, node) ⇒ Integer

Parameters:

Returns:

  • (Integer)


133
134
135
136
137
# File 'lib/tempest_db.rb', line 133

def in_degree(edge_type, node)
  @thrift_client.with_retries { |executor|
    executor.inDegree(edge_type, node)
  }
end

#in_neighbor(edge_type, node, i) ⇒ Teapot::TempestDB::Node

Parameters:

Returns:



171
172
173
174
175
# File 'lib/tempest_db.rb', line 171

def in_neighbor(edge_type, node, i)
  @thrift_client.with_retries { |executor|
    executor.inNeighbor(edge_type, node, i)
  }
end

#in_neighbors(edge_type, node) ⇒ Array<Teapot::TempestDB::Node>

Parameters:

Returns:



151
152
153
154
155
# File 'lib/tempest_db.rb', line 151

def in_neighbors(edge_type, node)
  @thrift_client.with_retries { |executor|
    executor.inNeighbors(edge_type, node)
  }
end

#k_step_in_neighbors_filtered(edge_type, source_node, k, sql_clause: "", degree_filter: {}, alternating: true) ⇒ Teapot::TempestDB::Node

Parameters:

  • edge_type (String)
  • source_node (Teapot::TempestDB::Node)
  • k (Integer)
  • sql_clause (String) (defaults to: "")
  • degree_filter (Hash) (defaults to: {})
  • alternating (Boolean) (defaults to: true)

Returns:



98
99
100
101
102
# File 'lib/tempest_db.rb', line 98

def k_step_in_neighbors_filtered(edge_type, source_node, k, sql_clause: "", degree_filter: {}, alternating: true)
  @thrift_client.with_retries { |executor|
    executor.kStepInNeighborsFiltered(edge_type, source_node, k, sql_clause, degree_filter, alternating)
  }
end

#k_step_out_neighbors_filtered(edge_type, source_node, k, sql_clause: "", degree_filter: {}, alternating: true) ⇒ Teapot::TempestDB::Node

Parameters:

  • edge_type (String)
  • source_node (Teapot::TempestDB::Node)
  • k (Integer)
  • sql_clause (String) (defaults to: "")
  • degree_filter (Hash) (defaults to: {})
  • alternating (Boolean) (defaults to: true)

Returns:



85
86
87
88
89
# File 'lib/tempest_db.rb', line 85

def k_step_out_neighbors_filtered(edge_type, source_node, k, sql_clause: "", degree_filter: {}, alternating: true)
  @thrift_client.with_retries { |executor|
    executor.kStepOutNeighborsFiltered(edge_type, source_node, k, sql_clause, degree_filter, alternating)
  }
end

#node_count(edge_type) ⇒ Integer

Parameters:

  • edge_type (String)

Returns:

  • (Integer)


179
180
181
182
183
# File 'lib/tempest_db.rb', line 179

def node_count(edge_type)
  @thrift_client.with_retries { |executor|
    executor.nodeCount(edge_type)
  }
end

#nodes(node_type, sql_clause) ⇒ Teapot::TempestDB::Node

Parameters:

  • node_type (String)
  • sql_clause (String)

Returns:



217
218
219
220
221
# File 'lib/tempest_db.rb', line 217

def nodes(node_type, sql_clause)
  @thrift_client.with_retries { |executor|
    executor.nodes(node_type, sql_clause)
  }
end

#out_degree(edge_type, node) ⇒ Integer

TODO: For methods that only need to be included (for irb auto-complete) and converted from camelCase to snake_case, is there a simple way of automating this?

Parameters:

Returns:

  • (Integer)


124
125
126
127
128
# File 'lib/tempest_db.rb', line 124

def out_degree(edge_type, node)
  @thrift_client.with_retries { |executor|
    executor.outDegree(edge_type, node)
  }
end

#out_neighbor(edge_type, node, i) ⇒ Teapot::TempestDB::Node

Parameters:

Returns:



161
162
163
164
165
# File 'lib/tempest_db.rb', line 161

def out_neighbor(edge_type, node, i)
  @thrift_client.with_retries { |executor|
    executor.outNeighbor(edge_type, node, i)
  }
end

#out_neighbors(edge_type, node) ⇒ Array<Teapot::TempestDB::Node>

Parameters:

Returns:



142
143
144
145
146
# File 'lib/tempest_db.rb', line 142

def out_neighbors(edge_type, node)
  @thrift_client.with_retries { |executor|
    executor.outNeighbors(edge_type, node)
  }
end

#ppr_single_target(edge_type, seed_nodes, target_node, bi_ppr_params) ⇒ Double

Parameters:

Returns:

  • (Double)


198
199
200
201
202
# File 'lib/tempest_db.rb', line 198

def ppr_single_target(edge_type, seed_nodes, target_node, bi_ppr_params)
  @thrift_client.with_retries { |executor|
    executor.pprSingleTarget(edge_type, seed_nodes, target_node, bi_ppr_params)
  }
end

#set_node_attribute(node, attribute_name, attribute_value) ⇒ Object

Parameters:



233
234
235
236
237
# File 'lib/tempest_db.rb', line 233

def set_node_attribute(node, attribute_name, attribute_value)
  @thrift_client.with_retries { |executor|
    executor.setNodeAttribute(node, attribute_name, attribute_value)
  }
end

#unique_node(node_type, sql_clause) ⇒ Teapot::TempestDB::Node

Convenience method to return the unique node node satisfying a condition

Parameters:

  • node_type (String)
  • sql_clause (String)

Returns:



108
109
110
111
112
113
114
115
116
# File 'lib/tempest_db.rb', line 108

def unique_node(node_type, sql_clause)
  matching_nodes = @thrift_client.with_retries { |executor|
    executor.nodes(node_type, sql_clause)
  }
  if matching_nodes.length != 1
    raise "Error: clause '#{sql_clause}' had #{matching_nodes.length} results"
  end
  matching_nodes[0]
end