Interactive Query¶
-
class
graphscope.interactive.query.
InteractiveQuery
(session, object_id, front_ip=None, front_port=None)[source]¶ InteractiveQuery class, is a simple wrapper around Gremlin-Python, which implements Gremlin within the Python language. It also can expose gremlin endpoint which can be used by any other standard gremlin console, with the method graph_url().
It also has a method called subgraph which can extract some fragments from origin graph, produce a new, smaller but concise graph stored in vineyard, which lifetime is independent from the origin graph.
User can either use execute() to submit a script, or use traversal_source() to get a GraphTraversalSource for further traversal.
-
__init__
(session, object_id, front_ip=None, front_port=None)[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
property
error_msg
¶
-
execute
(query)[source]¶ Execute gremlin querying scripts. Behind the scene, it uses gremlinpython to send the query.
- Parameters
query (str) – Scripts that written in gremlin quering language.
- Raises
RuntimeError – If the interactive script is not running.
- Returns
execution results
-
property
graph_url
¶ The gremlin graph url can be used with any standard gremlin console, e.g., tinkerpop.
-
property
object_id
¶ Get the vineyard object id of graph.
- Returns
object id
- Return type
str
-
property
status
¶
-
subgraph
(gremlin_script)[source]¶ Create a subgraph, which input is the result of the execution of gremlin_script. Any gremlin script that will output a set of edges can be used to contruct a subgraph. :param gremlin_script: gremlin script to be executed :type gremlin_script: str
- Raises
RuntimeError – If the interactive instance is not running.
- Returns
constructed subgraph. which is also stored in vineyard.
- Return type
Graph
-
traversal_source
()[source]¶ Create a GraphTraversalSource and return. Once g has been created using a connection, we can start to write Gremlin traversals to query the remote graph.
- Raises
RuntimeError – If the interactive script is not running.
Examples
sess = graphscope.session() graph = load_modern_graph(sess, modern_graph_data_dir) interactive = sess.gremlin(graph) g = interactive.traversal_source() print(g.V().both()[1:3].toList()) print(g.V().both().name.toList())
- Returns
GraphTraversalSource
-