如何使用Sparklyr过滤部分匹配 [英] How to filter on partial match using sparklyr

查看:87
本文介绍了如何使用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:

错误:org.apache.spark.sql.AnalysisException:未定义的函数:'GREPL'.该函数既不是注册的临时函数,也不是在数据库"project_eftpos_failure"中注册的永久函数.第5行pos 7

Error: org.apache.spark.sql.AnalysisException: Undefined function: 'GREPL'. This function is neither a registered temporary function nor a permanent function registered in the database 'project_eftpos_failure'.; line 5 pos 7

推荐答案

与标准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过滤部分匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