Giter Site home page Giter Site logo

flink-protobuf's Introduction

Protobuf serialization support for Apache Flink

CI Status Maven Central License: Apache 2

This project is an adapter to connect Google Protobuf to the flink's own TypeInformation-based serialization framework. This project can be useful if you have:

  • oneof-encoded protobuf messages, which cannot be efficiently encoded using flink's serialization without Kryo fallback.
  • flexible requirements on schema evolution for POJO classes (as compared to Flinks' for POJOs and Scala case classes)
  • schema evolution support is needed for scala case classes (as Flink lacks it out of the box)

Usage

flink-protobuf is released to Maven-central. For SBT, add this snippet to build.sbt:

libraryDependencies += "io.findify" %% "flink-protobuf" % "0.2"

Then, given that you have a following message format:

message Foo {
    required int32 value = 1;
}

You can build a TypeInformation for scalapb-generated classes like this:

import io.findify.flinkpb.FlinkProtobuf

implicit val ti = FlinkProtobuf.generateScala(Foo)
val result      = env.fromCollection(List(Foo(1), Foo(2), Foo(3)))

For Java it's going to look a bit different:

import io.findify.flinkprotobuf.java.Tests;
import org.apache.flink.api.common.typeinfo.TypeInformation;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

TypeInformation<Tests.Foo> ti = FlinkProtobuf.generateJava(Tests.Foo.class, Tests.Foo.getDefaultInstance());
env.fromCollection(List.of(Tests.Foo.newBuilder().setValue(1).build()), ti).executeAndCollect(100);

Schema evolution

Compared to Flink schema evolution for POJO classes, with flink-protobuf you can do much more:

  • fields can be renamed (as protobuf uses an index-based encoding for field names)
  • types can be changed (so optional field can be made repeated, or int32 can be upcasted to int64)

For Scala case classes Flink has no support for schema evolution, so with this project you can:

  • add, rename, remove fields
  • change field types

Compatibility

The library is built over Flink 1.13 for Scala 2.12, but should be binary compatible with older flink versions. Scala 2.11 version is not planned, as ScalaPB already dropped it's support.

License

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/

flink-protobuf's People

Contributors

shuttie avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.