Closed desmondcheongzx closed 3 years ago
One issue with a hashset implementation is that results are returned out of order. For example, say a client fed in this data:
{"Write": {"name": "disk", "labels": {"hostname": "host_desmond"}, "variables": {"total": 1099511627776.0}, "timestamp": "2016-01-01 00:04:00+00:00"}}
{"Write": {"name": "disk", "labels": {"hostname": "host_desmond"}, "variables": {"total": 2}, "timestamp": "2016-01-01 00:05:00+00:00"}}
{"Write": {"name": "disk", "labels": {"hostname": "host_desmond"}, "variables": {"total": 4}, "timestamp": "2016-01-01 00:06:00+00:00"}}
And then makes the following query:
{"Select": {"name": "test", "predicate":{"name": "test","condition":{"Leaf":{"lhs": {"LabelKey": "hostname"},"rhs": {"LabelValue": "host_desmond"},"op": "Eq"}}}}}
The following are some results returned by the server:
Received statement: Select { name: "test", predicate: Predicate { name: "test", condition: Leaf(Condition { lhs: LabelKey("hostname"), rhs: LabelValue("host_desmond"), op: Eq }) } }
Received result: [Record { name: "disk", labels: {"hostname": "host_desmond"}, variables: {"total": 1099511627776.0}, timestamp: 2016-01-01T00:04:00Z }, Record { name: "disk", labels: {"hostname": "host_desmond"}, variables: {"total": 4.0}, timestamp: 2016-01-01T00:06:00Z }, Record { name: "disk", labels: {"hostname": "host_desmond"}, variables: {"total": 2.0}, timestamp: 2016-01-01T00:05:00Z }]
Received statement: Select { name: "test", predicate: Predicate { name: "test", condition: Leaf(Condition { lhs: LabelKey("hostname"), rhs: LabelValue("host_desmond"), op: Eq }) } }
Received result: [Record { name: "disk", labels: {"hostname": "host_desmond"}, variables: {"total": 2.0}, timestamp: 2016-01-01T00:05:00Z }, Record { name: "disk", labels: {"hostname": "host_desmond"}, variables: {"total": 4.0}, timestamp: 2016-01-01T00:06:00Z }, Record { name: "disk", labels: {"hostname": "host_desmond"}, variables: {"total": 1099511627776.0}, timestamp: 2016-01-01T00:04:00Z }]
Received statement: Select { name: "test", predicate: Predicate { name: "test", condition: Leaf(Condition { lhs: LabelKey("hostname"), rhs: LabelValue("host_desmond"), op: Eq }) } }
Received result: [Record { name: "disk", labels: {"hostname": "host_desmond"}, variables: {"total": 4.0}, timestamp: 2016-01-01T00:06:00Z }, Record { name: "disk", labels: {"hostname": "host_desmond"}, variables: {"total": 2.0}, timestamp: 2016-01-01T00:05:00Z }, Record { name: "disk", labels: {"hostname": "host_desmond"}, variables: {"total": 1099511627776.0}, timestamp: 2016-01-01T00:04:00Z }]
...
The first result returns entries 1, 3, then 2. The second result returns entries 2, 3, then 1. The third result returns entries 3, 2, then 1. etc.
Finishing up our discussion from this afternoon, this is an implementation of statement evaluation via hashsets of records.