From 3f4cc9e9a18a3bd11205468539b3bc11acb3995f Mon Sep 17 00:00:00 2001 From: Arnaud <156100729+arnaud-daroussin@users.noreply.github.com> Date: Thu, 19 Dec 2024 19:04:16 +0100 Subject: [PATCH 1/4] Documents state migration --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index 961037d..67a43c0 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,18 @@ import org.apache.flinkx.api._ import org.apache.flinkx.api.serializers._ ``` +### State + +`flink-scala-api` generates at compile-time specific TypeInformation & TypeSerializer. To use them for state serialization, ensure to replace state descriptor constructors using `Class[T]` param with constructors using `TypeInformation[T]` param: +```scala +// state using Kryo +val eventStateDescriptor = new ValueStateDescriptor[Event]("event", classOf[Event]) +``` +```scala +// state using flink-scala-api +val eventStateDescriptor = new ValueStateDescriptor[Event]("event", implicitly[TypeInformation[Event]]) +``` + ## Usage `flink-scala-api` is released to Maven-central for 2.13 and 3. For SBT, add this snippet to `build.sbt`: From 172ff9fff0a7a3ca54a5954bee2feedc2b3ad981 Mon Sep 17 00:00:00 2001 From: novakov-alexey <117519424+novakov-alexey@users.noreply.github.com> Date: Fri, 20 Dec 2024 14:02:17 +0100 Subject: [PATCH 2/4] Update README.md Co-authored-by: Arnaud <156100729+arnaud-daroussin@users.noreply.github.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 67a43c0..eb4b9d5 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ import org.apache.flinkx.api.serializers._ ### State -`flink-scala-api` generates at compile-time specific TypeInformation & TypeSerializer. To use them for state serialization, ensure to replace state descriptor constructors using `Class[T]` param with constructors using `TypeInformation[T]` param: +Ensure to replace state descriptor constructors using `Class[T]` param with constructors using `TypeInformation[T]` or `TypeSerializer[T]` param: ```scala // state using Kryo val eventStateDescriptor = new ValueStateDescriptor[Event]("event", classOf[Event]) From 1fb1acf94f11c3f078a0caf812fbaaf5a704fdad Mon Sep 17 00:00:00 2001 From: adaroussin Date: Fri, 20 Dec 2024 15:19:16 +0100 Subject: [PATCH 3/4] Validates snippets with mdoc --- README.md | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index eb4b9d5..7521345 100644 --- a/README.md +++ b/README.md @@ -28,14 +28,19 @@ 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 +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[Event]("event", classOf[Event]) +val eventStateDescriptor = new ValueStateDescriptor[Option[String]]("event", classOf[Option[String]]) ``` -```scala +```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[Event]("event", implicitly[TypeInformation[Event]]) +val eventStateDescriptor = new ValueStateDescriptor[Option[String]]("event", implicitly[TypeInformation[Option[String]]]) ``` ## Usage From cd41e27c46db65aa7d376aa610f480ab31ea3965 Mon Sep 17 00:00:00 2001 From: adaroussin Date: Fri, 20 Dec 2024 15:25:50 +0100 Subject: [PATCH 4/4] Improves readiness --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7521345..21a9675 100644 --- a/README.md +++ b/README.md @@ -32,15 +32,19 @@ Ensure to replace state descriptor constructors using `Class[T]` param with cons ```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]]) +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]]]) +val eventStateDescriptor = new ValueStateDescriptor[Option[String]]("event", + implicitly[TypeInformation[Option[String]]]) ``` ## Usage