/*
 * 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.ignite.internal.sql.engine.prepare;

import it.unimi.dsi.fastutil.ints.IntSet;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import org.apache.ignite.internal.sql.engine.rel.IgniteRel;

/**
 * Relation with sources.
 */
public final class RelWithSources {

    private final IgniteRel rel;

    private final Long2ObjectMap<IgniteRel> sourceRels;

    private final IntSet modifiedTables;

    /**
     * Constructor.
     *
     * @param rel Relation.
     * @param sourceRels Source relations.
     * @param modifiedTables Modified tables.
     */
    public RelWithSources(IgniteRel rel, Long2ObjectMap<IgniteRel> sourceRels, IntSet modifiedTables) {
        this.rel = rel;
        this.sourceRels = sourceRels;
        this.modifiedTables = modifiedTables;
    }

    /** Plan. */
    public IgniteRel root() {
        return rel;
    }

    /** Returns tables modified by the plan. */
    public IntSet modifiedTables() {
        return modifiedTables;
    }

    /** Returns a source relation by the given id. */
    public IgniteRel get(long sourceId) {
        return sourceRels.get(sourceId);
    }

    /** Returns a map of source relations. */
    public Long2ObjectMap<IgniteRel> sources() {
        return sourceRels;
    }
}
