Case Study: Retail Near Real-time Analytics | 309
• Use a spark UDF to calculate the discount for each customer using certain logic.
• Save the data along with the possible discount for each customer in Cassandra.
• Print the DataFrame in console.
The full code can be found below.
==================================================================
package com.retail.spark.nrt.SparkNRTSolutionPkg
import kafka.serializer.StringDecoder
import org.apache.spark.storage.StorageLevel
import org.apache.spark.streaming._
import org.apache.spark.SparkConf
import _root_.kafka.serializer.DefaultDecoder
import org.apache.spark.streaming.Seconds
import _root_.kafka.serializer.StringDecoder
import org.apache.log4j._
import org.apache.spark.streaming.kafka010.KafkaUtils ...