Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NU-1848: TypeInformation support for scala.Option #6952

Merged
merged 2 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading