I have a dataframe df1 with fixed number of columns. I have applied an inner join with another dataframe df2.
However, while the select is written, I need to select some constant numbers which I am currently unable to.
I have read examples in scala but corresponding java isn't working.
df1.join(df2).filter(df1.col("a1").$eq$eq$eq(df2.col("a1")))
.select(df1.col("a1"), df1.col("a2"), df2.col("a2"), 8)
Suggest a way to select 8 as in above example.
I am aware of withColumn
api as well but not sure about the implementation.
Thanks.
This should work.
val joinedDF = df1.join(df2).filter(df1.col("a1").$eq$eq$eq(df2.col("a1")))
.select(df1.col("a1"), df1.col("a2"), df2.col("a2")).withColumn("constant", lit(8))
That is if you want to add an integer. If you want to add a constant string, use this after select
.withColumn("constantString",lit("some_string"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With