Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spark DataFrame groupBy

I have Spark Java that looked like this. Code pulls data from oracle table using JDBC and displays the groupby output.

DataFrame jdbcDF = sqlContext.read().format("jdbc").options(options).load();
jdbcDF.show();   
jdbcDF.groupBy("VA_HOSTNAME").count().show();

Long ll = jdbcDF.count();
System.out.println("ll="+ll);

When I ran the code, jdbcDF.show(); is working, whereas the groupBy and count are not printing anything and no errors were thrown.

My column name is correct. I tried by printing that column and it worked, but when groupBy it's not working.

Can someone help me with DataFrame output? I am using spark 1.6.3.

like image 659
AKC Avatar asked Aug 10 '26 09:08

AKC


1 Answers

You can try

import org.apache.spark.sql.functions.count

jdbcDF.groupBy("VA_HOSTNAME").agg(count("*")).show()
like image 62
mrsrinivas Avatar answered Aug 13 '26 00:08

mrsrinivas