Hi Team,
Would you agree that the below two scripts are expected to return the same results?
Script 1:
firstQuantity = from(bucket: “quantity/autogen”)
|> range(start: 2022-12-31T15:00:00Z, stop: 2023-05-31T16:00:00Z)
|> filter(fn: (r) => r._measurement == “quantity-items”)
|> filter(fn: (r) => r._field == “quantity”)
|> filter(fn: (r) => r.id == “A1”)
|> group(columns: [“id”, “_measurement”], mode:“by”)
|> first()
|> map(fn: (r) => ({ r with description: “first_quantity” }))
|> keep(columns: [“id”,“description”,“_value”])
|> yield(name: “firstQuantity”)
lastQuantity = from(bucket: “quantity/autogen”)
|> range(start: 2022-12-31T15:00:00Z, stop: 2023-05-31T16:00:00Z)
|> filter(fn: (r) => r._measurement == “quantity-items”)
|> filter(fn: (r) => r._field == “quantity”)
|> filter(fn: (r) => r.id == “A1”)
|> group(columns: [“id”, “_measurement”], mode:“by”)
|> last()
|> map(fn: (r) => ({ r with description: “last_quantity” }))
|> keep(columns: [“id”,“description”,“_value”])
|> yield(name: “last_quantity”)
Script 2:
data = from(bucket: “quantity/autogen”)
|> range(start: 2022-12-31T15:00:00Z, stop: 2023-05-31T16:00:00Z)
|> filter(fn: (r) => r._measurement == “quantity-items”)
|> filter(fn: (r) => r._field == “quantity”)
|> filter(fn: (r) => r.id == “A1”)
|> group(columns: [“id”, “_measurement”], mode:“by”)
firstQuantity = data
|> first()
|> map(fn: (r) => ({ r with description: “first_quantity” }))
|> keep(columns: [“id”,“description”,“_value”])
|> yield(name: “firstQuantity”)
lastQuantity = data
|> last()
|> map(fn: (r) => ({ r with description: “last_quantity” }))
|> keep(columns: [“id”,“description”,“_value”])
|> yield(name: “lastQuantity”)
I get different results for lastQuantity, which is I find super strange, my preference is to use Script 2 but that’s the one that’s giving unexpected results