Skip to content

Commit

Permalink
Improvement: TypeInformation support for scala.Option (#6952)
Browse files Browse the repository at this point in the history
  • Loading branch information
lciolecki authored Sep 28, 2024
1 parent a254240 commit 785daa8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
* Scenario Activity API implementation
* [#6925](https://github.com/TouK/nussknacker/pull/6925) Fix situation when preset labels were presented as `null` when node didn't pass the validation.
* [#6935](https://github.com/TouK/nussknacker/pull/6935) Spel: Scenario labels added to meta variable - `#meta.scenarioLabels`
* [#6952](https://github.com/TouK/nussknacker/pull/6952) Improvement: TypeInformation support for scala.Option

## 1.17

Expand Down
3 changes: 3 additions & 0 deletions docs/MigrationGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ To see the biggest differences please consult the [changelog](Changelog.md).
are registered based on class of Serializer instead of instance of Serializer. If you have values that were
serialized by these Serializers in some state, the state won't be restored after upgrade.

* [#6952](https://github.com/TouK/nussknacker/pull/6952) Improvement: TypeInformation support for scala.Option:
If you used CaseClassTypeInfoFactory with case classes that contain the Option type, the state won't be restored after the upgrade.

## In version 1.17.0

### Code API changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.apache.flink.api.common.typeinfo.{TypeInfoFactory, TypeInformation}
import org.apache.flink.api.common.typeutils.TypeSerializer
import org.apache.flink.api.java.typeutils.TypeExtractor
import org.apache.flink.api.java.typeutils.runtime.NullableSerializer
import pl.touk.nussknacker.engine.flink.api.typeinfo.option.OptionTypeInfo

import java.lang.reflect.Type
import scala.reflect._
Expand Down Expand Up @@ -45,7 +46,13 @@ abstract class CaseClassTypeInfoFactory[T <: Product: ClassTag] extends TypeInfo
val fieldNames = fields.map(_.name.decodedName.toString)
val fieldTypes = fields.map { field =>
val fieldClass = mirror.runtimeClass(field.typeSignature)
TypeExtractor.getForClass(fieldClass)

if (classOf[Option[_]].isAssignableFrom(fieldClass)) {
val optionTypeClass = mirror.runtimeClass(field.typeSignature.typeArgs.head)
new OptionTypeInfo(TypeExtractor.getForClass(optionTypeClass))
} else {
TypeExtractor.getForClass(fieldClass)
}
}
(fieldNames, fieldTypes)
}
Expand Down

0 comments on commit 785daa8

Please sign in to comment.