0

Currently I have a really weird behavior when I'm printing the results of the CEP pattern.

The data model as follows:

  • Event: (type:String, timestamp:Long)
  • VehicleRelated extends Event: (vehicleId:Integer)
  • Position extends VehicleRelated: (pos:Integer, direction:Integer)
  • Recognize extends VehicleRelated: (pos:Integer, id:Integer, direction:Integer)

The CEP part looks like the following:

val pattern = Pattern
  .begin[VehicleRelated]("before")
  .subtype(classOf[Position])
  .next("recognize")
  .subtype(classOf[Recognize])
  .next("after")
  .subtype(classOf[Position])
  .within(Time.seconds(5))

val patternStream = CEP.pattern(actionEvents, pattern)
val recognitions = patternStream
  .select(pattern => {
    val s = pattern("recognize").head.asInstanceOf[Recognize]
    LOG.debug(s.toString)
    s
  })

recognitions.print("RECO")

The Output of the logs is the following:

14:45:27,286 DEBUG stoff.schnaps.RecognizingJob$ - Recognize(VehicleId: 2, Id: 601, Pos: 1601, Direction: 35, Add: Map())
RECO:8> Recognize(VehicleId: null, Id: 601, Pos: 1601, Direction: 35, Add: Map())

Now the big question is, why is the vehicleId attribute null after I return the casted object? Any suggestions?

Update I made some investigations and found out that the PojoSerializer is the problem. The copy function gets called and on line 151 this.numFields is wrong.. The count includes only the count of the attributes of the Recognize class itself, but without the inherited classes, in this case Event and VehicleRelated.. The attributes type and timestamp are null too..

Daniel Eisenreich
  • 1,353
  • 3
  • 16
  • 32

1 Answers1

0

The problem was that the flink internal POJO serializer was not able to resolve the polymorphism properly.

Therefore I set the Kyro serializer as default with:

val config = env.getConfig
config.enableForceKryo()
Daniel Eisenreich
  • 1,353
  • 3
  • 16
  • 32