【问题标题】:How to manually construct the following functional statement如何手动构造以下函数语句
【发布时间】:2019-11-13 18:37:20
【问题描述】:

我需要为下面的表达式创建一个函数式语句

select from table where not any venue like/:("tst1";tst2)

这就是我现在拥有的:

(enlist(~:;(any;((/:;like);`venue;(enlist;a)))))

其中 a 可以是 "tst1"("tst1";tst2)

这就是问题所在。我想将a 作为参数传递,但它不起作用。 该行应如下所示:

(enlist(~:;(any;((/:;like);`venue;(enlist;"tst1";"tst2")))))

任何人都有任何建议。我有点卡住了。

【问题讨论】:

    标签: kdb


    【解决方案1】:

    首先让我们使用parse 来查看树:

    q)parse "select from table where not any venue like/:(\"tst1\";\"tst2\")"
    ?
    `table
    ,,(~:;(max$["b"];((/:;like);`venue;(enlist;"tst1";"tst2"))))
    0b
    ()
    

    接下来,让我们使用enlist, 技巧在您的like 语句中构建元素列表

    q)0N!enlist,`a`b;
    (enlist;`a;`b)
    
    // let's define 'a' and use the same method
    q)a:("tst1";"tst2")
    q)enlist,a
    enlist
    "tst1"
    "tst2"
    q)0N!enlist,a;
    (enlist;"tst1";"tst2")
    

    让我们拼凑起来

    // define table
    q)table:([]venue:("tst1";"tst2";"tst3"))
    q)?[`table;enlist(not;(any;((/:;like);`venue;enlist,a)));0b;()]
    venue
    ------
    "tst3"
    

    请注意,您没有使用任何类型的正则表达式,因此最好使用直接匹配:

    q)select from table where not ([]venue) in ([]venue:a)
    venue
    ------
    "tst3"
    
    // or a function to help you
    q)f:{[lst] select from table where not ([]venue) in ([]venue:lst)}
    q)f[a]
    venue
    ------
    "tst3"
    

    HTH,肖恩

    【讨论】:

    • 嗨。请解释这个enlist,a。那是关于什么的。这是我第一次看到它,是的,您的解决方案有效。所以我所要做的就是创建一个列表,其中一个元素是 enlist。哇。谢谢
    • enlist,a 只是将一个函数与另一个变量连接起来。您可以对{x*x},a 执行相同的操作。需要将它们连接起来以创建给定的解析树结构。至于为什么需要enlist,这是由于/: 的处理方式,即parse "sym foo/: (x;y;z)"
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-03
    • 2023-03-03
    • 1970-01-01
    • 2013-02-18
    • 2016-01-29
    • 1970-01-01
    相关资源
    最近更新 更多