简体   繁体   English

如何识别Gremlin查询返回的内容? 像顶点或边或标签等

[英]How can I identify what is being returned from a Gremlin query? Like vertices or edges or labels, etc

I have a Java application which allows user to push Gremlin queries from UI and those queries are executed at a backend gremlin server. 我有一个Java应用程序,允许用户从UI推送Gremlin查询,这些查询在后端gremlin服务器上执行。

I want to know what is being returned in the ResultSet. 我想知道ResultSet中返回的内容。 It can be a list of Vertices or list of Edges or it can be list of String (may be labels) as well. 它可以是顶点列表或边缘列表,也可以是字符串列表(也可以是标签)。 So that I can show proper UI pertaining to that type of object being returned. 这样我就可以显示与返回的那种对象有关的适当UI。

There is no certainty what is being returned just be looking at the initial part of query. 只是在查看查询的初始部分时,无法确定返回的内容。 For example: 例如:

g.V() // returns list of Vertices
g.V().outE() // returns list of Edges
g.E().outV() // returns list of Vertices
g.E().outV().label() // returns list of Strings

String query = "g.E().outV().label()";
ResultSet resultSet = client.submit(query);
resultSet.forEach(result -> result.getString()); // getString or getVertex or getEdge ???

Analysing whole query to identify the returned object is not an intelligent and foolproof approach. 分析整个查询以识别返回的对象并不是一种智能且简单的方法。

What can be the best approach to identify the return type? 什么是识别返回类型的最佳方法? Besides trying all with try...catch and then choosing wherever it succeeded. 除了尝试所有尝试...捕获然后选择它成功的地方。

You really don't have much choice but to test the result to see its type. 您真的没有太多选择,只能测试结果以查看其类型。 Gremlin results are also not always homogeneous. Gremlin结果也不总是同质的。 For example, someone could send this: 例如,有人可以发送:

g.V(1).outE().path().
  unfold().
  inject(1, [1L, "xyz", [x:"don't care that this traversal is crazy"]], Double.NaN)

Forget that no one would likely do that and just consider that they could. 忘记没有人会这样做,只考虑他们可以。 You get a mix of vertices, edges, a list with a long a double and embedded map. 您可以混合使用顶点,边缘,带有长双精度和嵌入式映射的列表。 You don't know the result until you have it and even then you may need to detect the types inside of the container collections. 在获得结果之前,您不知道结果,即便如此,您可能需要检测容器集合中的类型。 If you have different sorts of rendering in your UI for each type you have no choice but to recursively do type detection. 如果在UI中为每种类型提供不同类型的渲染,则别无选择,只能递归进行类型检测。 You will probably also want some sort of default rendering that can handle things you don't know how to render. 您可能还需要某种默认渲染,它可以处理您不知道如何渲染的内容。

If you switch off from Gryo serialization (I presume you're using that as the default for your client ) to GraphSON you do get a more reduced set of types to expect. 如果您从Gryo序列化(我认为您将其用作client的默认设置)切换到GraphSON,您可以获得更多减少的类型。 You can see those in the IO documentation . 您可以在IO文档中看到这些内容

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 gremlin查询以检索在它们之间具有多个边的顶点 - gremlin query to retrieve vertices which are having multiple edges between them 如何使用Jung定义边或顶点的属性? - How can i define the attributes of edges or vertices by using Jung? 如何通过 Gremlin 查询具有 OR 关系的多条边 - how to query multiple edges with OR relationship by Gremlin 如何使用 addV 在 gremlin-java 中插入未知数量的顶点? - How can I use addV to insert an unknown number of vertices in gremlin-java? 在java中的gremlin titan中过滤出顶点数量上的顶点 - filter vertices on number of outgoing edges in gremlin titan in java 如何从屏幕截图中识别/识别不同类型的对象(文本字段,标签,按钮等)? - How to recognize/identify different types of objects (textfields, labels, buttons etc) on screen/ from screenshots? 我可以将我的Java类注册为OrientDB Vertices和/或Edges吗? - Can I register my Java classes as OrientDB Vertices and/or Edges? Gremlin 查询以获取以前缀开头的顶点 - Gremlin query to get vertices starting with a prefix 一个 Gremlin 查询以获取多个顶点的所有连接顶点 - One Gremlin query to get all connected vertices for multiple vertices 如何识别作为函数参数的抽象对象的类? - How can I identify the class of an abstract object being an argument to a function?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM