可以在Spark中保留Dataframe联接的顺序吗?

编程入门 行业动态 更新时间:2024-10-23 15:19:49
本文介绍了可以在Spark中保留Dataframe联接的顺序吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我目前正在尝试将两个DataFrame结合在一起,但在其中一个Dataframe中保持相同的顺序.

I'm currently trying to join two DataFrames together but retain the same order in one of the Dataframes.

从哪些操作保留了RDD顺序?,似乎(如果这是不准确的,因为我是Spark的新手.联接不会保留顺序,因为由于数据位于不同的分区中,所以行以未指定的顺序联接/到达"最终数据帧,而不是按指定的顺序到达.

From Which operations preserve RDD order?, it seems that (correct me if this is inaccurate because I'm new to Spark) joins do not preserve order because rows are joined / "arrive" at the final dataframe not in a specified order due to the data being in different partitions.

在保留一个表的顺序的同时,如何执行两个DataFrame的联接?

How could one perform a join of two DataFrames while preserving the order of one table?

例如

+ ------------ + --------- +|col1 |col2 |+ ------------ + --------- +|0 |一个||1 |b |+ ------------ + --------- +

加入

+ ------------ + --------- +|col2 |col3 |+ ------------ + --------- +|b |x ||一个|y |+ ------------ + --------- +

在 col2 上应该给出

+ ------------ + -------------------- +|col1 |col2 |第3列|+ ------------ + --------- + ---------- +|0 |一个|y ||1 |b |x |+ ------------ + --------- + ---------- +

我听说过有关使用 coalesce 或 repartition 的一些信息,但是我不确定.任何建议/方法/见解均表示赞赏.

I've heard some things about using coalesce or repartition, but I'm not sure. Any suggestions/methods/insights are appreciated.

编辑:这类似于在MapReduce中使用一个reducer吗?如果是这样,在Spark中会是什么样子?

Edit: would this be analogous to having one reducer in MapReduce? If so, how would that look like in Spark?

推荐答案

不能.您可以添加 monotonically_increasing_id 并在加入后重新排序数据.

It can't. You can add monotonically_increasing_id and reorder data after join.

更多推荐

可以在Spark中保留Dataframe联接的顺序吗?

本文发布于:2023-10-23 02:03:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1519413.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:顺序   Spark   Dataframe

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!