All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.kafka.streams.kstream.Joined Maven / Gradle / Ivy

There is a newer version: 3.7.1
Show newest version
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements. See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.kafka.streams.kstream;

import org.apache.kafka.common.serialization.Serde;

/**
 * The {@code Joined} class represents optional params that can be passed to
 * {@link KStream#join(KTable, ValueJoiner, Joined) KStream#join(KTable,...)} and
 * {@link KStream#leftJoin(KTable, ValueJoiner) KStream#leftJoin(KTable,...)} operations.
 */
public class Joined implements NamedOperation> {

    protected final Serde keySerde;
    protected final Serde valueSerde;
    protected final Serde otherValueSerde;
    protected final String name;

    private Joined(final Serde keySerde,
                   final Serde valueSerde,
                   final Serde otherValueSerde,
                   final String name) {
        this.keySerde = keySerde;
        this.valueSerde = valueSerde;
        this.otherValueSerde = otherValueSerde;
        this.name = name;
    }

    protected Joined(final Joined joined) {
        this(joined.keySerde, joined.valueSerde, joined.otherValueSerde, joined.name);
    }

    /**
     * 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              key type
     * @param              value type
     * @param             other value type
     * @return new {@code Joined} instance with the provided serdes
     */
    public static  Joined with(final Serde keySerde,
                                                   final Serde valueSerde,
                                                   final Serde otherValueSerde) {
        return new Joined<>(keySerde, valueSerde, otherValueSerde, null);
    }

    /**
     * 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  key type
     * @param  value type
     * @param  other value type
     * @return new {@code Joined} instance with the provided serdes
     */
    public static  Joined with(final Serde keySerde,
                                                   final Serde valueSerde,
                                                   final Serde otherValueSerde,
                                                   final String name) {
        return new Joined<>(keySerde, valueSerde, otherValueSerde, name);
    }

    /**
     * Create an instance of {@code Joined} with  a key {@link Serde}.
     * {@code null} values are accepted and will be replaced by the default key serde as defined in config.
     *
     * @param keySerde the key serde to use. If {@code null} the default key serde from config will be used
     * @param       key type
     * @param       value type
     * @param      other value type
     * @return new {@code Joined} instance configured with the keySerde
     */
    public static  Joined keySerde(final Serde keySerde) {
        return new Joined<>(keySerde, null, null, null);
    }

    /**
     * Create an instance of {@code Joined} with a value {@link Serde}.
     * {@code null} values are accepted and will be replaced by the default value serde as defined in config.
     *
     * @param valueSerde the value serde to use. If {@code null} the default value serde from config will be used
     * @param         key type
     * @param         value type
     * @param        other value type
     * @return new {@code Joined} instance configured with the valueSerde
     */
    public static  Joined valueSerde(final Serde valueSerde) {
        return new Joined<>(null, valueSerde, null, null);
    }

    /**
     * Create an instance of {@code Joined} with an other value {@link Serde}.
     * {@code null} values are accepted and will be replaced by the default value serde as defined in config.
     *
     * @param otherValueSerde the otherValue serde to use. If {@code null} the default value serde from config will be used
     * @param              key type
     * @param              value type
     * @param             other value type
     * @return new {@code Joined} instance configured with the otherValueSerde
     */
    public static  Joined otherValueSerde(final Serde otherValueSerde) {
        return new Joined<>(null, null, otherValueSerde, null);
    }

    /**
     * Create an instance of {@code Joined} with base name for all components of the join, this may
     * include any repartition topics created to complete the join.
     *
     * @param name the name used as the base for naming components of the join including any
     * repartition topics
     * @param  key type
     * @param  value type
     * @param  other value type
     * @return new {@code Joined} instance configured with the name
     *
     * @deprecated use {@link #as(String)} instead
     */
    @Deprecated
    public static  Joined named(final String name) {
        return new Joined<>(null, null, null, name);
    }

    /**
     * Create an instance of {@code Joined} with base name for all components of the join, this may
     * include any repartition topics created to complete the join.
     *
     * @param name the name used as the base for naming components of the join including any
     * repartition topics
     * @param  key type
     * @param  value type
     * @param  other value type
     * @return new {@code Joined} instance configured with the name
     *
     */
    public static  Joined as(final String name) {
        return new Joined<>(null, null, null, name);
    }


    /**
     * Set the key {@link Serde} to be used. Null values are accepted and will be replaced by the default
     * key serde as defined in config
     *
     * @param keySerde the key serde to use. If null the default key serde from config will be used
     * @return new {@code Joined} instance configured with the {@code name}
     */
    public Joined withKeySerde(final Serde keySerde) {
        return new Joined<>(keySerde, valueSerde, otherValueSerde, name);
    }

    /**
     * Set the value {@link Serde} to be used. Null values are accepted and will be replaced by the default
     * value serde as defined in config
     *
     * @param valueSerde the value serde to use. If null the default value serde from config will be used
     * @return new {@code Joined} instance configured with the {@code valueSerde}
     */
    public Joined withValueSerde(final Serde valueSerde) {
        return new Joined<>(keySerde, valueSerde, otherValueSerde, name);
    }

    /**
     * Set the otherValue {@link Serde} to be used. Null values are accepted and will be replaced by the default
     * value serde as defined in config
     *
     * @param otherValueSerde the otherValue serde to use. If null the default value serde from config will be used
     * @return new {@code Joined} instance configured with the {@code valueSerde}
     */
    public Joined withOtherValueSerde(final Serde otherValueSerde) {
        return new Joined<>(keySerde, valueSerde, otherValueSerde, name);
    }

    /**
     * Set the base name used for all components of the join, this may include any repartition topics
     * created to complete the join.
     *
     * @param name the name used as the base for naming components of the join including any
     * repartition topics
     * @return new {@code Joined} instance configured with the {@code name}
     */
    @Override
    public Joined withName(final String name) {
        return new Joined<>(keySerde, valueSerde, otherValueSerde, name);
    }

    public Serde keySerde() {
        return keySerde;
    }

    public Serde valueSerde() {
        return valueSerde;
    }

    public Serde otherValueSerde() {
        return otherValueSerde;
    }

    /**
     * @deprecated this method will be removed in a in a future release
     */
    @Deprecated
    public String name() {
        return name;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy