java - Dividing the value of 2 columns in spark dataframe -


the table looks this

i have table in spark stored dataframe. want dataframe(url,url1,ratio) contains ratio,where ratio = count1/count in it. how write operation it?

it's straightforward :

import spark.implicits._ val newdf = df.withcolumn("ratio", $"count1" / $"count")  

this line of code add column named ration df , sotore result in newdf

edit 1 : (solution in java requested)

import org.apache.spark.sql.functions._ dataset<row> newdf = df.withcolumn("ration", col("count1").divide(col("count")) 

Comments

Popular posts from this blog

sql - Time in datatime field -

javascript - How to split the success output from an Ajax post? -

java - sharing object across different classes -