def test_create_vertex_label(): cmd = "CREATE vertex movie" result = create_vertex.parseString(cmd)[0] assert isinstance(result, CreateVertex) result = parse_line(cmd) assert isinstance(result, CreateVertex) assert result.label == "movie" assert "buildVertexLabel" in str(result) assert "movie" in str(result) result2 = parse_line("CREATE vertex label movie") assert isinstance(result, CreateVertex)
def test_create_edge_index(): # NOT WORKING, property is on the edge # s = "CREATE OUT index ratedbyStars on edge rated(reviewer.stars)" s = "CREATE OUT INDEX ratedbyStars ON VERTEX reviewer ON EDGE rated(stars)" tmp = create_edge_index.parseString(s)[0] assert tmp.edge == "rated" assert tmp.direction == "OUT" assert tmp.name == "ratedbyStars" assert tmp.vertex == "reviewer" assert tmp.property == "stars" parse_line(s)
def test_create_index_fulltext(): s = "CREATE materialized INDEX movie_title_idx ON VERTEX movie(title )" result = create_vertex_index.parseString(s)[0] assert result.type == "materialized" assert result.label == 'movie' assert result.name == 'movie_title_idx' groovy = str(result) result = parse_line(s) s = "CREATE secondary INDEX movie_title_idx ON VERTEX movie(title )" result = create_vertex_index.parseString(s)[0] assert result.type == "secondary" s = "CREATE search INDEX movie_title_idx ON VERTEX movie(title )" result = create_vertex_index.parseString(s)[0] assert result.type == "search" result = parse_line(s)
def test_create_graph(): s = "CREATE GRAPH jon" parsed = parse_line(s) assert isinstance(parsed, CreateGraph) assert "system.createGraph('jon').build()" in str(parsed)
def test_describe_graph(): s = "describe graph" tmp = describe_graph.parseString(s)[0] parse_line(s)
def test_create_property(): result = parse_line("CREATE PROPERTY name text") assert isinstance(result, CreateProperty) result = parse_line("CREATE PROPERTY name TEXT") assert isinstance(result, CreateProperty)
def test_create_edge_label(): result = parse_line("CREATE edge rated") assert isinstance(result, CreateEdge) assert result.label == "rated" result2 = parse_line("CREATE edge label rated") assert isinstance(result2, CreateEdge)
def main(): arguments = docopt(__doc__) host = [arguments['--host']] if arguments["--host"] else ["localhost"] session = Cluster(host).connect() graph = arguments['<keyspace>'] if graph and graph not in session.cluster.metadata.keyspaces: print "Graph {}{}{} not found".format(Fore.RED, graph, Style.RESET_ALL) sys.exit(1) session.default_graph_options.graph_name = graph print Fore.GREEN + "Connected to {}/{}".format(host[0], graph) + Style.RESET_ALL accum = None eof = None print "Gremlin REPL, use heredocs for multiline ex:<<EOF, help for help\n" while True: graph = session.default_graph_options.graph_name prompt = "gremlin [{}/{}]> ".format( host[0], graph) if eof is None else "gremlin (cont)> " input = raw_input(prompt) output_time = False start_time = time.time() if input.startswith("<<"): # heredoc print "Multiline mode activated" eof = input[2:] accum = [] continue if eof and input == eof: eof = None input = "\n".join(accum) print input elif eof: accum.append(input) continue if input == "quit" or input == "exit": break if input == "%schema": continue if input == "help": print_help() continue if input == "docs": webbrowser.open( "http://docs.datastax.com/en/datastax_enterprise/5.0/datastax_enterprise/graph/graphTOC.html#graphTOC__missing-elem-id--graphTOC" ) continue total_time = None try: try: parsed = parse_line(input) result = parsed.execute(session) print_result_set(result) continue except ParseError as e: pass except Exception as e: print e continue stmt = SimpleGraphStatement(input) if input.startswith("a"): print Fore.GREEN + "Spark Graph Traversal Enabled, this may take a while..." + Style.RESET_ALL stmt.options.graph_source = "a" stmt.options.graph_alias = "a" start = time.time() result = session.execute_graph(stmt) total_time = time.time() - start except Exception as e: print e continue if isinstance(result, ResultSet): print_result_set(result) if total_time: print Fore.RED + "Query Time: {}s".format(round( total_time, 3)) + Style.RESET_ALL else: try: print "Unknown result", type(result), result except Exception as e: print e
def test_show_graphs(): s = "show graphs" parsed = parse_line(s) assert isinstance(parsed, ShowGraphs) assert "system.graphs" in str(parsed)
def main(): arguments = docopt(__doc__) host = [arguments['--host']] if arguments["--host"] else ["localhost"] session = Cluster(host).connect() graph = arguments['<keyspace>'] if graph and graph not in session.cluster.metadata.keyspaces: print "Graph {}{}{} not found".format(Fore.RED, graph, Style.RESET_ALL) sys.exit(1) session.default_graph_options.graph_name = graph print Fore.GREEN + "Connected to {}/{}".format(host[0], graph) + Style.RESET_ALL accum = None eof = None print "Gremlin REPL, use heredocs for multiline ex:<<EOF, help for help\n" while True: graph = session.default_graph_options.graph_name prompt = "gremlin [{}/{}]> ".format(host[0], graph) if eof is None else "gremlin (cont)> " input = raw_input(prompt) output_time = False start_time = time.time() if input.startswith("<<"): # heredoc print "Multiline mode activated" eof = input[2:] accum = [] continue if eof and input == eof: eof = None input = "\n".join(accum) print input elif eof: accum.append(input) continue if input == "quit" or input == "exit": break if input == "%schema": continue if input == "help": print_help() continue if input == "docs": webbrowser.open("http://docs.datastax.com/en/datastax_enterprise/5.0/datastax_enterprise/graph/graphTOC.html#graphTOC__missing-elem-id--graphTOC") continue total_time = None try: try: parsed = parse_line(input) result = parsed.execute(session) print_result_set(result) continue except ParseError as e: pass except Exception as e: print e continue stmt = SimpleGraphStatement(input) if input.startswith("a"): print Fore.GREEN + "Spark Graph Traversal Enabled, this may take a while..." + Style.RESET_ALL stmt.options.graph_source = "a" stmt.options.graph_alias = "a" start = time.time() result = session.execute_graph(stmt) total_time = time.time() - start except Exception as e: print e continue if isinstance(result, ResultSet): print_result_set(result) if total_time: print Fore.RED + "Query Time: {}s".format(round(total_time, 3)) + Style.RESET_ALL else: try: print "Unknown result", type(result), result except Exception as e: print e