Create a new column to store data of a new query

I have two queries that I combine using the union() function in InfluxDB.

core_data = from(bucket: "tel-cats")
  |> range(start: v.timeRangeStart, stop:v.timeRangeStop)
  |> filter(fn: (r) => r._measurement == "core")
  |> keep(columns: ["_time", "_value", "cats_id"])
  |> group()

kdump_data = from(bucket: "tel-cats")
  |> range(start: v.timeRangeStart, stop:v.timeRangeStop)
  |> filter(fn: (r) => r._measurement == "kdump")
  |> keep(columns: ["_time", "_value", "cats_id"])
  |> group()

union(tables: [core_data, kdump_data])

The union output looks like this:

The resulting table has a cats_id column. For each cats_id value, I want to perform an additional query to retrieve a single value (let’s call it “X”) from another bucket and add it as a new column in the existing table.

So eventually, I would have a new column with a value for each cats_id.
I do not want the new column to be written into the DB.

@Mani_Amoozadeh,
Welcome! First off please tell me this isn’t dummy data and you are in fact monitoring cats. <33333 Would you be willing to tell me more about your project? This is so exciting.

Hmmm unfortunately you can easily pull in one value but value matching from another bucket isn’t really possible.

like you could do:

data1 = your query from the orignial bucket 

data2 = from(bucket: "bucket2") |> range() |> filter() |> findRecord(
        fn: (key) => true,
        idx: 0,
    )._value

data1 
    |> map(fn: (r) => ({ r with newColumn: data2 }))

but that’s just for one value.

If you have cat_ids in the other bucket than you can perform a join.
But there isn’t a way to dynamically extract multiple single values and pair them with your cat id.

Can you share more about what your data in the other bucket looks like please?