【发布时间】:2018-09-04 17:26:17
【问题描述】:
我正在尝试在一个字段上加入两个数据框。为此,我必须首先确保该字段是唯一的。所以我的事件顺序是:
- 读入第一个数据帧
- 选择我要加入的字段(例如,
field1),以及我要加入的另一个字段(field2) - 做
.distinct
那么,对于第二张桌子..
- 读入第二个数据帧
- 在
field1上与第一个表进行左连接 - 做
.distinct
我尝试运行我的脚本,但它花费的时间比它应该的要长。
为了调试它,我在连接前后的第一个表上添加了println 记录计数,结果如下:
在加入之前,记录数为904,326。之后,2,658,632。
所以我认为它正在爆炸,但不知道为什么。我认为这与选择两个字段后尝试仅使用一个“不同”有关..?
请帮忙!
代码如下:
val ticketProduct = Source.fromArg(args, "f1").read
.select($"INSTRUMENT_SK", $"TICKET_CODES_SK")
.distinct
val instrumentD = Source.fromArg(args, "f2").read
// println("instrumentD count before join is " + instrumentD.count)
.join(ticketProduct, Seq("INSTRUMENT_SK"), "leftouter")
// .select($"SERIAL_NBR", $"TICKET_CODES_SK")
.distinct
println("instrumentD count after join is " + instrumentD.count)
【问题讨论】:
-
我们能看到代码,如果可能的话,还能看到数据集吗?
-
另外,在加入它们之前尝试对每个将加入的数据帧进行区分
-
这是我的代码主体:
-
val ticketProduct = Source.fromArg(args, "f1").read .select($"INSTRUMENT_SK", $"TICKET_CODES_SK") .distinct val instrumentD = Source.fromArg(args, "f2" ).read // println("instrumentD 加入前的计数是 " + instrumentD.count) .join(ticketProduct, Seq("INSTRUMENT_SK"), "leftouter") // .select($"SERIAL_NBR", $"TICKET_CODES_SK") .distinct println("连接后的instrumentD计数为" + instrumentD.count) // .writeToSource(Source.fromArg(args, "output")) } } }
-
请在添加更多信息(代码等)时更新您的问题
标签: scala apache-spark dataframe join