title: How to create key-value pairs DStream in Spark Streaming
body: <p>I'm new to Spark Streaming. There's a project using Spark Streaming, the input is a key-value pair string like "productid,price".</p>
  
  <p>The requirement is to process each line as a separate transaction, and make RDD triggered every 1 second.</p>
  
  <p>In each interval I have to calculate the total price for each individual product, like</p>
  
  <pre><code>select productid, sum(price) from T group by productid
  </code></pre>
  
  <blockquote>
    <p>My current thought is that I have to do the following steps 
    1) split the whole line with \n val lineMap = lines.map{x=>x.split("\n")}</p>
    
    <p>2) split each line with "," val
    recordMap=lineMap.map{x=>x.map{y=>y.split(",")}}</p>
  </blockquote>
  
  <p>Now I'm confused about how to make the first column as key and second column as value, and use <strong>reduceByKey</strong> function to get the total sum.</p>
  
  <p>Please advise.</p>
  
  <p>Thanks</p>