【问题标题】:Extracting data from piped string KDB从管道字符串 KDB 中提取数据
【发布时间】:2021-02-23 19:28:05
【问题描述】:

我有下表

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


【解决方案1】:

这是一种使用"|" 分离的方法,类似于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

【讨论】:

    【解决方案2】:

    这将通过"|" 分隔每个组合,然后嵌套函数将根据列表中每个字符串的最后一个字符进行过滤。如果始终为 1 或 0,您可以直接转换为布尔值 "B"$

    select {x where "B"$-1#/: x} each "|" vs/: comps from t
    

    或在where 中使用= 转换为int

    select {x where 1 = "I"$-1#/: x} each "|" vs/: comps from t
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-21
      • 1970-01-01
      • 1970-01-01
      • 2021-08-07
      相关资源
      最近更新 更多