# How to specify a Starlark output metric type

**URL:** <https://community.influxdata.com/t/how-to-specify-a-starlark-output-metric-type/31480>\
**Category:** Telegraf\
**Created:** [September 12, 2023, 8:53am UTC](https://community.influxdata.com/t/how-to-specify-a-starlark-output-metric-type/31480 "2023-09-12T08:53:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![simonsmart9](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/simonsmart9/32/13949_2.png) [@simonsmart9](https://community.influxdata.com/u/simonsmart9)\
**Post date:** [September 12, 2023, 8:53am UTC](https://community.influxdata.com/t/how-to-specify-a-starlark-output-metric-type/31480/1 "2023-09-12T08:53:30Z")

</div>

I have created the Starlark script below which functions as expected, however the two output metrics “higham\_spd” and “higham\_dir” inherit the same type (in this case string) as the input metric “higham\_message”.

I would like to change the type of the output metrics to int, however if I do so within the python script, the following error message is generated within telegraf:

> 2023-09-12T08:50:47Z E! [outputs.influxdb\_v2] Failed to write metric (will be dropped: 400 Bad Request): invalid: dml handler error: schema conflict: table higham\_anemometer, column higham\_spd is type string but write has type i64

I was hoping there is another way to change the output metric type.

```auto
[[processors.starlark]]
namepass = ['higham_anemometer']
source = '''
def apply(metric):
    higham_data = metric.fields['higham_message']
    metric.fields['higham_spd'] = higham_data.split(",")[0]
    metric.fields['higham_dir'] = higham_data.split(",")[1]
    return metric
'''

```

---

<div class="post-metadata">

**Author:** ![srebhan](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/srebhan/32/8572_2.png) [@srebhan](https://community.influxdata.com/u/srebhan)\
**Post date:** [September 12, 2023, 9:49am UTC](https://community.influxdata.com/t/how-to-specify-a-starlark-output-metric-type/31480/2 "2023-09-12T09:49:27Z")

</div>

@simonsmart9 not exactly sure, but I read the error message the opposite way, you are trying to write an int64 but the column in InfluxDB is of type string…

---

<div class="post-metadata">

**Author:** ![simonsmart9](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/simonsmart9/32/13949_2.png) [@simonsmart9](https://community.influxdata.com/u/simonsmart9)\
**Post date:** [September 12, 2023, 10:49am UTC](https://community.influxdata.com/t/how-to-specify-a-starlark-output-metric-type/31480/3 "2023-09-12T10:49:20Z")

</div>

Thank you @srebhan. I was looking at the split processor yesterday but couldn’t figure out how to use it to accomplish what I have done with Starlark. Any pointers would be much appreciated.

Regarding the int type, it was a school boy error. I forgot to change the measurement name, so influxdb was refusing an int in the field which had already been specified as a string. With the change it looks as follows:

```auto
[[processors.starlark]]
namepass = ['higham_turbine']
source = '''
def apply(metric):
    higham_data = metric.fields['higham_message']
    metric.fields['higham_windspd'] = int(higham_data.split(",")[0])
    metric.fields['higham_winddir'] = int(higham_data.split(",")[1])
    return metric
'''

```

---

<div class="post-metadata">

**Author:** ![srebhan](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/srebhan/32/8572_2.png) [@srebhan](https://community.influxdata.com/u/srebhan)\
**Post date:** [September 18, 2023, 1:16pm UTC](https://community.influxdata.com/t/how-to-specify-a-starlark-output-metric-type/31480/4 "2023-09-18T13:16:10Z")

</div>

Sorry, seems like you can’t do it with the split processor. I was misreading your message.  
You could use the `parser` processor with `CSV` but I’m not sure it’s worth it if you are fine with the performance of starlark…
