使用我有的快速入门示例:
[{
"id": "thomas",
"label": "person",
"type": "vertex",
"outE": {
"knows": [
{
"id": "edd08c25-cd6d-43e6-ad10-e1806f63cb90",
"inV": "mary"
},
{
"id": "e30693c4-019c-42fc-8968-3b6cd37fb279",
"inV": "ben"
}
]
},
"properties": {
"firstName": [
{
"id": "3c401844-d30a-4046-a833-3f378ee52a30",
"value": "Thomas"
}
],
"age": [
{
"id": "1cacf839-daa3-415f-8930-f4bedd15f803",
"value": 44
}
]
}
},{
"id": "mary",
"label": "person",
"type": "vertex",
"inE": {
"knows": [
{
"id": "edd08c25-cd6d-43e6-ad10-e1806f63cb90",
"outV": "thomas"
}
]
},
"properties": {
"firstName": [
{
"id": "c8edabe7-10d5-4ef9-922b-4e6382c7d902",
"value": "Mary"
}
],
"lastName": [
{
"id": "64f60649-278d-40d5-a511-b28970facc1d",
"value": "Andersen"
}
],
"age": [
{
"id": "d8bd7758-baf0-4f5f-bd07-fa96d125fcd8",
"value": 39
}
]
}
},{
"id": "ben",
"label": "person",
"type": "vertex",
"inE": {
"knows": [
{
"id": "e30693c4-019c-42fc-8968-3b6cd37fb279",
"outV": "thomas"
}
]
},
"outE": {
"knows": [
{
"id": "f8f136b0-d698-49d9-bb0a-f6291454d99a",
"inV": "robin"
}
]
},
"properties": {
"firstName": [
{
"id": "2e0e52ac-4890-42bc-bc9e-0594c093d72c",
"value": "Ben"
}
],
"lastName": [
{
"id": "b0367dd4-e559-4421-9e92-bdae80e41d0f",
"value": "Miller"
}
]
}
},{
"id": "robin",
"label": "person",
"type": "vertex",
"inE": {
"knows": [
{
"id": "f8f136b0-d698-49d9-bb0a-f6291454d99a",
"outV": "ben"
}
]
},
"properties": {
"firstName": [
{
"id": "3f9edd99-09ab-40cb-99e7-8ef280618aae",
"value": "Robin"
}
],
"lastName": [
{
"id": "76327942-3fcc-46a7-9ebd-a8df1141ec57",
"value": "Wakefield"
}
]
}
}]
当我尝试按年龄排序时,
g.V().hasLabel('person').order().by('age', decr)
发生此异常:
Gremlin查询执行错误:订单:下一步:订单提供的遍历或属性名称未映射到值。
System.InvalidOperationException: Failed to compare two elements in the array. ---> Microsoft.Azure.Graphs.Common.GraphRuntimeException: Gremlin Query Execution Error: Order: Next: The provided traversal or property name of Order does not map to a value.
at Microsoft.Azure.Graphs.Runtime.Operators.OrderOperator.<ComputeNextRecordAsync>b__5_0(RawRecord x, RawRecord y)
at System.Collections.Generic.ArraySortHelper`1.InsertionSort(T[] keys, Int32 lo, Int32 hi, IComparer`1 comparer)
at System.Collections.Generic.ArraySortHelper`1.IntrospectiveSort(T[] keys, Int32 left, Int32 length, IComparer`1 comparer)
at System.Collections.Generic.ArraySortHelper`1.Sort(T[] keys, Int32 index, Int32 length, IComparer`1 comparer)
--- End of inner exception stack trace ---
at System.Collections.Generic.ArraySortHelper`1.Sort(T[] keys, Int32 index, Int32 length, IComparer`1 comparer)
at System.Array.Sort[T](T[] array, Int32 index, Int32 length, IComparer`1 comparer)
at System.Collections.Generic.List`1.Sort(Comparison`1 comparison)
at Microsoft.Azure.Graphs.Runtime.Operators.OrderOperator.<ComputeNextRecordAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Graphs.Runtime.Operators.GraphExecutionOperator.<NextAsync>d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Graphs.Runtime.TableValuedFunction.<ComputeNextRecordAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Graphs.Runtime.Operators.GraphExecutionOperator.<NextAsync>d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Graphs.Runtime.Operators.ProjectOperator.<ComputeNextRecordAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Graphs.Runtime.Operators.GraphExecutionOperator.<NextAsync>d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Graphs.GraphTraversal.GraphTraversalIterator.<CurrentOperatorNextAsync>d__17.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Graphs.GraphTraversal.GraphTraversalIterator.<MoveNextAsync>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Graphs.GraphTraversal.<MoveNextAsync>d__17.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Graphs.GremlinDocumentQuery`1.<ExecuteNextAsync>d__15`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Graphs.GremlinDocumentQuery`1.<ExecuteNextAsync>d__14.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Documents.Portal.PlatformProxy.Graph.Controllers.GremlinQueriesController.<SubmitQueryAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Documents.Portal.PlatformProxy.Graph.Controllers.GremlinQueriesController.<Post>d__0.MoveNext()
如何按年龄订购,因为并非所有Vertex都设置了年龄属性?
答案 0 :(得分:2)
只需过滤掉没有DIV
属性的顶点:
age
所以在你的情况下:
gremlin> g.V().order().by('age', decr)
The property does not exist as the key has no associated value for the provided element: v[3]:age
Type ':help' or ':h' for help.
Display stack trace? [yN]n
gremlin> g.V().has('age').order().by('age', decr)
==>v[6]
==>v[4]
==>v[1]
==>v[2]