Hi.
I’m facing a problem that seems like a bug.
If I do a var(…) query and apply some sort condition to it, and then use the exported var in a uid(var) subquery, the order that was supposed to be in the uids in the var is not enforced.
Here an example:
{
# Case 1: Ordering directly
test_1(func: has(__is_data_ocorrencia), orderasc: data) @filter(ge(data, "2018-08-01T03:00:00.000Z") and le(data, "2018-08-30T02:59:59.000Z")) @cascade @normalize{
uid
data: data
~data_ocorrencia @filter(NOT has(__is_deleted) AND eq(principal, "true") AND has(__is_ocorrencias)) {
uid
classificacoes @facets( orderdesc: _created_time) ( first: 1) @filter(NOT has(__is_deleted)) {
uid
}
}
}
# Case 2: same query but within a var, exporting "filtro" as var
var(func: has(__is_data_ocorrencia), orderasc: data) @filter(ge(data, "2018-08-01T03:00:00.000Z") and le(data, "2018-08-30T02:59:59.000Z")) @cascade @normalize{
uid
data: data
filtro as ~data_ocorrencia @filter(NOT has(__is_deleted) AND eq(principal, "true") AND has(__is_ocorrencias)) {
uid
classificacoes @facets( orderdesc: _created_time) ( first: 1) @filter(NOT has(__is_deleted)) {
uid
}
}
}
# Subquery based on "filtro" var can not be properly sorted
teste_2(func: uid(filtro)) @filter(NOT has(__is_deleted) AND eq(principal, "true")) @cascade{
uid
data_ocorrencia @filter(NOT has(__is_deleted) ) (orderasc: data) {
uid
data
}
}
}
Please observe that I do the exactly same query, first executing directly, and in the second case using it as a var query that sorts by “data” and fills “filtro” var to be used by the second query.
Here is the result, please observe that at the end you have “2018-08-21T19:28:11Z” correctly sorted in the first case and in the wrong position at the end, when using var.
{
"data": {
"test_1": [
{
"data": "2018-08-02T17:11:49Z",
"uid": "0xc1fb"
},
{
"data": "2018-08-07T16:25:39Z",
"uid": "0xc1ec"
},
{
"data": "2018-08-09T20:40:45Z",
"uid": "0xc1fc"
},
{
"data": "2018-08-13T18:49:50Z",
"uid": "0xc1fb"
},
{
"data": "2018-08-14T11:56:46Z",
"uid": "0xc1fb"
},
{
"data": "2018-08-14T13:48:00Z",
"uid": "0xc1ec"
},
{
"data": "2018-08-20T20:55:57Z",
"uid": "0xc1ec"
},
{
"data": "2018-08-21T19:28:11Z", # GOOD BOY!
"uid": "0xc1fb"
},
{
"data": "2018-08-22T13:12:00Z",
"uid": "0xc1ec"
},
{
"data": "2018-08-22T13:21:48Z",
"uid": "0xc1ec"
},
{
"data": "2018-08-22T13:28:00Z",
"uid": "0xc1ec"
},
{
"data": "2018-08-22T19:17:03Z",
"uid": "0xc1fb"
}
],
"test_2": [
{
"uid": "0xc241",
"data_ocorrencia": [
{
"uid": "0xc242",
"data": "2018-08-02T17:11:49Z"
}
]
},
{
"uid": "0xc251",
"data_ocorrencia": [
{
"uid": "0xc250",
"data": "2018-08-07T16:25:39Z"
}
]
},
{
"uid": "0xc25a",
"data_ocorrencia": [
{
"uid": "0xc25b",
"data": "2018-08-09T20:40:45Z"
}
]
},
{
"uid": "0xc266",
"data_ocorrencia": [
{
"uid": "0xc267",
"data": "2018-08-13T18:49:50Z"
}
]
},
{
"uid": "0xc27d",
"data_ocorrencia": [
{
"uid": "0xc27e",
"data": "2018-08-14T11:56:46Z"
}
]
},
{
"uid": "0xc287",
"data_ocorrencia": [
{
"uid": "0xc285",
"data": "2018-08-14T13:48:00Z"
}
]
},
{
"uid": "0xc2a1",
"data_ocorrencia": [
{
"uid": "0xc29d",
"data": "2018-08-20T20:55:57Z"
}
]
},
{
"uid": "0xc2cf",
"data_ocorrencia": [
{
"uid": "0xc2cb",
"data": "2018-08-22T13:12:00Z"
}
]
},
{
"uid": "0xc2d2",
"data_ocorrencia": [
{
"uid": "0xc2d0",
"data": "2018-08-22T13:21:48Z"
}
]
},
{
"uid": "0xc2da",
"data_ocorrencia": [
{
"uid": "0xc2d8",
"data": "2018-08-22T13:28:00Z"
}
]
},
{
"uid": "0xc2e1",
"data_ocorrencia": [
{
"uid": "0xc2e2",
"data": "2018-08-22T19:17:03Z"
}
]
},
{
"uid": "0xc30f",
"data_ocorrencia": [
{
"uid": "0xc31b",
"data": "2018-08-21T19:28:11Z" #BAD GUY
}
]
}
]
},
"extensions": {
"server_latency": {
"parsing_ns": 134762,
"processing_ns": 19092756,
"encoding_ns": 2610135
},
"txn": {
"start_ts": 300428,
"lin_read": {
"ids": {
"1": 326788
}
}
}
}
}
Please, any help?