Reputation: 25
When I send a request with Fiware orion-ld, it constantly changes the order. This needs to remain constant. What is the reason of this?
Sample data is as follows.
[ { "id": "urn:ngsi-ld:yilliktopluenerjituketimi:2f63e178-4e0e-4319-a3b4-0f9814b097f5", "type": "yilliktopluenerjituketimi", "ay": "Şubat", "co2EmisyonuDogalgazKgCo2": 25617.26832, "co2EmisyonuElektrikKgCo2": 209561.884, "co2EmisyonuYakitKgCo2": 26800, "dogalgazKwh": 126818.16, "elektrikKwh": 341306, "yakitKwh": 76019.875, "year": 2024 }, { "id": "urn:ngsi-ld:yilliktopluenerjituketimi:ad3f268a-18ad-4c7c-b4ca-3a2f6ee284f5", "type": "yilliktopluenerjituketimi", "ay": "Ocak", "co2EmisyonuDogalgazKgCo2": 25114.3368, "co2EmisyonuElektrikKgCo2": 214071.1, "co2EmisyonuYakitKgCo2": 30649.6, "dogalgazKwh": 124328.4, "elektrikKwh": 348650, "yakitKwh": 86939.506, "year": 2024 }, { "id": "urn:ngsi-ld:yilliktopluenerjituketimi:7b218913-2c1b-46ef-9be7-29f15c9d8986", "type": "yilliktopluenerjituketimi", "ay": "Mart", "co2EmisyonuDogalgazKgCo2": 28267.33056, "co2EmisyonuElektrikKgCo2": 219725.426, "co2EmisyonuYakitKgCo2": 31420.8, "dogalgazKwh": 139937.28, "elektrikKwh": 357859, "yakitKwh": 89127.063, "year": 2024 }, { "id": "urn:ngsi-ld:yilliktopluenerjituketimi:79f29c7f-8373-4b66-b8cc-a1b4bb73be15", "type": "yilliktopluenerjituketimi", "ay": "Nisan", "co2EmisyonuDogalgazKgCo2": 24282.56544, "co2EmisyonuElektrikKgCo2": 205822.01, "co2EmisyonuYakitKgCo2": 31305.6, "dogalgazKwh": 120210.72, "elektrikKwh": 335215, "yakitKwh": 88800.291, "year": 2024 }, { "id": "urn:ngsi-ld:yilliktopluenerjituketimi:431af7d3-1a6f-43f0-945d-8d05a7433f47", "type": "yilliktopluenerjituketimi", "ay": "Mayıs", "co2EmisyonuDogalgazKgCo2": 24705.9736, "co2EmisyonuElektrikKgCo2": 201862.938, "co2EmisyonuYakitKgCo2": 28041.6, "dogalgazKwh": 122306.8, "elektrikKwh": 328767, "yakitKwh": 79541.751, "year": 2024 }, { "id": "urn:ngsi-ld:yilliktopluenerjituketimi:b61d84c1-5596-45dc-a4f2-6a71fc37e540", "type": "yilliktopluenerjituketimi", "ay": "Haziran", "co2EmisyonuDogalgazKgCo2": 25890.22688, "co2EmisyonuElektrikKgCo2": 217440.118, "co2EmisyonuYakitKgCo2": 30758.4, "dogalgazKwh": 128169.44, "elektrikKwh": 354137, "yakitKwh": 87248.124, "year": 2024 } ]
Upvotes: 0
Views: 128
Reputation: 5290
Quite simply, maintaining an ordered list is not considered to be the job of a context broker. If you look at the current 1.7.1 NGSI-LD specification from ETSI and look for the words "sort" or "ordered", you'll find that maintaining order is simply not mentioned.
The reason for this is that a context broker is not a database. When you make an entity query such as /entities?type=Sensor&q=temperature>30
the context broker will return everything it locally knows about Sensors
with a temperature
currently above 30, and also interrogate remotely all of it registered context sources about Sensors
entities they know about which also have a temperature
currently above 30.
This distributed nature leads to the following problem regarding sort. Firstly registered context sources can be independently updated, so the query must always be made across all sources. Secondly any registered context source could be currently unavailable and thirdly timing is such that any registered context source could respond back in any order.
Internally a context broker does its best to collate all this information and return its holistically correct representation of the state of the system right now. Adding in another sort step after that would slow the response time of the broker itself. It is not necessary in most applications.
Now your user-agent can order the entities in a context broker response itself with a single line of code like:
ordered.sort((a, b) => a.id.localCompare(b.id));
Which doesn't add overhead to the broker, but does allow you to receive the data in a random order and make it consistent for you, in the manner that you require.
Besides which, which specific collation sort order would you expect? ASCII? German? Swedish? Lithuanian? All of these would result in a different order.
Since NGSI-LD doesn't mandate a specific backing database, you cannot make any inference about the default sort ordering that local entities are held.
Upvotes: 0