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 committed Oct 4, 2024
1 parent 1f0495b commit 26a9e12
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions docs/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

#### Highlights

### 1.17-esp
* [#6952](https://github.com/TouK/nussknacker/pull/6952) Improvement: TypeInformation support for scala.Option

### 1.17.1 (Not released yet)

* [#6880](https://github.com/TouK/nussknacker/pull/6880) Performance optimization of generating Avro messages with unions
Expand Down
4 changes: 4 additions & 0 deletions docs/MigrationGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

To see the biggest differences please consult the [changelog](Changelog.md).

## In version 1.17-esp
* [#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 @@ -5,6 +5,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 @@ -41,7 +42,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 26a9e12

Please sign in to comment.