嗨,我有具有以下结构的数据框,我想做的是从表Histoachat中获取网站应该在POS中的数据,而FRN应该是供应商DataFrame的ID码头应在表格中
histoachat.printSchema()
pos.printSchema()
supplier.printSchema()
article.printSchema()
pos.printSchema()
root
|-- SITE: decimal(5,0) (nullable = false)
|-- FRN: string (nullable = true)
|-- CODA: string (nullable = true)
|-- QT: decimal(38,0) (nullable = true)
|-- PB: decimal(38,0) (nullable = true)
|-- REMI: decimal(38,0) (nullable = true)
|-- PNETTVA: decimal(38,0) (nullable = true)
|-- SCH: decimal(38,0) (nullable = true)
root
|-- id: long (nullable = false)
root
|-- id: long (nullable = false)
root
|-- id: long (nullable = false)
root
|-- id: long (nullable = false)
在这里我仍然遇到外国密钥问题,最终数据框架将插入包含三个外国键网站的PostgreSQL表中,FRN和CODA
val test_Pos = histoachat.select($"SITE" as "pos_id").except(pos.select("id").distinct())
val supplier_Test = histoachat.select($"FRN" as "frn_id").except(supplier.select("id").distinct())
val article_Test = histoachat.select($"CODA" as "art_id").except(article.select("id").distinct())
val finalHistoachat = histoachat.except(exRows)
任何帮助谢谢在这里我得到的问题
非常感谢
我有一个昂贵的解决方案,即通过使用join
val finalHistoachat = histoachat.as("histo").join(pos.as("pos"), $"histo.SITE" === $"pos.id")
.drop($"pos.id")
.as("joined1")
.join(supplier.as("sup"), $"joined1.FRN" === $"sup.id")
.drop($"sup.id")
.as("joined2")
.join(article.as("art"), $"joined2.CODA" === $"art.id")
.drop($"art.id")
我希望答案很有帮助,直到您获得一些灯光答案,这个答案应帮助您获得最终的数据框架