TICK script to move field to tag in different measurement

Hello,

I’ve spent the better part of the day trying to combine two timeseries into one with a TICK script in kapacitor.
I have these two series:
name: firmware_hourly
time ownerId participantId value_value
---- ------- ------------- -----------
1508742000000000000 0019a4eb-db34-42e7-9534-c590e565365e 27 2.0.5620
1508742000000000000 09fed99d-d3f2-4866-b8aa-20aa5ef4fd45 27 2.0.5620
1508742000000000000 26bf7c0e-af8a-4ff0-a044-b4a3228d5377 27 2.0.5620
1508742000000000000 269eeb3a-cf85-44c3-8c34-54416f3c8810 27 2.0.5620
1508742000000000000 4e67b40c-01bf-4943-bcd3-24d3974db67e 27 2.0.5620

and
name: electricalEnergyConsumption
time ownerId participantId value valueState valueType
---- ------- ------------- ----- ---------- ---------
1501545600000000000 3642f007-c5a5-418e-9b6c-a7ce4b250539 1 10.988 Measured
1501545600000000000 8e9aacec-bbce-4a24-8933-b284e4050787 1 10.72 Measured
1501632000000000000 3642f007-c5a5-418e-9b6c-a7ce4b250539 1 19.8940000305176 Measured
1501632000000000000 8e9aacec-bbce-4a24-8933-b284e4050787 1 24.11 Measured
1501718400000000000 3642f007-c5a5-418e-9b6c-a7ce4b250539 1 16.86 Measured
1501718400000000000 8e9aacec-bbce-4a24-8933-b284e4050787 1 8.69 Measured
1501804800000000000 3642f007-c5a5-418e-9b6c-a7ce4b250539 1 18.936 Measured
1501804800000000000 8e9aacec-bbce-4a24-8933-b284e4050787 1 10.76 Measured
1501891200000000000 3642f007-c5a5-418e-9b6c-a7ce4b250539 1 12.836 Measured
1501891200000000000 8e9aacec-bbce-4a24-8933-b284e4050787 1 9.22 Measured

I need to combine the firmware and the number of values per hour in the second series. I have come up with this tick script:
var collected = batch
|query(‘select count(*) from “timeseries”.“autogen”.electricalEnergyConsumption’)
.period(12h)
.every(1m)
.groupBy(time(1h), ‘participantId’, ‘ownerId’)
.fill(0)

var firmware = batch
|query(‘select last(*) from “timeseries”.“autogen”.firmware_hourly’)
.period(12h)
.every(1m)
.groupBy(time(1h), ‘participantId’, ‘ownerId’)
.fill(‘previous’)

firmware
|join(collected)
.as(‘firmware’, ‘collected’)
|log()
|eval(lambda: string(“firmware.last_value_value”))
.as(‘firmware’)
.tags(‘firmware’)
|influxDBOut()
.database(‘timeseries’)
.measurement(‘firmware_quality_by_hour’)

The idea is that is should write out a series with
time, participantId, ownerId, firmware as tags and a value.

However, when it is executed, this is printed to the log:
unable to parse ‘firmware_quality_by_hour,firmware=2.0.5628,ownerId=29e8ace1-a04c-49cd-a712-933c2bdf18fc,participantId=27 1509012000000000000’: invalid field format

Is there any way to get around this? Can I somehow use a field value in .measurement('new-measurement).tag(‘firmware’, “firmware_field-_here”)?

I see that there’s an open issue for this at Bug: Invalid field format when using tags() on eval() · Issue #1484 · influxdata/kapacitor · GitHub

Managed to get around this myself: I think the error might have been caused by no .keep() clause and hence no values being stored.

Changing the last part of the tick script to
firmware
|join(collected)
.as(‘firmware’, ‘collected’)
|eval(lambda: string(“firmware.last_value_value”), lambda: “collected.count_value”)
.as(‘firmware’, ‘value’)
.tags(‘firmware’)
.keep(‘value’)
|influxDBOut()
.database(‘timeseries’)
.measurement(‘firmware_quality_by_hour’)

did the trick.