In this last question I asked, I didn’t explain myself well… what I want is now that I have the updateID, I want to compare the last value of the updateID with the first value of the oldTemplateID column for the same plan_id and see if it has the same value.
So I made this query:
import “experimental/dynamic”
data =
from(bucket: “planner”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r._measurement =~ /^$measurement$/ and r[“environment”] =~ /^$environment$/ and r[“plan_id”] =~ /^$plan_id$/ and r[“step”] == “update-templates” and exists r[“oldTemplateId”])
|> pivot(rowKey: [“_time”], columnKey: [“_field”], valueColumn: “_value”)
|> group(columns: [“_measurement”,“plan_id”, “userId”, “procedure”, “modality”])
first =
data
|> first(column: “oldTemplateId”)
|> set(key: “context”, value: “oldTemplateId_first”)
last =
data
|> last(column: “updatedTemplate”)
|> map(fn: (r) => {
_templateAsBytes = bytes(v: r[“updatedTemplate”])
_templateParsed = dynamic.jsonParse(data: _templateAsBytes)
_templateTyped = {
id: string(v: _templateParsed.id),
fragmentName: string(v: _templateParsed.fragmentName),
name: string(v: _templateParsed.name),
}
return {r with context: "updateID_last", updateID: string(v: _templateTyped.id)}
}
)
union(tables: [first, last])
|> pivot(rowKey: [“plan_id”], columnKey: [“context”], valueColumn: “oldTemplateId”)
|> map(fn: (r) => ({r with updateID_diff: r.oldTemplateId_first != r.updateID_last}))
|> map(fn: (r) => ({
measurementName: r._measurement,
planId: r[“plan_id”],
userID: r[“userId”],
procedureName: r[“procedure”],
modalityName: r[“modality”],
firstOldTemplateID: r[“oldTemplateId_first”],
lasttUpdateID: r[“updateID_last”],
changeOLD: r[“updateID_diff”]
}))
The issue is that it is fetching the first value from firstOldTemplateID, but in lasttUpdateID it is also returning the first instead of the last and I think it is because in the pivot it is putting valueColumn: “oldTemplateId”… Will it be that?
Right now it’s giving me:
Plan ID |
Old Template ID |
Update Template ID |
Change ID? |
123456 |
7654321 |
1e9u465 |
True |
But it should give false because it is true that the Update Template has already changed it to “1e9u465” but the last value is the same as the Old Template ID “7654321” .
Contextualizing the same plan ID can make changes over time to the updateID value but I want to know if the last plan_id returns to the initial value or is equal to the Old Template ID.
Could you help me @scott ? Thanks!!