I am creating web service for Apache Spark Sql in java and I am returning the result set as json. It runs quickly for minimum no of rows but for maximum no of rows it takes too much time to load. can you tell me how to return these results in an efficient way. Here is my java code
String output = "[";
SparkConf sparkConf = new SparkConf().setAppName("Hive").setMaster("local").set("spark.driver.allowMultipleContexts", "true");
JavaSparkContext ctx = new JavaSparkContext(sparkConf);
HiveContext sqlContext = new org.apache.spark.sql.hive.HiveContext(ctx.sc());
Row[] result = sqlContext.sql("Select * from activity where column="'value'" ).collect();
for (int i = 0; i < result.length; i++) {
output += "{\"" + "Column1" + "\":\"" + result[i].getString(0) + "\",\"" + "Column2" + "\":" + result[i].getString(1) + ",\"" + "Column3" + "\":" + result[i].getString(2) + ",\"" + "Column4" + "\":" + result[i].getString(3) + ",\"" + "Column5" + "\":" + result[i].getInt(4) + ",\"" + "Column6" + "\":" + result[i].getString(5) + ",\"" + "Column7" + "\":" + result[i].getString(6) + "},";
}
I am using for loop to get the contents of result sets. I may have 1 million rows so using for loop costs me more time. Is there any efficient way to achieve this