Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spark - Divide int with column?

I'm trying to divide a constant with a column. I know I can do

df.col("col1").divide(90)

but how can I do (90).divide(df.col("col1")) (obviously this is incorrect). Thank you!

like image 455
lte__ Avatar asked Aug 09 '16 15:08

lte__


2 Answers

Use o.a.s.sql.functions.lit:

lit(90).divide(df.col("col1"))

or o.a.s.sql.functions.expr:

expr("90 / col1")
like image 82
zero323 Avatar answered Nov 15 '22 19:11

zero323


Alternatively, this can be used as well

lit(90)/col("col1")
like image 30
Shubham Gupta Avatar answered Nov 15 '22 19:11

Shubham Gupta