Scala 学习草稿 1

原创
2017/01/11 22:56
阅读数 97
class DomainNamePartitioner(numParts:Int) extends Partitionar {
	override def numPartitions:Int = numParts
	override def getPartition(key:Any):Int = {
		val domain = new Java.net.URL(key.toString()).getHost()
		val code = (domain.hashCode % numPartitions)

		if(code <0 ) {
			code + numPartitions
		} else {
			code
		}
	}

	override def equals(key:Any):Boolean = other match {
		case dnp:DomainNamePartitioner =>
			dnp.numPartitions == numPartitions
		case _ =>
			false
	} 
}

 

上面这段是一个自定义的partitioner好像是RDD分区用的

有哪位大神告诉我上面的other match是什么鬼语法。 

刚看spark。 这语法other match啥的真是少见。

class SearchFunction(object):

	def __init__(self,query):
		self.query = query

	def isMatch(self,s):
		return self.query in s


	def getMatchesFunctionReference(self,rdd):
		return rdd.filter(self.isMatch)

	def getMatchesMemberReference(self,rdd):
		return rdd.filter(lambda x:s)




class WordkFunctions(object):
	def getMatchesNoReference(self,rdd):
		query = self.query
		return rdd.filter(lambda x:query in x)

 

class SearchFunctions(val query:String) {
	def isMatch(s:String):Boolean = {
		s.contains(query)
	}

	def getMatchesFunctionReference(rdd:RDD[String]):RDD[String] {
		rdd.map(isMatch)
	}

	def getMatchesFieldReference(rdd:RDD[String]):RDD[String] = {
		rdd.map(x=>x.split(query))
	}

	def getMatchesNoReference(rdd:RDD[String]):RDD[String] {
		val query_ = this.query
		rdd.map(x=>x.split(query_))
	}
}

为了节省点硬盘都粘上来了了。

 

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部