Publicidad
Publicidad

Más contenido relacionado

Más de InfluxData(20)

Publicidad

Scott Anderson [InfluxData] | New & Upcoming Flux Features | InfluxDays 2022

  1. New & Upcoming Flux Features Scott Anderson
  2. Two new features are coming to Flux that add flexibility and functionality to your data workflow—polymorphic labels and dynamic types. This session walks through these new features and shows how they work. Scott Anderson Staff Technical Writer, InfluxData Scott Anderson is a Technical Writer for InfluxData who thrives on distilling complex information into simple, easy-to-understand concepts. He oversees the documentation of the Flux language and loves the challenge of showing how Flux can work for your use case. Scott’s formal education is in graphic design, but he is a self-taught writer and coder and applies skills and principles learned in both worlds to many different disciplines including programming and software development. New & Upcoming Flux Features
  3. Agenda ● Polymorphic Labels ● Dynamic Type
  4. These features are in development and are subject to change. Disclaimer
  5. Polymorphic Labels polymorphic adjective: occurring in several different forms label noun: Flux column name
  6. toInt()
  7. toInt = (tables=<-) => tables |> map( fn: (r) => ({r with _value: int(v: r._value)}) )
  8. Label Syntax .mylabel ._value ."with spaces"
  9. Label Syntax customCol = ."myColumn"
  10. Label Syntax customCol = .myColumn data |> map(fn: (r) => ({r with [customCol]: r[customCol] + 2})) // Executed as: |> map(fn: (r) => ({r with myColumn: r.myColumn + 2}))
  11. toInt()
  12. toInt = (tables=<-, column=._value) => tables |> map( fn: (r) => ({r with [column]: int(v: r[column])}) )
  13. toInt(column: ."myColumn")
  14. Polymorphic Labels Create flexible functions & transformations with customizable column parameters using native Flux.
  15. Dynamic type A wrapper for external data whose type is not known until runtime
  16. JSON Flux
  17. import "experimental/json" json.parse(data: ...)
  18. [1, null, false, 2.0, "foo"] Type Conflict
  19. { "items": [ {"name": "a", "pos": {"x": 10, "y": 10}}, {"name": "b", "pos": {"x": 30}}, {"name": "c", "pos": {}}, {"name": "d"} ] } Type Conflict
  20. parsed = dynamic.parseJSON( data: jsonDataAsBytes ) import "experimental/dynamic" { "items": [ {"name": "a", "pos": {"x": 10, "y": 10}}, {"name": "b", "pos": {"x": 30}}, {"name": "c", "pos": {}}, {"name": "d"} ] } JSON Data // parsed = <dynamic>
  21. parsed = dynamic.parseJSON( data: jsonDataAsBytes ) import "experimental/dynamic" { "items": [ {"name": "a", "pos": {"x": 10, "y": 10}}, {"name": "b", "pos": {"x": 30}}, {"name": "c", "pos": {}}, {"name": "d"} ] } JSON Data parsed.items |> dynamic.asArray() // [<dynamic>]
  22. parsed = dynamic.parseJSON( data: jsonDataAsBytes ) import "experimental/dynamic" { "items": [ {"name": "a", "pos": {"x": 10, "y": 10}}, {"name": "b", "pos": {"x": 30}}, {"name": "c", "pos": {}}, {"name": "d"} ] } JSON Data parsed.items |> dynamic.asArray() import "array" |> array.map( fn: (x) => ( { name: string(v: x.name), posX: int(v: x.pos.x), posY: int(v: x.pos.y) } ) )
  23. [ {name: "a", posX: 10, posY: 10}, {name: "b", posX: 30, posY: <null>}, {name: "c", posX: <null>, posY: <null>}, {name: "d", posX: <null>, posY: <null>}, ] { "items": [ {"name": "a", "pos": {"x": 10, "y": 10}}, {"name": "b", "pos": {"x": 30}}, {"name": "c", "pos": {}}, {"name": "d"} ] } JSON Data
  24. parsed = dynamic.parseJSON( data: jsonDataAsBytes ) import "experimental/dynamic" { "items": [ {"name": "a", "pos": {"x": 10, "y": 10}}, {"name": "b", "pos": {"x": 30}}, {"name": "c", "pos": {}}, {"name": "d"} ] } JSON Data parsed.items |> dynamic.asArray() import "array" import "experimental/dynamic" parsed = dynamic.parseJSON( data: jsonDataAsBytes ) parsed.items |> dynamic.asArray() |> array.map( fn: (x) => ( { name: string(v: x.name), posX: int(v: x.pos.x), posY: int(v: x.pos.y) } ) ) import "array" |> array.map( fn: (x) => ( { name: string(v: x.name), posX: int(v: x.pos.x), posY: int(v: x.pos.y) } ) ) |> array.from()
  25. { "items": [ {"name": "a", "pos": {"x": 10, "y": 10}}, {"name": "b", "pos": {"x": 30}}, {"name": "c", "pos": {}}, {"name": "d"} ] } JSON Data name posX posY a 10 10 b 30 c d
  26. JSON Flux
  27. val0 = 1 val1 = 1.0 val2 = "one" import "json" jsonData = json.encode(v: ...)
  28. val0 = 1 val1 = 1.0 val2 = "one" import "json" jsonData = json.encode(v: [val0, val1, val2]) Type Conflict
  29. import "json" import "experimental/dynamic" val0 = 1 val1 = 1.0 val2 = "one" jsonData = json.encode(v: ...)
  30. import "json" import "experimental/dynamic" val0 = 1 val1 = 1.0 val2 = "one" jsonData = json.encode(v: [ dynamic.dynamic(v: val0), dynamic.dynamic(v: val1), dynamic.dynamic(v: val2), ]) Good to go
  31. import "json" import "experimental/dynamic" import "http/requests" val0 = 1 val1 = 1.0 val2 = "one" jsonData = json.encode(v: [ dynamic.dynamic(v: val0), dynamic.dynamic(v: val1), dynamic.dynamic(v: val2), ]) requests.post( url: "http://example.com", body: jsonData, )
  32. Dynamic Type Work with external data sources and targets with data types that don’t have exact corollaries in native Flux types.
  33. Dynamic Type Rollout ● Introduced as experimental ● Will be available as part of a future Flux edition
  34. Recap ● Polymorphic Labels ● Dynamic type
  35. Additional Resources Free InfluxDB: OSS or Cloud - influxdata.com/cloud Forums: community.influxdata.com Slack: influxcommunity.slack.com Reddit: r/InfluxDB Influx Community (GH): github.com/InfluxCommunity Book: awesome.influxdata.com Docs: docs.influxdata.com Blogs: influxdata.com/blog InfluxDB University: influxdata.com/university How to guides: docs.influxdata.com/resources/how-to-guides/
  36. T H A N K Y O U
Publicidad