Hello Guys I don't know what's wrong with me that ...
# troubleshooting
d
Hello Guys I don't know what's wrong with me that I can't find a simple doc or example for having a window based on event time. I have a very simple scenario, I want to read from kafka and have window based on field "@timestamp"!
s
are you using flink sql?
d
No I am using DataStream API and this is my code I want to convert to event time:
Copy code
case class Record(
                   `@timestamp`: Long,
                   host: Option[String],
                   request_uri: Option[String],
                   status: Option[String],
                   request_time: Option[String],
                   size_sent: Option[String]
                 )

case class HostError(
                      host: String,
                      errorcode: Int,
                      errorcount: Int
                    )

object StreamingJob extends AbstractStreamingJob[Record, HostError] {


  def main(args: Array[String]) {
    val parameter = ParameterTool.fromArgs(args)
    val filename = if (parameter.getBoolean("production", false) == true) "defaults-prod.conf" else "defaults-staging.conf"
    val config = ConfigFactory.load(filename).getConfig("jobs.host_error")
    val JOB_NAME = config.getString("JOB_NAME")
    val THRESHOLD = config.getInt("THRESHOLD")

    val env = StreamExecutionEnvironment.getExecutionEnvironment

    val kafka_consumer = StreamConsumer(config)
    val kafka_producer = StreamProducer(config)

    env.fromSource(kafka_consumer, WatermarkStrategy.noWatermarks()
        , "kafka_" + config.getString("KAFKA_SRC_TOPIC"))
      .map { x => StreamSerializer(x) }.name("raw_log")
      .filter(_.host.nonEmpty).filter(_.status.nonEmpty)
      .map(r => HostError(r.host.get, r.status.get.toInt, 1)).name("map_host")
      .keyBy(r => (r.host, r.errorcode))
      .window(SlidingProcessingTimeWindows.of(Time.seconds(20),
        Time.seconds(5)))
      .reduce { (e1, e2) => HostError(e2.host, e2.errorcode, e2.errorcount + e1.errorcount) }
      .name("agg_errors")
      .print()

    env.execute(JOB_NAME)

  }
}
x
You can refer to this doc for datastream window usage and this doc for working with event time.