Skip to content

sql input does not handle bool values correctly #9517

@milgner

Description

@milgner

Relevant telegraf.conf:

    [[inputs.sql.query]]
      field_columns_float = ["NumValue"]
      field_columns_bool = ["LogValue"]
      field_columns_include = []
      field_columns_string = ["StringValue"]
      measurement = "DataSeries"
      # shortened query for better readability
      query = "SELECT TagName, DataSeriesId, ValueTime, LogValue, NumValue, StringValue FROM ... WHERE ValueTime > (SELECT DATEADD(second, -10, GETDATE()))"
      tag_columns_include = ["DataSeriesId", "TagName"]
      time_column = "ValueTime"

System info:

  • Telegraf 1.19.0 (git: tag-1.19.0 tag-1.19.0)
  • MS SQL Server

Docker

Don't have a full environment with a database at hand. The SQL server docker image is mcr.microsoft.com/mssql/server:2019-latest@sha256:51965e4e4c17e6fef087550190c2920c7ef91bd449d0eec06a5484b92c437767.

Steps to reproduce:

  1. Use a sql input with float_columns_bool filled in - I used MS SQL Server
  2. Start telegraf

Expected behavior:

The boolean column is inserted as a boolean field into InfluxDB.

Actual behavior:

2021-07-19T11:31:00+02:00 E! [inputs.sql] Error in plugin: converting field column "LogValue" to bool failed: type "bool" unsupported

Additional info:

The query is correct: adding a typecast to integer (CAST(LogValue AS INT) as LogValue) and moving it to field_columns_float makes the system work.

I have a general idea where the bug is located but will need to take a closer look at the code - currently working on a deadline, will try to find some time next week to prepare a patch. Any pointers & support welcome!

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/sqlbugunexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions