title: Kafka time difference last two records, KSQL or other?
body: <p>So I'm evaluating Kafka. In our use case would have to create new topics containing "time elapsed" from one event to the next, essentially since a sensor will report as "on" or "off" into Kafka. So having the timestamp, sensorname and state, create new topics with duration of the "on" and "off" state.</p>
  
  <ol>
  <li>Is that doable in KSQL, and how?  </li>
  <li>Or should one really leave this to consumers or stream processors to figure out?</li>
  </ol>
  
  <p>My data is something like this: </p>
  
  <pre><code>{ 2019:02:15 00:00:00, sensor1, off}
  { 2019:02:15 00:00:30, sensor1, on} 
  </code></pre>
  
  <p>to get result </p>
  
  <pre><code>{ 2019:02:15 00:30:00, sensor1, off, 30sec }. 
  </code></pre>
  
  <p>Essentially have to combine states of multiple sensors to determine combined state of a machine. Hundreds if not eventually thousands of sensors in a factory</p>