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

如何在Ballerina查询表达式中获取DISTINCT值?

在Ballerina查询表达式中获取DISTINCT值

当然可以通过Ballerina查询表达式获取唯一值,你只需要在select关键字前添加distinct关键字,就能自动过滤结果中的重复元素。修改后的代码如下:

string[]|error connectorProducts = from record {string product;} {product} in products
        distinct select product;

distinct关键字会对查询返回的结果做去重处理,最终connectorProducts数组里只会保留不重复的product字符串。如果后续遇到多字段去重的场景,还可以将目标字段组合成不可变的tuple或record后再使用distinct,不过针对你当前的单字段去重需求,上面的代码就完全够用。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.28 07:03:10