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

org.apache.flink.streaming.api.lineage.DefaultLineageGraph Maven / Gradle / Ivy

The 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.flink.streaming.api.lineage;

import org.apache.flink.annotation.Internal;

import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/** Default implementation for {@link LineageGraph}. */
@Internal
public class DefaultLineageGraph implements LineageGraph {
    @JsonProperty private final List lineageEdges;
    @JsonProperty private final List sources;
    @JsonProperty private final List sinks;

    private DefaultLineageGraph(List lineageEdges) {
        this.lineageEdges = lineageEdges;

        Set deduplicatedSources = new HashSet<>();
        Set deduplicatedSinks = new HashSet<>();
        for (LineageEdge lineageEdge : lineageEdges) {
            deduplicatedSources.add(lineageEdge.source());
            deduplicatedSinks.add(lineageEdge.sink());
        }
        this.sources = new ArrayList<>(deduplicatedSources);
        this.sinks = new ArrayList<>(deduplicatedSinks);
    }

    @Override
    public List sources() {
        return Collections.unmodifiableList(sources);
    }

    @Override
    public List sinks() {
        return Collections.unmodifiableList(sinks);
    }

    @Override
    public List relations() {
        return Collections.unmodifiableList(lineageEdges);
    }

    public static LineageGraphBuilder builder() {
        return new LineageGraphBuilder();
    }

    /** Build the default lineage graph from {@link LineageEdge}. */
    @Internal
    public static class LineageGraphBuilder {
        private final List lineageEdges;

        private LineageGraphBuilder() {
            this.lineageEdges = new ArrayList<>();
        }

        public LineageGraphBuilder addLineageEdge(LineageEdge lineageEdge) {
            this.lineageEdges.add(lineageEdge);
            return this;
        }

        public LineageGraphBuilder addLineageEdges(LineageEdge... lineageEdges) {
            this.lineageEdges.addAll(Arrays.asList(lineageEdges));
            return this;
        }

        public LineageGraph build() {
            return new DefaultLineageGraph(lineageEdges);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy