kdb - 如何使用 wj 在表中存储时间戳列表
问题描述
我有一个按日期、符号和 client_type 聚合的表。其余的列不是聚合的,而是列表。
例如:
table2: select requestId, initialTimestamp by date, sym, client_type, from table
requestId 和 initialTimestamp 因此是列表。
我想基本上在 5 分钟内找到重复数据并将它们标记为如此。
如果我的 5 分钟是固定的,那么我可以执行以下操作:
table3: update bucket: (5 xbar\:`minute$initialTimestamp) from table2;
然后取消分组并与存储桶一起工作以识别骗子......例如
table4: select requestId by bucket, sym, client_type ungroup table3;
update duplicateId: ` from (ungroup update duplicateId: ?[(count each requestId)>1; requestId@'1; `] from table4) where requestId=duplicateId
这很好用,但是如果我想要一个 5 分钟的滚动窗口而不是固定窗口怎么办?
它似乎指向 wj - 但我不确定如何使其与分组列一起使用。
解决方案
如果您只想查找重复项,您可以使用fby
而不是时间桶/窗口?
select from table where 1 < (count;initialTimestamp) fby ([]date;sym;client_type;requestId)
编辑:我仍然认为 wj 是不必要的,也不会那么有效。您可以像这样按组进行更新:
// given the following dummy table
t:update time:"P"$"D" sv/: flip(string[date];string[time]) from ([]date:raze 20#'.z.d+til 5;sym:100?`symA`symB`symC;time:10:00+til 100;clientType:100?`clientA`clientB;requestId:100?3);
update dup:00:05>=deltas time by date,sym,clientType,requestId from t
编辑:既然你想要第一个副本,那么我认为这wj
可能是你最初想要的唯一方法。您想使用wj1
aswj
将在进入时间窗口之前考虑当前行。
// sort by grouping then time
t2:`date`sym`clientType`time xasc t;
times:-00:05 -00:00:00.000000001 +\:t2`time;
// params
// pair of time lists
// common columns/grouping with time last
// tableToJoinTo
// (windowJoinTable;(function;col))
wj1[times;`date`sym`clientType`time;t2;(update dupId:requestId from t2;(first;`dupId))]
推荐阅读
- python - 如何在线程内使用 QWebEngineView 而不会崩溃?
- node.js - 让 gulp-imagemin 工作的问题
- sql - 具有全局用户定义类型的 Oracle SQL TABLE 运算符显示“表达式类型错误”
- java - JAXB 自定义绑定 - 前缀必须解析为命名空间
- python - 如何从字符串中提取90%以上的字母和数字?
- objective-c - Apple PTP - withCompleteContentCatalog not firing (Rust + Obj-C)
- encryption - Filecoin Lotus PrivateKey 转换为长度为 32 的常规私钥
- kubernetes - Airflow - KubernetesPodOperator - 绑定服务帐户的角色
- visual-studio-code - 如何向 VSCode 添加自定义参数提示?
- r - 如果字符向量中的任何字符串值在数据框的列中,则在新列中返回匹配的字符串