Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The Stream Table join is inflexible how it handles late out of order data in its current state. There is only one option from the stream side and only recently is there a second option on the table sideWe recently added versioned tables which allow the table side of the a join to be processed in a timestamp aware method, but it is not taken advantage of in joins. Right now we only have the option to process the stream side in the offset order as the records arrive. However a record that is a better fit might show up in the table later. This semantic gap leads to incorrect output in some cases as the stream can only process data as it comes in and then is joined with whatever is the latest version in the table.

If the table side uses a materialized version store the value is the latest by stream time rather than by offset , it can store multiple versions of each record within its defined grace period. This proposal would bring the stream side into alignment with that flexibility. By adding a grace period buffer to the stream side it can wait until it is certain that the record in the table side is the right one for its timestamp.

In summary, by buffering the stream side the join will be able to find the correct version of the key in the table for the timestamp.

Small example.

Say we have a versioned table like this and a grace period of 10:

KeyValue at timestamp 1val@TS2val@TS3
1aaa
2bxx
3ccy

and a stream joining with it like this:

KeyValueTS
1

d

4
2e1
3f2
2g2
3h3

With these changes and a large enough grace period we would buffer the stream and always have the same join output:

KeyJoin result
2eb
3fc
2gx
3hy
1da

Without buffering the stream it could look like this:

KeyJoin result
1da
2ex
3fy
2gx
3hy

or this is also a valid result:

KeyJoin result
1da
2eb
3fc
2gb
3hc

Public Interfaces

Code Block
titleJoined.java
linenumberstrue
public class Joined {
   /**
	* Set the grace period on the stream side of the join. Records will enter a buffer before being processed. Out Lateof order records in the grace period will be processed in timestamp order,. Late records, out of the grace period, will be dropped.
	*
	* @param gracePeriod the duration of the grace period. If zero, no buffer will be used. 
	* @return new {@code Joined} instance configured with the gracePeriod
	*/
	public Joined withGracePeriod(Duration gracePeriod);

   /**
     * Create an instance of {@code Joined} with key, value, and otherValue {@link Serde} instances.
     * {@code null} values are accepted and will be replaced by the default serdes as defined in
     * config.
     *
     * @param keySerde the key serde to use. If {@code null} the default key serde from config will be
     * used
     * @param valueSerde the value serde to use. If {@code null} the default value serde from config
     * will be used
     * @param otherValueSerde the otherValue serde to use. If {@code null} the default value serde
     * from config will be used
     * @param name the name used as the base for naming components of the join including any
     * repartition topics
	 * @param gracePeriod Duration of the stream side buffer
     * @param <K> key type
     * @param <V> value type
     * @param <VO> other value type
     * @return new {@code Joined} instance with the provided serdes
     */
    public static <K, V, VO> Joined<K, V, VO> with(final Serde<K> keySerde,
                                                   final Serde<V> valueSerde,
                                                   final Serde<VO> otherValueSerde,
                                                   final String name,
                                                   final Duration gracePeriod);

    public Duration gracePeriod() {
        return gracePeriod;
    }
}

...

If a grace period is not set the join will execute as before, using the same logic in the stream table join node. If a grace period of zero is set the join will drop all late out of order records from the stream side operations. If the grace period is non zero, the record will enter a stream buffer and will dequeue when the record timestamp is greater than stream time plus the grace period.

...

Old joins will not be affected, in order to use the new feature users will need to set a grace period. Nothing needs to be deprecated.

Changing grace period

Test Plan

The testing should be covered with unit test and integration test. The only other tests that would be necessary, would be benchmarking to assess the  performance impact on the stream buffer on the join.

...

  • Only allowing grace period for versioned tables. This would be unnecessarily restrictive especially if the table is not going to change and there is no need for the versioning. Or if the table is already materialized for another use that does not want versioning
  • Offset order buffer. It might make sense to do this, but it should be part of a follow up kip. The point of adding a buffer to the stream in joins is to process records based on timestamp rather the order they come out of the topic. Adding offset processing seems counterintutive and out of scope.