与Pyarrow的链滤器
我正在尝试使用多个参数在Pyarrow中搜索表。 看起来过滤器可以被束缚,但是我错过了使它实际上起作用的神奇咒语。
表从CSV加载,因此结构可以工作 - 我可以使用单个条件过滤,并且结果如预期。
链接过滤器:
table.filter(
compute.equal(table['a'], a_val)
).filter(
compute.equal(table['b'], b_val)
).filter(
compute.equal(table['c'], b_val)
)
导致错误:
pyarrow.lib.ArrowInvalid: Filter inputs must all be the same length
我怀疑问题是第二个过滤器是在原始Table
上,而不是第一个过滤器的过滤输出。
I am trying to search a table in pyarrow using multiple parameters.
It looks like filters can be chained, but I am missing the magical incantation to make it actually work.
Table is loaded from CSV, so the structure works — I can filter using a single condition and the results are as expected.
Chaining the filters:
table.filter(
compute.equal(table['a'], a_val)
).filter(
compute.equal(table['b'], b_val)
).filter(
compute.equal(table['c'], b_val)
)
Results in an error:
pyarrow.lib.ArrowInvalid: Filter inputs must all be the same length
I suspect the issue is that the second filter is on the original table
and not the filtered output of the first filter.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以将2个过滤器与
和_
组合在一起:You can combine 2 filters together with
and_
:我相信您的怀疑是正确的。
第一个调用
table.filter
给出的输出表比原始表更小,但是您在第二个过滤器中的表达式仍然取决于原始表,该表现在是大的。要解决此问题,只需将表简单地保存回第一个调用之后的变量就足够了。
例如这样:
I believe your suspicion is correct.
The first call to
table.filter
gives an output table that is smaller then the original table, but your expression in the second filter call still depends on the original table, which is now to large.To fix this, it should be enough to simply save the table back to a variable after the first call.
For instance like this:
链多滤波器的另一种方法是这样。好处是,您可以根据条件获得可选的过滤器。
Another way to chain multiple filters is like this. The benefit is that you can have optional filters based on conditions.