Lassen Sie ein Diagramm auf Datastax Enterprise Graph (Version 5.1) ausführen, das auf Cassandra-Speicher ausgeführt wird. Der Versuch, eine Abfrage auszuführen, um die ID und die Eigenschaft abzurufen. In Gremlin-Konsole kann ich dies tun:Gremlin Python-Projekt Nach Klausel
gremlin> g.V(1).project("v", "properties").by().by(valueMap())
==>[v:v[1],properties:[name:[marko],age:[29]]]
Wie kann ich den valueMap Anruf noch mit Python GraphTraversal API übersetzen. Ich weiß, dass ich eine direkte Abfrage über Session Execution wie folgt ausführen kann.
session.execute_graph("g.V().has(\"Node_Name\",\"A\").project(\"v\", \"properties\").by().by(valueMap())",{"name":graph_name})
Unten ist mein Setup-Code.
from dse.cluster import Cluster, EXEC_PROFILE_GRAPH_DEFAULT
from dse_graph import DseGraph
from dse.cluster import GraphExecutionProfile, EXEC_PROFILE_GRAPH_SYSTEM_DEFAULT
from dse.graph import GraphOptions
from gremlin_python.process.traversal import T
from gremlin_python.process.traversal import Order
from gremlin_python.process.traversal import Cardinality
from gremlin_python.process.traversal import Column
from gremlin_python.process.traversal import Direction
from gremlin_python.process.traversal import Operator
from gremlin_python.process.traversal import P
from gremlin_python.process.traversal import Pop
from gremlin_python.process.traversal import Scope
from gremlin_python.process.traversal import Barrier
graph_name = "TEST"
graph_ip = ["127.0.0.1"]
graph_port = 9042
schema = """
schema.edgeLabel("Group").create();
schema.propertyKey("Version").Text().create();
schema.edgeLabel("Group").properties("Version").add()
schema.vertexLabel("Example").create();
schema.edgeLabel("Group").connection("Example", "Example").add()
schema.propertyKey("Node_Name").Text().create();
schema.vertexLabel("Example").properties("Node_Name").add()
schema.vertexLabel("Example").index("exampleByName").secondary().by("Node_Name").add();
"""
profile = GraphExecutionProfile(
graph_options=GraphOptions(graph_name=graph_name))
client = Cluster(
contact_points=graph_ip, port=graph_port,
execution_profiles={EXEC_PROFILE_GRAPH_DEFAULT: profile}
)
graph_name = graph_name
session = client.connect()
graph = DseGraph.traversal_source(session)
# force the schema to be clean
session.execute_graph(
"system.graph(name).ifExists().drop();",
{'name': graph_name},
execution_profile=EXEC_PROFILE_GRAPH_SYSTEM_DEFAULT
)
session.execute_graph(
"system.graph(name).ifNotExists().create();",
{'name': graph_name},
execution_profile=EXEC_PROFILE_GRAPH_SYSTEM_DEFAULT
)
session.execute_graph(schema)
session.shutdown()
session = client.connect()
graph = DseGraph.traversal_source(session)
Update:
ich ich denke nicht das Problem deutlich gemacht. Es ist in Python und nicht in Gremlin Konsole. So läuft Code wie graph.V().has("Node_Name","A").project("v","properties").by().by(valueMap()).toList()
wird folgendes Ergebnis geben. Wie man die Gremlin-Abfrage ausführt, während sie noch auf der GLV-Ebene bleibt, und nicht auf eine Text-serialisierte Abfrage zu Gremlin-Server verzweigt?
Traceback (most recent call last):
File "graph_test.py", line 79, in <module>
graph.V().has("Node_Name","A").project("v", "properties").by().by(valueMap()).toList()
NameError: name 'valueMap' is not defined
ich denke, ich habe meine Frage nicht klar gemacht. Es ist in Python und ich kann valueMap nicht direkt in eine by() -Klausel setzen wie in der regulären Gremlin-Konsole. – ZhijieWang
Dieser Link sollte helfen: http://tinkerpop.apache.org/docs/current/reference/#_static_enums_and_methods –
Danke, ich denke, nicht viele Leute benutzen Gremlin Python. – ZhijieWang