作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
更新:这是 here 的回答。
我正在组合一个有点复杂的查询,以在 Snowflake 中对大型时间序列数据集进行事件检测、连接和基于时间的装箱。我最近注意到 match_recognize
让我可以 Eloquent 地检测时间序列事件,但每当我尝试在公用表表达式中使用 match_recognize
表达式时(with .. as ..
),我收到以下错误:
SQL compilation error: MATCH_RECOGNIZE not supported in this context.
我进行了大量搜索/阅读,但没有发现 CTE 中关于 match_recognize
的任何记录限制。这是我的查询:
with clean_data as (
-- Remove duplicate entries
select distinct id, timestamp, measurement
from dataset
),
label_events as (
select *
from clean_data
match_recognize (
partition by id
order by timestamp
measures
match_number() as event_number
all rows per match
after match skip past last row
pattern(any_row row_between_gaps+)
define
-- Classify contiguous sections of datapoints with < 20min between adjacent points.
row_between_gaps as datediff(minute, lag(timestamp), timestamp) < 20
)
)
-- Do binning with width_bucket/etc. here
select id, timestamp, measurement, event_number
from label_events;
我得到了与上面相同的错误。
这是我没有看到的限制,还是我做错了什么?
最佳答案
非递归 cte 总是可以重写为内联 View :
--select ...
--from (
select id, timestamp, measurement, event_number
from (select distinct id, timestamp, measurement
from dataset) clean_data
match_recognize (
partition by id
order by timestamp
measures
match_number() as event_number
all rows per match
after match skip past last row
pattern(any_row row_between_gaps+)
define
-- Classify contiguous sections of datapoints with < 20min between adjacent points.
row_between_gaps as datediff(minute, lag(timestamp), timestamp) < 20
)mr
-- ) -- if other transformations are required
这并不理想,但至少它允许查询运行。
关于sql - 在 Snowflake 的公用表表达式中使用 "match_recognize",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68183062/
我是一名优秀的程序员,十分优秀!