Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
279 views
in Technique[技术] by (71.8m points)

How to use Pyspark UDF to update a particular column in Mysql table?

I have a dataframe which contains two column 'mobile' & 'totalcount' and I want to update 'totalcount' column of the dataframe in mysql table in which 'totalcount' column is already present. I was doing this with simple 'for' loop but it's taking too long to update. How can I speed up my process or how can I use UDF functions to do the same?

for row in df.rdd.collect():
    query = f"UPDATE dummy.member_report SET totalcount = '{row.totalcount}' WHERE mobile = '{row.mobile}'"        
    Mysql_insert(spark,query)
    print("finsished")
question from:https://stackoverflow.com/questions/66045820/how-to-use-pyspark-udf-to-update-a-particular-column-in-mysql-table

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...