How to select constant values ​​from Dataframe encoding in Java

I have a dataframe df1 with a fixed number of columns. I applied the inner join to another df2 frame.

However, while we select the record, I need to select some constant numbers that I currently cannot.

I read the examples in scala, but the corresponding java does not work.

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 selection method of 8, as in the example above.

I know withColumnapi, but not sure about the implementation.

Thank.

+4
source share
2 answers

That 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))

, . ,

.withColumn("constantString",lit("some_string"))
+6

sql ?

df1.registerAsTempTable("df1");
df2.registerAsTempTable("df2");

val joinedDf = hc.sql("Select df1.a1, df1.a2, df2.a2, 8 from df1 inner join df2 on df1.a1 = df2.a1");
+2

All Articles