3

我在 q 中发现了一个奇怪的问题,我想这是一个可能的错误。我已经定义了一个简单的函数,它返回一个浮点数,给定一个日期作为输入:

give_dummy:{[the_date] 
   /// give_dummy[2013.05.10]  // <- if u wanna test
   :$[ the_date > 2013.01.01 ; 0.001 ; 0.002] ;
 }

如果单独调用,它可以正常工作:

q)give_dummy[2013.05.10]
0.001

不过,如果我尝试在查询中调用它,我会收到错误消息:

q)select  give_dummy[date] from tab where sym = sec, i >= first_i  , i < 4000
'type

如果我将函数简化为只返回输入日期(身份函数),它就可以在查询中使用。如果我将函数简化为只返回一个浮点数,而不比较日期,它就可以在查询中使用。当我在 if 语句中使用输入日期进行比较时,就会出现问题: $[ the_date > 2013.01.01 ; 0.001; 0.002]

如果我重新定义将浮点数而不是日期作为输入的函数,也会发生同样的情况,然后我尝试在查询中将价格作为输入:

 give_dummy:{[the_price] 
    /// give_dummy[12]  // <- if u wanna test
   :$[ the_price > 20 ; 0.001 ; 0.002] ;
 }
 q) give_dummy[12]
 0.002
 q)select  give_dummy[price] from tab where sym = sec, i >= first_i  , i < 4000
 'type

你知道为什么会这样吗?我什么都试过了。谢谢马可

4

1 回答 1

4

您需要:

select give_dummy each date from tab where ...

或者:

give_dummy:{[the_date] :?[ the_date > 2013.01.01 ; 0.001 ; 0.002]; }
select give_dummy[date] from tab where ...

?是有条件的向量。有关详细信息,请参见此处:http: //code.kx.com/q4m3/10_Execution_Control/

于 2013-05-29T12:17:02.207 回答