我有一个Azure Cosmos DB,下面是以下文档。 在此,电子邮件jim@test.com的人员有3个角色,如何查询此信息以返回包含电子邮件和3个角色的列表? 我现在所拥有的只是以下内容,但会返回重复的电子邮件地址。
public static void main(String[] args) {
List<String> a1 = Arrays.asList("v1", "route1", "1.4", "destination1");
List<String> a2 = Arrays.asList("v1", "route2", "2.3", "destination1");
List<String> a3 = Arrays.asList("v2", "route2", "3.0", "destinationx");
List<String> a4 = Arrays.asList("v1", "route3", "1.2", "destination2");
List<String> a5 = Arrays.asList("v1", "route4", "3.4", "destination2");
List<List<String>> all = List.of(a1, a2, a3, a4, a5);
List<String> str = all.stream().filter(l -> "v1".equals(l.get(0)))
.map(l -> {
double v = Double.parseDouble(l.get(2)) + Double.parseDouble(a5.get(2));
return String.format("%s,%s,%s,%s,%s,%1.1f", l.get(0), l.get(1), l.get(3), "route4", a5.get(3), v);
})
.collect(Collectors.toList());
str.forEach(System.out::println);
}
答案 0 :(得分:0)
您需要用户定义的功能才能执行此操作。寄存器:
function getEmailAndRoles(doc) {
var result = { Email: doc.Email }
result.Roles = []
for(idx = 0; idx < doc.OrgRoles.length; idx++) {
result.Roles.push(doc.OrgRoles[idx].RoleDesc)
}
return result;
}
然后致电
SELECT udf.getEmailAndRoles(c)
FROM c
WHERE c.Email = "jim@test.com"