乡亲您好我有一个加载一些S3位置的数据集,并返回有趣的数据有条件申请`filter` /`where`到火花`Dataset` /`Dataframe`
private def filterBrowseIndex(spark: SparkSession, s3BrowseIndex: String, mids: Seq[String] = Seq(), indices: Seq[String] = Seq()): Dataset[BrowseIndex] = {
import spark.implicits._
spark
.sparkContext.textFile(s3BrowseIndex)
// split text dataset
.map(line => line.split("\\s+"))
// get types for attributes
.map(BrowseIndex.strAttributesToBrowseIndex)
// cast it to a dataset (requires implicit conversions)
.toDS()
// pick rows for the given marketplaces
.where($"mid".isin(mids: _*))
// pick rows for the given indices
.where($"index".isin(indices: _*))
功能}
如果有人提供mids = Seq()
或indices = Seq()
,此实现将过滤所有内容。另一方面,我希望语义只有在“mids
非空时才应用此where子句”(与indices
相同),以便在函数的用户提供空序列时不发生过滤。
有没有一个很好的功能方法来做到这一点?
对我表示感谢! –