www.influxdata.com Open in urlscan Pro
2606:4700:10::ac43:29d9  Public Scan

Submitted URL: https://em.influxdata.com/OTcyLUdEVS01MzMAAAGDMqeSSnIg07V1ZFsxHa6LyyYOSXCp3t-EQyZHHfyAtPAjGuvM81P68DAltIJuogxjUWRC3Sk=
Effective URL: https://www.influxdata.com/blog/using-new-flux-types-package/?utm_source=newsletter&utm_medium=email&utm_campaign=2022-03-0...
Submission: On March 16 via api from SE — Scanned from DE

Form analysis 5 forms found in the DOM

GET https://www.influxdata.com/search/r/

<form class="search-form" action="https://www.influxdata.com/search/r/" method="get">
  <span class="search-text-wrap">
    <label for="s" class="screen-reader-text">Search …</label>
    <input name="s" class="search-field" type="text" autocomplete="off" value="" placeholder="Search …">
  </span>
  <span id="close" class="close"><span class="ast-icon icon-close"></span></span>
</form>

GET https://www.influxdata.com/search/r/

<form class="search-form" action="https://www.influxdata.com/search/r/" method="get">
  <span class="search-text-wrap">
    <label for="s" class="screen-reader-text">Search …</label>
    <input name="s" class="search-field" type="text" autocomplete="off" value="" placeholder="Search …">
  </span>
  <span id="close" class="close"><span class="ast-icon icon-close"></span></span>
</form>

POST https://www.influxdata.com/wp-comments-post.php

<form action="https://www.influxdata.com/wp-comments-post.php" method="post" id="ast-commentform" class="comment-form">
  <p class="comment-notes"><span id="email-notes">Your email address will not be published.</span> Required fields are marked <span class="required">*</span></p>
  <div class="ast-row comment-textarea">
    <fieldset class="comment-form-comment">
      <div class="comment-form-textarea ast-col-lg-12"><label for="comment" class="screen-reader-text">Type here..</label><textarea id="comment" name="comment" placeholder="Type here.." cols="45" rows="8" aria-required="true"></textarea></div>
    </fieldset>
  </div>
  <div class="ast-comment-formwrap ast-row">
    <p class="comment-form-author ast-col-xs-12 ast-col-sm-12 ast-col-md-4 ast-col-lg-4"><label for="author" class="screen-reader-text">Name*</label><input id="author" name="author" type="text" value="" placeholder="Name*" size="30"
        aria-required="true"></p>
    <p class="comment-form-email ast-col-xs-12 ast-col-sm-12 ast-col-md-4 ast-col-lg-4"><label for="email" class="screen-reader-text">Email*</label><input id="email" name="email" type="text" value="" placeholder="Email*" size="30"
        aria-required="true"></p>
    <p class="comment-form-url ast-col-xs-12 ast-col-sm-12 ast-col-md-4 ast-col-lg-4"><label for="url"><label for="url" class="screen-reader-text">Website</label><input id="url" name="url" type="text" value="" placeholder="Website" size="30"></label>
    </p>
  </div>
  <p class="form-submit"><input name="submit" type="submit" id="submit" class="submit" value="Post Comment »"> <input type="hidden" name="comment_post_ID" value="265744" id="comment_post_ID">
    <input type="hidden" name="comment_parent" id="comment_parent" value="0">
  </p>
  <p style="display: none;"><input type="hidden" id="akismet_comment_nonce" name="akismet_comment_nonce" value="763a9dd8a6"></p>
  <p style="display: none !important;"><label>Δ<textarea name="ak_hp_textarea" cols="45" rows="8" maxlength="100"></textarea></label><input type="hidden" id="ak_js" name="ak_js" value="1647464035681">
    <script>
      document.getElementById("ak_js").setAttribute("value", (new Date()).getTime());
    </script>
  </p>
</form>

<form id="mktoForm_1212" novalidate="novalidate" class="mktoForm mktoHasWidth mktoLayoutAbove">
  <style type="text/css"></style>
  <div class="mktoTemplateBox">Welcome back, Ashok Ramasamy<br><br><span class="mktoButtonWrap mktoNative"><button type="submit" class="mktoButton">Subscribe</button></span><br><br><a class="mktoNotYou">Not you?</a></div><input type="hidden"
    name="formid" class="mktoField mktoFieldDescriptor" value="1212"><input type="hidden" name="munchkinId" class="mktoField mktoFieldDescriptor" value="972-GDU-533"><input type="hidden" name="mkto_content_name" class="mktoField mktoFieldDescriptor"
    value="Newsletter Signup">
