首页 > 解决方案 > Split one row into multiple rows of dataframe

问题描述

I want to convert one row from dataframe into multiple rows. If hours is same then rows will not get split but if hour is different then rows will split into multiple rows wrt difference between hours.I am good with solution using dataframe function or hive query.

Input Table or Dataframe
enter image description here


Expected Output Table or Dataframe enter image description here


Please help me to get workaround for expected output.

标签: scalaapache-sparkdataframe

解决方案


对于这种简单模式,最简单的解决方案是在为输入和输出模式定义案例类之后使用Dataset.flatMap 。

一个简单的 UDF 解决方案将返回一个序列,然后您可以使用functions.explode. 远不如使用清洁和高效flatMap

最后但并非最不重要的一点是,您可以创建自己的表生成 UDF,但这对于这个问题来说是非常过分的。


推荐阅读