我有2个dataframes,我想找到除2等于所有列(surrogate_key,电流)的记录火花保存服用大量的时间
然后,我要保存新surrogate_key值的记录。
以下是我的代码:
val seq = csvDataFrame.columns.toSeq
var exceptDF = csvDataFrame.except(csvDataFrame.as('a).join(table.as('b),seq).drop("surrogate_key","current"))
exceptDF.show()
exceptDF = exceptDF.withColumn("surrogate_key", makeSurrogate(csvDataFrame("name"), lit("ecc")))
exceptDF = exceptDF.withColumn("current", lit("Y"))
exceptDF.show()
exceptDF.write.option("driver","org.postgresql.Driver").mode(SaveMode.Append).jdbc(postgreSQLProp.getProperty("url"), tableName, postgreSQLProp)
该代码给出正确的结果,但在写这些结果postgre卡住。
不知道是什么问题。还有没有更好的方法呢?
问候, Sorabh
还显示()写入正确postgre打印数据帧,但后来在写之前需要太多的时间。 –
'show'不会对整个数据执行转换,只需要显示多少数据(默认为20)。在写入postgres之前,您需要执行缓存+操作,然后您可以测量写入postgres的实际时间。 “很多时间”是一个非常广泛的描述,你有多少数据以及它实际上需要多少时间... – eliasah
嗨Eliasah,我用过cache()+ count(),它需要大约1/2小时只有3行10列,延迟也不是由于写入Postgre。在添加count()之后,它的count()现在需要时间。 –