[英]How to apply Greater than equal in python lambda expression in Rethinkdb
I have below json record in RethinkDB table. 我在RethinkDB表中有下面的json记录。
[{
"pid": 12,
"sk": [
{
"sid": 30,
"et": 3
},
{
"sid": 22,
"et": 10
},
{
"sid": 30,
"et": 8
}
],
"wc": [
{
"wid": 7,
"et": 8
},
{
"wid": 3,
"et": 6
},
{
"wid": 9,
"et": 7
}
]
}]
Like this one, I have millions of rows in the table. 像这样,表中有数百万行。 What am trying to achieve is to filter this json based on input sets of {sid,et}
试图实现的是基于{sid,et}的输入集过滤此json
Am using below code in python (skObj is the input) :: 我在python中使用下面的代码(skObj是输入)::
skObj=[{'sid': 1, 'et': 9},{'sid': 27, 'et': 6}]
cursor2=r.table('cube7').filter(lambda row: r.expr(skObj).set_difference(row['sk']).is_empty())['pid'].run(t)
cur_list2 = list(cursor2)
The Above query correctly filters my cube7 table in RethinkDB as per the input sets of sk. 上面的查询根据sk的输入集正确过滤了我在RethinkDB中的cube7表。 skObj can contain sets upto 10.
skObj最多可以包含10个集合。
What I would like to see is for every input set 我想看到的是每个输入集
skObj=[{'sid': 22, 'et': 10},{'sid': 30, 'et': 8}]
I would like to filter the table with this condition: 我想用这种条件过滤表:
(sid=22 & et>=10) and (sid=30 & et>=8)
But currently it is doing equals only like 但目前它只做等于
(sid=22 & et=10) and (sid=30 & et=8)
How can I use greater than inside my lambda expression for et values for each set of (sid,et) ? 如何为每个(sid,et)组的et值使用大于lambda表达式内部的值?
How can I create generic expression from below - this works with raw data 如何从下面创建通用表达式-适用于原始数据
lambda x: (x['sid'] == 22) & (x['et'] >= 10)
So you want to get all the documents where the sk
array contains at least one document matching each predicate? 因此,您想获取
sk
数组包含至少一个与每个谓词匹配的文档的所有文档吗?
Does this do what you want? 这是您想要的吗?
r.table('cube7').filter(
lambda row: r.and_(r.args(r.expr(skObj).map(
lambda x: row['sk'].contains(
lambda y: (y['sid'] == x['sid']) & (y['et'] >= x['et'])
)
)))
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.