</form>

<form novalidate="novalidate" class="mktoForm mktoHasWidth mktoLayoutAbove" style="font-family: inherit; font-size: 12px; color: rgb(51, 51, 51); visibility: hidden; position: absolute; top: -500px; left: -1000px; width: 1600px;"></form>

Text Content

Skip to content
Search …
 * ProductsMenu Toggle
    * Products-mega
      
      InfluxDB
      
      Build real-time applications for analytics, IoT and cloud-native services
      in less time with less code using InfluxDB.
      
      Learn more
      
      Running in the cloud
      
      Fast, elastic, serverless real-time monitoring platform, dashboarding
      engine, analytics service and event and metrics processor.
      
      Running in my own environment
      
      InfluxDB Enterprise is the solution for running the InfluxDB platform on
      your own infrastructure.
      
      Running on my laptop
      
      InfluxDB is the essential time series toolkit — dashboards, queries, tasks
      and agents all in one place.
      
      Collecting data
      
      Telegraf is a plugin-driven server agent for collecting and sending
      metrics and events from databases, systems, and IoT sensors.
      
      

 * Developers
 * Customers
 * CompanyMenu Toggle
    * Company-mega
      
      The Platform for Real-Time Apps
      
      Innovators are building the future of data with our leading time series
      platform, InfluxDB.
      
      About Us
      
      At InfluxData, we empower developers and organizations to build real-time
      IoT, analytics and cloud applications with time-stamped data.
      
      Careers
      
      InfluxData is a remote-first company that’s growing rapidly worldwide.
      Join us!
      
      

 * Pricing
 * Contact Us
 * LoginMenu Toggle
   * Login to InfluxDB Cloud 2.0
   * Login to InfluxDB Enterprise
   * Login to InfluxDB Cloud 1.x
 * Get InfluxDB



Search …
Main Menu



Get InfluxDB
Get InfluxDB
 * ProductsMenu Toggle
    * Products-mega
      
      InfluxDB
      
      Build real-time applications for analytics, IoT and cloud-native services
      in less time with less code using InfluxDB.
      
      Learn more
      
      Running in the cloud
      
      Fast, elastic, serverless real-time monitoring platform, dashboarding
      engine, analytics service and event and metrics processor.
      
      Running in my own environment
      
      InfluxDB Enterprise is the solution for running the InfluxDB platform on
      your own infrastructure.
      
      Running on my laptop
      
      InfluxDB is the essential time series toolkit — dashboards, queries, tasks
      and agents all in one place.
      
      Collecting data
      
      Telegraf is a plugin-driven server agent for collecting and sending
      metrics and events from databases, systems, and IoT sensors.
      
      

 * Developers
 * Customers
 * CompanyMenu Toggle
    * Company-mega
      
      The Platform for Real-Time Apps
      
      Innovators are building the future of data with our leading time series
      platform, InfluxDB.
      
      About Us
      
      At InfluxData, we empower developers and organizations to build real-time
      IoT, analytics and cloud applications with time-stamped data.
      
      Careers
      
      InfluxData is a remote-first company that’s growing rapidly worldwide.
      Join us!
      
      


USING THE NEW FLUX “TYPES” PACKAGE

By Sean Brickley / March 7, 2022 March 6, 2022 / Community, Developer, Flux,
Tutorial / Leave a Comment
3 minutes

As a strictly typed language, Flux protects you from a lot of potential runtime
failures. However, if you don’t know the column types on the data you’re
querying, you might encounter some annoying errors.

Suppose you have a bucket that receives regular writes from multiple different
streams, and you want to write a task to downsample a measurement from that
bucket into another bucket. If you know ahead of time that, for example, the
_value column will always be a numeric type, you could run the following task
without any problems:

option task = {name: "write-agg", every: 30m, offset: 1s}

from(bucket: "test-bucket")
       |> range(start: -30m)
       |> filter(fn: (r) => r._measurement == "logs")
       |> aggregateWindow(fn: mean, every: 5m)
       |> to(bucket: "test-downsample")
Copy

But if you don’t know the schema of the data before you query it, you could run
into trouble. It’s possible for this query to fail if, for instance,
_value turns out to be a string instead of a number.



Until now, there has not been a one-size-fits-all solution to this problem. A
filter on _field could do the trick if you know the labels you’re looking for,
but maybe you don’t know those details, or maybe the list of labels you need to
include or exclude is too long to comfortably fit in a filter predicate.

