Kapacitor: Retain tags when transforming data

I have setup Kapacitor to read a measurement and convert field of type string to lower case and output the transformed data to another measurement. The tag in the original measurement is getting stored as a field in the new measurement. How to retain tags when transforming data?

This is the .tick file that I am using:

dbrp "test"."autogen"

batch
    |query('SELECT * FROM "test"."autogen"."store"')

      .period(1d)

      .every(30s)

    |eval(lambda: strToLower("timezone"))

      .as('timezone_lower_case')

      .keep()

    |InfluxDBOut()

      .database('test')

      .measurement('currentTime')

The original measurement “store” has a field “timezone” and a tag “storeId”. The new measurement has fields of “timezone”, “timezone_lower_case”, “storeId”.

The “storeId” tag got converted to a field

I want to retain “storeId” as tag in the new measurement

Use groupBy and set the tags you want to retain.

batch
    |query('SELECT * FROM "test"."autogen"."store"')

      .period(1d)

      .every(30s)
      .groupBy(*)

That should retain all tags in the original data. you can change it and specify specific tags you want to retain.

Thanks! This solved the issue.

No worries, glad it solved your issue.