From ec4b405b09483d665e2bb6e948e2396fabb7fbeb Mon Sep 17 00:00:00 2001 From: Arnaud <156100729+arnaud-daroussin@users.noreply.github.com> Date: Fri, 20 Dec 2024 22:21:32 +0100 Subject: [PATCH] #187 Documents state migration (#188) * Documents state migration * Update README.md Co-authored-by: Arnaud <156100729+arnaud-daroussin@users.noreply.github.com> * Validates snippets with mdoc * Improves readiness --------- Co-authored-by: novakov-alexey <117519424+novakov-alexey@users.noreply.github.com> --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index 961037d..21a9675 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,8 @@ This project is a community-maintained fork of official Apache Flink Scala API, `flink-scala-api` uses a different package name for all api-related classes like `DataStream`, so you can do gradual migration of a big project and use both upstream and this versions of scala API in the same project. +### API + The actual migration should be straightforward and simple, replace old import to the new ones: ```scala // original api import @@ -24,6 +26,27 @@ import org.apache.flinkx.api._ import org.apache.flinkx.api.serializers._ ``` +### State + +Ensure to replace state descriptor constructors using `Class[T]` param with constructors using `TypeInformation[T]` or `TypeSerializer[T]` param: +```scala mdoc +import org.apache.flink.api.common.state.ValueStateDescriptor +import org.apache.flink.api.common.typeinfo.TypeInformation + +// state using Kryo +val eventStateDescriptor = new ValueStateDescriptor[Option[String]]("event", + classOf[Option[String]]) +``` +```scala mdoc:reset-object +import org.apache.flinkx.api.serializers._ +import org.apache.flink.api.common.state.ValueStateDescriptor +import org.apache.flink.api.common.typeinfo.TypeInformation + +// state using flink-scala-api +val eventStateDescriptor = new ValueStateDescriptor[Option[String]]("event", + implicitly[TypeInformation[Option[String]]]) +``` + ## Usage `flink-scala-api` is released to Maven-central for 2.13 and 3. For SBT, add this snippet to `build.sbt`: