【问题标题】:Create an empty DF using schema from another DF (Scala Spark)使用来自另一个 DF (Scala Spark) 的模式创建一个空 DF
【发布时间】:2023-03-07 17:53:01
【问题描述】:

我必须将一个 DF 与另一个从特定路径读取的具有相同架构的 DF 进行比较,但可能在该路径中没有文件,所以我认为我必须将它与具有相同的空 DF 进行比较列作为原始列。

所以我正在尝试使用另一个包含大量列的 DF 的架构创建一个 DF,但我找不到解决方案。我一直在阅读以下帖子,但没有人帮助我:

How to create an empty DataFrame with a specified schema?

How to create an empty DataFrame? Why "ValueError: RDD is empty"?

How to create an empty dataFrame in Spark

我怎样才能在 scala 中做到这一点?还是选择其他方案更好?

【问题讨论】:

    标签: scala apache-spark


    【解决方案1】:

    originalDF.limit(0) 将返回具有相同架构的空数据框。

    【讨论】:

      猜你喜欢
      • 2018-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-14
      • 2021-09-07
      • 2020-11-12
      • 2017-09-11
      • 2017-06-26
      相关资源
      最近更新 更多