首页 > 解决方案 > 从管道字符串 KDB 中提取数据

问题描述

我有下表

t:flip (`comps`uid)!(("ub01,140,16600,1|msil,140,31,0|gsc,140,40,0|csf,140,9,1|ci,140,18,1|in,140,10,1|j106,100,100,1";"ub01,140,16600,1|msil,140,31,0|gsc,140,40,0|csf,140,9,1|ci,140,18,1|in,140,10,1|j106,100,100,1");`user1`user2)

我正在尝试填充下表中的valueWhere1valueWhere0

tRes:flip (`comps`uid`valueWhere1`valueWhere0)!(("ub01,140,16600,1|msil,140,31,0|gsc,140,40,0|csf,140,9,1|ci,140,18,1|in,140,10,1|j106,100,100,1";"ub01,140,16600,1|msil,140,31,0|gsc,140,40,0|csf,140,9,1|ci,140,18,1|in,140,10,1|j106,100,100,1");`user1`user2;(`ub01`csf`ci`in`j106;`ub01`csf`ci`in`j106);(`msil`gsc;`msil`gsc))

我得到了每个字符串的计数,其中每个管道之前的值为 1,0

t:update countWhere1:sum each {"1"=last x}''["|"vs'comps],countWhere0:sum each {"0"=last x}''["|"vs'comps] from t

尝试拉入每个字符串的第一部分并根据 1;0 标志进行过滤。我有以下但不太工作

`$first each raze {"," vs x} each '{"|"vs x} each ("ub01,140,16600,1|msil,140,31,0|gsc,140,40,0|csf,140,9,1|ci,140,18,1|in,140,10,1|j106,100,100,1";"ub01,140,16600,1|msil,140,31,0|gsc,140,40,0|csf,140,9,1|ci,140,18,1|in,140,10,1|j106,100,100,1")

感谢您的关注

标签: kdb

解决方案


这是一种使用"|"类似于 Matt 的分离的方法,然后0:基于管道之间的位是可预测且规则的假设进行解析:

t,'exec{group`$"valueWhere",/:string(!).("S  B";csv)0:"|"vs x}each comps from t

请注意,这可能需要进行一些调整才能概括...在组之后创建的字典可能并不总是符合要求,在这种情况下,您可能需要

t,'exec{`valueWhere1`valueWhere0#group`$"valueWhere",/:string(!).("S  B";csv)0:"|"vs x}each comps from t

推荐阅读