Flux (原 IFQL) v0.0.4 版本发布
作者:Nathaniel Cook / 产品, 用例, 开发者
2018 年 1 月 22 日
导航至
我们最近发布了 IFQL - Influx 查询语言 [现已更名为 Flux] 的 v0.0.4 版本。由于年底的假期,我们的发布速度有点慢。展望未来,我们预计每两周发布一次。此版本包含一些令人兴奋的开发成果,几乎完全侧重于 Flux 语言本身的新功能。以下是重点功能的快速列表:
- 支持在 Flux 中定义/调用函数
- 多个新的内置函数:map、shift、integral、derivative 和 difference
- 支持多个值,其中协方差函数是第一个使用多个值的函数
在语言中添加对函数的支持,使用户可以在其查询中创建小的可重用组件,随着时间的推移构建有用的代码片段库。当逻辑需要应用于数据记录时,也会使用函数。函数使用明确且范围明确的函数来评估,取代了以前的表达式。我们希望您发现它们是清晰而强大的工具。Flux 函数遵循以下语法:
(parameter list) => <function body>
添加两个值的示例函数
// define the function add add = (a,b) => a + b // call the add function add(a:1, b:5) // 6
以下是函数实际应用的一个示例:
// serviceData gets the field from the requests measurement for a given service. serviceData = (service,field) => from(db:"myapp") // Use an anonymous function as the filter predicate, where "r" is the record. .filter(fn: (r) => r._measurement == "requests" and r._service == service and r._field == field) // We want the last hour of data start = -1h // Get the requests for the "cart" service reqs = serviceData(service:"cart", field:"requests").range(start:start) // Get the errors for the "cart" service errs = serviceData(service:"cart", field:"errors").range(start:start) // Compute the correlation between the reqs and errs for the "cart" service pearsonr(x:reqs, y:errs, on:["region"])
上面的脚本将计算过去一小时内购物车服务的错误和请求之间的皮尔逊相关系数。有趣的是,pearsonr
函数是使用原生 Flux 函数定义的,并且内置于语言中。以下是 pearsonr
在源代码中显示的定义。
// Covariance computes the covariance between x and y. covariance = (x,y,on,pearsonr=false) => join( tables:{x:x, y:y}, on:on, fn: (t) => ({x:t.x._value, y:t.y._value}), ) .covariance(pearsonr:pearsonr) // Pearsonr computes the Pearson R correlation coefficient of x and y. pearsonr = (x,y,on) => covariance(x:x, y:y, on:on, pearsonr:true)
pearsonr
函数实际上只是将 pearsonr
参数设置为 true
的 covariance
函数。反过来,covariance
函数是一个 join
操作,它在将数据传递到 covariance
方法之前连接 x 和 y 表,该方法计算连接表上多个值之间的实际协方差。随着时间的推移,将在语言中添加更多函数,我们希望这些内置函数可以成为新用户的良好示例来源。
我们对函数和多值支持将为 Flux 带来的强大功能感到兴奋。有任何反馈或希望看到对特定函数的支持吗?在 Flux repo 上打开 issue 或 pull request。有关 v0.0.4 中更改的完整列表,请参阅 CHANGELOG。