You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何编写自定义Kusto函数实现标的投资工具查询?

Kusto 标的映射函数修正方案

原代码存在的问题

  • 未使用传入的SecId参数过滤数据,导致返回结果无法匹配目标证券
  • 列名错误:规则要求返回UnderlyingInvestment,但代码中误写为UnderlyingInv
  • 获取最新数据的方式效率低下,且未保证单条匹配
  • 返回逻辑未正确提取目标标的值

修正后的函数代码

.create-or-alter function Risk_Ticker(SecId: string)
{
    database('test').ETLN_SecMaster
    // 过滤目标证券的记录
    | where Code == SecId
    // 获取该证券的最新版本数据(按FileDateTime取最大值)
    | summarize arg_max(FileDateTime, *) by Code
    // 根据RecordClass规则映射标的
    | extend MappedUnderlying = case(
        RecordClass == "SwapInvestment", InvestmentIn,
        RecordClass in ("Warrant", "Option", "Future"), UnderlyingInvestment,
        Code  // 其他类型直接返回自身Code
    )
    // 提取并返回标的值
    | project MappedUnderlying
    | toscalar()
}

关键修改说明

  1. 添加目标过滤:通过where Code == SecId确保只处理传入的目标证券数据
  2. 优化最新数据获取:用arg_max(FileDateTime, *) by Code替代原有的两次查询,性能更优且能直接拿到单条最新记录
  3. 修正列名错误:将UnderlyingInv改为规则要求的UnderlyingInvestment
  4. 简化返回逻辑:先完成过滤和映射,再通过toscalar()直接返回单个标的值

内容的提问来源于stack exchange,提问作者A_4964835789

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.18 20:59:58