Influx Continuous Query - Is there any way to transform a filed data type from base table to the corresponding filed in down sampled table?

Viewed 17

Below is a continuous query -

CREATE CONTINUOUS QUERY cq1 ON mydb 
BEGIN SELECT filed1 AS name
INTO cum_cq1 base_stats GROUP BY controller, time(1m) END

filed1 is a floating value.

I want name to be an integer or long.

Is there any way for this transformation.

1 Answers

First, InfluxDB supports following types of data: string, integer, float, boolean. No long type. There are two options in my opinion to achieve integer type in your case.

  1. Use ceil() function:

    CREATE CONTINUOUS QUERY cq1 ON mydb  
    BEGIN SELECT ceil(filed1) AS name  
    INTO cum_cq1 base_stats GROUP BY controller, time(1m) END  
    

This will round your float value to nearest integer.
Ceil function docs for InfluxQL

  1. Use "::integer" operator to cast value to integer:

    CREATE CONTINUOUS QUERY cq1 ON mydb  
    BEGIN SELECT filed1::integer AS name  
    INTO cum_cq1 base_stats GROUP BY controller, time(1m) END  
    

This will round down your integer.

Cast operation docs for InfluxQL

Related