Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 成对RDD中的scala正则表达式_Regex_Eclipse_Scala_Apache Spark - Fatal编程技术网

Regex 成对RDD中的scala正则表达式

Regex 成对RDD中的scala正则表达式,regex,eclipse,scala,apache-spark,Regex,Eclipse,Scala,Apache Spark,我对Scala/Eclipse/Spark中RDD操作中的regex有一个问题 我有两个数据文件,我已经解析了它们,并将它们连接在一起形成了一个RDD,其中有成对的[URL regexofur],它们看起来像 (http://coach.nationalexpress.com/nxbooking/journey-list, (^https://www\.nationalexpress\.com/bps/confirmation\.cfm\?id=|^https://coach\.national

我对Scala/Eclipse/Spark中RDD操作中的regex有一个问题

我有两个数据文件,我已经解析了它们,并将它们连接在一起形成了一个RDD,其中有成对的[URL regexofur],它们看起来像

(http://coach.nationalexpress.com/nxbooking/journey-list,
(^https://www\.nationalexpress\.com/bps/confirmation\.cfm\?id=|^https://coach\.nationalexpress\.com/nxbooking/delivery-details))
我希望运行一个操作,使每个URL(第一部分)与regex(第二部分)匹配。如果正则表达式匹配,则将其标记为true,否则将其标记为false

我尝试过编写一个函数:

def operation(s1:RDD[String], s2:RDD[String]) = 
s1 match{
case s2 => 't'
case _ => 'f'
}
但是匹配不是我想要的,我想正确使用正则表达式,并且遇到了麻烦

我还尝试将RDD分解成每一行,并运行一个函数,但没有成功。你认为最好的方法是什么


提前感谢

假设输入数据是成对的RDD
(string,regex)
,其中
regex
string
形式:
RDD[(string,string)]
,则此转换应如下所示:

val urlMatchRegexRdd = urlRegexPairsRDD.map{case (url, regex) => url match {
    regex.r(_ *) => ((url, regex), true)
    _ => ((url, regex), false)
}
这将产生一个形式为
RDD[((String,String),Boolean)]
的RDD,它使用添加的正则表达式匹配结果保留原始信息