Dataframe 用于从数据帧查找所有间隔重叠的Spark
我有一个由两列组成的区间数据帧:“from”,“to” 例如: 从…起 到 1. 10 16 18 9 15 11 14Dataframe 用于从数据帧查找所有间隔重叠的Spark,dataframe,apache-spark,intervals,Dataframe,Apache Spark,Intervals,我有一个由两列组成的区间数据帧:“from”,“to” 例如: 从…起 到 1. 10 16 18 9 15 11 14 将列值放入列表中,对其排序,转换为对,然后转换为数据帧 我不知道级别是什么 scala> def toPairs[A](xs: Seq[A]): Seq[(A,A)] = xs.zip(xs.tail) toPairs: [A](xs: Seq[A])Seq[(A, A)] scala> val df = Seq((1, 10),(16, 18), (9, 15
将列值放入列表中,对其排序,转换为对,然后转换为数据帧 我不知道
级别是什么
scala> def toPairs[A](xs: Seq[A]): Seq[(A,A)] = xs.zip(xs.tail)
toPairs: [A](xs: Seq[A])Seq[(A, A)]
scala> val df = Seq((1, 10),(16, 18), (9, 15), (11, 14)).toDF("from", "to")
df: org.apache.spark.sql.DataFrame = [from: int, to: int]
scala> val col1 = df.select($"from").rdd.map(r => r(0).asInstanceOf[Integer]).collect()
col1: Array[Integer] = Array(1, 16, 9, 11)
scala> val col2 = df.select($"to").rdd.map(r => r(0).asInstanceOf[Integer]).collect()
col2: Array[Integer] = Array(10, 18, 15, 14)
scala> toPairs((col1 ++ col2).sorted).toDF("from", "to").show
+----+---+
|from| to|
+----+---+
| 1| 9|
| 9| 10|
| 10| 11|
| 11| 14|
| 14| 15|
| 15| 16|
| 16| 18|
+----+---+