Enter the types package. This package introduces the isType function, which
makes filtering on column types much easier. We can use it to fix our original
query by importing the types package and adding a new filter that checks the
type of r._value.

import "types"

option task = {name: "write-agg", every: 30m, offset: 1s}

from(bucket: "test-bucket")
       |> range(start: -30m)
       |> filter(fn: (r) => r._measurement == "logs")
       |> filter(fn: (r) => types.isType(v: r._value, type: "float"))
       |> aggregateWindow(fn: mean, every: 5m)
       |> to(bucket: "test-downsample")
Copy

Now we can be sure that any data piped into aggregateWindow has a _value column
of type float, and thus avoid any potential type errors. Sure enough, our task
succeeds and successfully writes the downsampled data to our new bucket:



We can also do more complex filtering using isType. Let’s imagine that the logs
measurement we’re reading from the task above has fields with many different
types. We want to aggregate all of them, but we know that some aggregates won’t
work for every type. We can use isType to decide which aggregate function to use
based on the type of data we find.

import "types"

option task = {name: "write-agg", every: 30m, offset: 1s}

from(bucket: "test-bucket")
       |> range(start: -30m)
       |> filter(fn: (r) => r._measurement == "logs")
       |> filter(fn: (r) => {
                 return types.isType(v: r._value, type: "float")
                         or types.isType(v: r._value, type: "int")
                         or types.isType(v: r._value, type: "uint")
       })	
       |> aggregateWindow(fn: mean, every: 5m)
       |> to(bucket: "test-downsample")

from(bucket: "test-bucket")
       |> range(start: -30m)
       |> filter(fn: (r) => r._measurement == "logs")
       |> filter(fn: (r) => {
                return types.isType(v: r._value, type: "string")
                        or types.isType(v: r._value, type: "bool")
       })
      |> aggregateWindow(fn: last, every: 5m)
      |> to(bucket: "test-downsample")
Copy

This new package is included in the latest version of Flux, and is available to
all cloud users. We encourage you to test it out and let us know what you think!

RELATED BLOG POSTS

 * Getting Started with C++ and InfluxDB
   This article was written by Pravin Kumar Sinha and was originally published
   by The …
   
   Getting Started with C++ and InfluxDB Read More »
   
   Community
 * Telegraf Release Candidates, Nightlies, & Test Artifacts
   Since 2016, the Telegraf project has released 22 minor releases, 48 release
   candidates, and …
   
   Telegraf Release Candidates, Nightlies, & Test Artifacts Read More »
   
   Josh Powers
 * Class is in Session – Announcing InfluxDB University
   At InfluxData, it’s no surprise that we are passionate about time series
   data. Our …
   
   Class is in Session – Announcing InfluxDB University Read More »
   
   Emily Kurze

Twitter
Facebook
Linkedin

Post navigation
← Previous Post
Next Post →


LEAVE A COMMENT CANCEL REPLY

Your email address will not be published. Required fields are marked *

Type here..

Name*

Email*

Website





Δ

Twitter
Facebook
Linkedin



CATEGORIES

 * About Company
 * Community
 * Developer►
   * Chronograf
   * Flux
   * InfluxData
   * InfluxDB
   * InfluxDB Templates
   * Kapacitor
   * Partners►
     * AWS
     * Azure
     * Google Cloud
   * Release Notes
   * Tech Tips
   * Telegraf
 * General
 * InfluxDB Cloud
 * InfluxDB Enterprise
 * Press Room►
   * In The News
   * Press Releases
 * Trust
 * Tutorial
 * Use Case►
   * Analytics
   * DevOps
   * IIoT
   * IoT
   * Security

TRY INFLUXDB CLOUD

The most powerful time series database as a service is a click away.

Try It Free



548 Market St, PMB 77953
San Francisco, California 94104

Contact Us



PRODUCTS

InfluxDB
Telegraf
Pricing
Support
Use Cases

RESOURCES

InfluxDB U
Blog
Community
Customers
Swag
Events

INFLUXDATA

About
Careers
Partners
Legal
Newsroom
Contact Sales

SIGN UP FOR THE INFLUXDATA NEWSLETTER

Welcome back, Ashok Ramasamy

Subscribe

Not you?

© 2022  InfluxData Inc. All Rights Reserved. Sitemap


Scroll to Top
X


INFLUXDATA CONSENT MANAGER

Like many companies, InfluxData uses cookies and other technologies, some of
which are essential to make our website work. Others help us improve services
and the user experience. In using our site, you agree to the Privacy Policy and
Cookie Policy.