简体   繁体   English

如何在Rethinkdb中的python lambda表达式中应用大于等于

[英]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.

相关问题 在Python中具有加号,等于号和大于号的表达式 - Expression with plus, equal, and greater than symbols in python 如何使 python 大于/小于或等于? - How to make a greater/less than or equal to on python? python 中的“大于”或“等于”与“等于”或“大于” - “Greater than” or “equal” vs “equal” or “greater than” in python 如何在django过滤器中做小于或等于和大于等于? - how to do less than or equal to and greater than equal to in django filter? 在 python 中,如何比较两个 CalVer 字符串以确定一个大于、小于或等于另一个? - In python, how can you compare two CalVer strings to determine if one is greater than, lesser than, or equal to, the other? 如何使用python更改条件“大于或等于”的excel单元格中字符串的字体颜色? - How to change font color of string in excel cell with condition "Greater than or equal to" using python? 如何使用 Python 查找等于或大于给定总和的值组合? - How To Use Python to find combinations of value with equal or greater than given sum? 如何使用Python中的字典找到值总和等于或大于k的键的可能组合? - How to find possible combination of keys having sum of values equal or greater than k using dictionary in Python? 如何在 python 中删除列表中大于或等于指定数字的数字 - How do you remove numbers greater than or equal to a specified number within a list, in python 在 Python Selenium 中等待某个值大于等于某个数 - Waiting for a value to be greater than or equal to a certain number in Python Selenium
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM