scala - 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.
Expected Output Table or Dataframe
Please help me to get workaround for expected output.
解决方案
对于这种简单模式,最简单的解决方案是在为输入和输出模式定义案例类之后使用Dataset.flatMap 。
一个简单的 UDF 解决方案将返回一个序列,然后您可以使用functions.explode
. 远不如使用清洁和高效flatMap
。
最后但并非最不重要的一点是,您可以创建自己的表生成 UDF,但这对于这个问题来说是非常过分的。
推荐阅读
- blogger - 如何避免创建博主账号错误?
- vue.js - 为什么在 vue data() 中很难使用 vue-i18n(为什么它不是响应式的)
- javascript - 确定 pr 从对象中消除空键:用于多种过滤目的的值
- android - 如何使用非常小的尺寸按钮(24dp)android
- python - 如何阻止 Pandas DataFrame 无缘无故地将 int 转换为 float?
- css - 结合 box-shadow 和 z-index 时,Chrome 不会呈现正确的高度
- java - 如果放置在库 jar 中,则不会拾取 Bean 验证配置
- ios - React native - 信号 SIGILL 有一个非 Crashlytics 处理程序(
)。这会干扰报告 - sql-server - 使用 T-SQL 在 Linux 上获取 sql server 默认备份文件夹
- reactjs - 将调度操作导入 React 组件辅助