本文介绍了如何使用Sparklyr过滤部分匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是Sparklyr的新手(但熟悉spark和pyspark),我有一个非常基本的问题.我正在尝试根据部分匹配来过滤列.在dplyr中,我会这样写操作:
I'm new to sparklyr (but familiar with spark and pyspark), and I've got a really basic question. I'm trying to filter a column based on a partial match. In dplyr, i'd write my operation as so:
businesses %>%
filter(grepl('test', biz_name)) %>%
head
但是在spark数据帧上运行该代码却给了我
Running that code on a spark dataframe however gives me:
推荐答案
与标准Spark相同,您可以使用rlike
(Java正则表达式):
The same as in standard Spark, you can use either rlike
(Java regular expressions):
df <- copy_to(sc, iris)
df %>% filter(rlike(Species, "osa"))
# or anchored
df %>% filter(rlike(Species, "^.*osa.*$")
或like
(简单的SQL正则表达式):
or like
(simple SQL regular expressions):
df %>% filter(like(Species, "%osa%"))
这两种方法也都可以使用后缀表示法
Both methods can be also used with suffix notation as
df %>% filter(Species %rlike% "^.*osa.*$")
和
df %>% filter(Species %like% "%osa%")
分别.
有关详细信息,请参见vignette("sql-translation")
.
For details see vignette("sql-translation")
.
这篇关于如何使用Sparklyr过滤部分匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!