Hi Fauna Community,
I am having issues with index bindings returning null values where a value should be found through the reference path. I believe the issue stems from my attempt to reverse the order of binding results (i.e. "reverse": True
)
Using the python driver, I create indexes relevant to individual location_hash
results corresponding the following command:
client.query(
q.create_index({
“name”: index_name,
“source”: {
“collection”: q.collection(“Recipe”),
“fields”: {
“sort_result”: q.query(
q.lambda_(
“doc”,
q.select([“data”, “algorithm_result” ,
location_hash],
q.var(“doc”))
)
)
}
},
“values”:
[
{ “binding”: “sort_result” ,
“reverse”: True },
{ “field”: [“ref”] }
]
}
)
)
With `location_hash`corresponding to a string like `"irpbgytrlp"` I get the following result:
{
data: [
[null, Ref(Collection("Recipe"), "287118064268345869")],
[null, Ref(Collection("Recipe"), "287118064279880205")],
[null, Ref(Collection("Recipe"), "287118064310288909")],
[null, Ref(Collection("Recipe"), "287118064339649037")],
[null, Ref(Collection("Recipe"), "287118064361669133")],
[null, Ref(Collection("Recipe"), "287118064393126413")],
[null, Ref(Collection("Recipe"), "287118064424583693")],
[null, Ref(Collection("Recipe"), "287118064448700941")],
[null, Ref(Collection("Recipe"), "287118064484352525")],
[null, Ref(Collection("Recipe"), "287118064496935437")],
[null, Ref(Collection("Recipe"), "287118064509518349")],
[null, Ref(Collection("Recipe"), "287118064531538445")],
[null, Ref(Collection("Recipe"), "287118064556704269")],
...]
}
Now if I were to perform a simple get/select
on the first result of the above index to simulate the sort_result
field I get the following indicating to me that the path is correct:
Select(["data", "algorithm_result" , "irpbgytrlp"], Get(Ref(Collection("Recipe"), "287118064268345869")))
0.377
>> Time elapsed: 178ms
I can’t understand why this binding won’t work as intended. Can anyone point out an issue with my index construction or is this a known issue with bindings?
Attempting to construct the same index without reversing sort_result
values as below works as i would have expected:
client.query(
q.create_index({
“name”: index_name,
“source”: {
“collection”: q.collection(“Recipe”),
“fields”: {
“sort_result”: q.query(
q.lambda_(
“doc”,
q.select([“data”, “algorithm_result” ,
location_hash],
q.var(“doc”))
)
)
}
},
“values”:
[
{ “binding”: “sort_result” },
{ “field”: [“ref”] }
]
}
)
)
This index using the same location_hash
provides the following result as expected:
{
data: [
[0.0529, Ref(Collection(“Recipe”), “287769033861759501”)],
[0.0607, Ref(Collection(“Recipe”), “287768961888551437”)],
[0.0659, Ref(Collection(“Recipe”), “287768990310203916”)],
[0.074, Ref(Collection(“Recipe”), “289612639276892685”)],
[0.0761, Ref(Collection(“Recipe”), “287769013402993164”)],
[0.0842, Ref(Collection(“Recipe”), “289612641747337741”)],
[0.0849, Ref(Collection(“Recipe”), “287769013018165772”)],
[0.0879, Ref(Collection(“Recipe”), “289614288444719629”)],
[0.089, Ref(Collection(“Recipe”), “289599237629411848”)],
[0.0897, Ref(Collection(“Recipe”), “287768990946689548”)],
[0.0899, Ref(Collection(“Recipe”), “289612672624755213”)],
[0.0906, Ref(Collection(“Recipe”), “289613888261980685”)],
[0.0921, Ref(Collection(“Recipe”), “289599357313876488”)],
[0.093, Ref(Collection(“Recipe”), “287769013318058508”)],
[0.098, Ref(Collection(“Recipe”), “287769023339299341”)],
[0.099, Ref(Collection(“Recipe”), “287769059566551560”)],
[0.0998, Ref(Collection(“Recipe”), “287118081464992269”)],
[0.0998, Ref(Collection(“Recipe”), “287769219663135245”)],
…]
}
Have I attempted to reverse the result incorrectly or is reversing the resulting order simply not possible across a binding value?
Please also accept my apologies for poor formatting, I can’t seem to find the block preformatting button on the new topic GUI.