Flink Data Operator

Flink Data Operator #

Proxima provides native Apache Flink integration through two modules:

  • cz.o2.proxima:proxima-flink-core (@Experimental): Native Flink SourceFunction connectors (CommitLogSourceFunction and BatchLogSourceFunction) built on top of DirectDataOperator, supporting Flink checkpointing, partition distribution across subtasks, and event-time watermarks.
  • cz.o2.proxima:proxima-flink-utils: Utilities for integrating Flink clusters with Proxima’s global watermark coordination (FlinkGlobalWatermarkTracker).

Note: proxima-flink-core is currently marked @Experimental. If you need full-featured Flink batch/streaming pipelines including sinks (ProximaIO.write), batch snapshot reduction, or retractable joins, you can also run BeamDataOperator on Apache Flink using Apache Beam’s FlinkRunner (org.apache.beam:beam-runners-flink-1.20).

Dependencies #

dependencies {
  implementation "cz.o2.proxima:proxima-core:0.15.0"
  implementation "cz.o2.proxima:proxima-direct-core:0.15.0"
  implementation "cz.o2.proxima:proxima-flink-core:0.15.0"
  // Plus your storage IO & scheme modules, e.g.:
  implementation "cz.o2.proxima:proxima-direct-io-kafka:0.15.0"
  implementation "cz.o2.proxima:proxima-scheme-proto:0.15.0"
}

Extracting Elements with ResultExtractor #

Both Flink source functions accept a serializable ResultExtractor<T> to convert incoming StreamElements into the type emitted downstream in your Flink DataStream<T>:

  • ResultExtractor.identity() — emits raw StreamElement instances.
  • ResultExtractor.parsed() — extracts the deserialized attribute value (element.getParsed()).
  • Custom lambda element -> ... — extracts any custom POJO, Protobuf, or Flink Tuple type.

Streaming Source (CommitLogSourceFunction) #

CommitLogSourceFunction reads an unbounded Proxima commit log (such as Kafka or Pub/Sub) into a Flink DataStream:

  • Automatically distributes commit-log partitions across parallel Flink subtasks.
  • Implements Flink’s CheckpointedFunction to snapshot consumed Offsets into Flink operator state and resume seamlessly on recovery (observeBulkOffsets).
  • Emits Flink event-time timestamps (StreamElement.getStamp()) and advances Flink watermarks both on incoming elements and during idle periods (onIdle).
import cz.o2.proxima.core.repository.AttributeDescriptor;
import cz.o2.proxima.core.repository.Repository;
import cz.o2.proxima.core.storage.StreamElement;
import cz.o2.proxima.flink.core.CommitLogSourceFunction;
import cz.o2.proxima.flink.core.ResultExtractor;
import cz.o2.proxima.typesafe.config.ConfigFactory;
import java.util.Collections;
import org.apache.flink.api.common.typeinfo.TypeInformation;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
env.enableCheckpointing(30_000L);

Repository repo = Repository.of(ConfigFactory.load().resolve());
AttributeDescriptor<?> eventData = repo.getEntity("event").getAttribute("data");

CommitLogSourceFunction<StreamElement> source = new CommitLogSourceFunction<>(
    repo.asFactory(),
    Collections.singletonList(eventData),
    ResultExtractor.identity());

DataStream<StreamElement> events = env
    .addSource(source, "proxima-events-source", TypeInformation.of(StreamElement.class));

events
    .map(el -> el.getKey() + " @ " + el.getStamp())
    .print();

env.execute("Proxima Flink Streaming Job");

Tip: Always pass repo.asFactory() (never repo directly) into CommitLogSourceFunction or BatchLogSourceFunction so Flink can serialize the operator cleanly across TaskManagers.

Bounded Batch Source (BatchLogSourceFunction) #

BatchLogSourceFunction reads bounded batch attribute families (batch-updates or batch-snapshot, such as GCS, S3, HDFS, Cassandra, or HBase):

  • Wraps the underlying BatchLogReader with OffsetTrackingBatchLogReader so Flink checkpoints exact element indices within each partition.
  • On failover, skips already-completed partitions and resumes mid-partition without duplicating previously checkpointed records.
AttributeDescriptor<String> detailsAttr = repo.getEntity("user").getAttribute("details");

BatchLogSourceFunction<String> batchSource = new BatchLogSourceFunction<>(
    repo.asFactory(),
    Collections.singletonList(detailsAttr),
    ResultExtractor.parsed());

DataStream<String> userDetails = env
    .addSource(batchSource, "proxima-user-batch", TypeInformation.of(String.class));

Global Watermark Tracking (FlinkGlobalWatermarkTracker) #

When backfilling or throttling commit-log consumption to stay aligned with an active Flink streaming job, add cz.o2.proxima:proxima-flink-utils and configure FlinkGlobalWatermarkTracker with GlobalWatermarkThroughputLimiter.

FlinkGlobalWatermarkTracker polls the Flink JobManager REST API for the current minimum input watermark of a running job (optionally filtered to specific operator vertex names):

direct.throughput-limiter.my-family {
  class: cz.o2.proxima.core.storage.watermark.GlobalWatermarkThroughputLimiter
  tracker: cz.o2.proxima.flink.utils.FlinkGlobalWatermarkTracker
  rest-address: "http://flink-jobmanager:8081"
  job-name: "my-flink-streaming-job"
  vertex-names: [ "Source: proxima-events-source" ]
  update-interval-ms: 30000
}