According to How do I detect if a Spark DataFrame has a column , there is a function like df.columns.contains("column-name-to-check")
which can check whether a column exists. I searched around and didn't find similar function in Java Spark. Does anybody know whether there's a similar one in Java?
One of the options:
Arrays.asList(df.columns()).contains("column-name-to-check")
In the Java API, columns
returns String[]
. Therefore, I guess you can use java.util.Arrays
(sinceJava 8 ):
String yourColumn = "columnName";
String[] columns = df.columns();
boolean contains = Arrays.stream(columns).anyMatch(yourColumn::equals);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.