PaimonPartitionInfo.java

// 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.doris.datasource.paimon;

import org.apache.doris.catalog.PartitionItem;

import org.apache.paimon.partition.Partition;

import java.util.Collections;
import java.util.Map;

/**
 * Snapshot-scoped Paimon partition metadata used by Doris.
 *
 * <p>The map key is a logical partition name. It normally matches the Paimon path, but may
 * contain a typed suffix when multiple logical partitions share one physical path.
 */
public class PaimonPartitionInfo {
    /**
     * Whether the complete snapshot-scoped Paimon partition set can be represented as Doris
     * PartitionItems. UNPRUNABLE keeps queries correct by leaving scan planning to Paimon.
     *
     * <p>This capability state can be removed only after Doris supports every legal Paimon
     * partition type and partition conversion is guaranteed not to fail.
     */
    public enum PruningStatus {
        PRUNABLE,
        UNPRUNABLE
    }

    public static final PaimonPartitionInfo EMPTY = new PaimonPartitionInfo(PruningStatus.PRUNABLE);
    public static final PaimonPartitionInfo UNPRUNABLE = new PaimonPartitionInfo(PruningStatus.UNPRUNABLE);

    private final PruningStatus pruningStatus;
    private final Map<String, PartitionItem> nameToPartitionItem;
    private final Map<String, Partition> nameToPartition;

    private PaimonPartitionInfo(PruningStatus pruningStatus) {
        this.pruningStatus = pruningStatus;
        this.nameToPartitionItem = Collections.emptyMap();
        this.nameToPartition = Collections.emptyMap();
    }

    public PaimonPartitionInfo(Map<String, PartitionItem> nameToPartitionItem,
            Map<String, Partition> nameToPartition) {
        this.pruningStatus = PruningStatus.PRUNABLE;
        this.nameToPartitionItem = nameToPartitionItem;
        this.nameToPartition = nameToPartition;
    }

    public Map<String, PartitionItem> getNameToPartitionItem() {
        return nameToPartitionItem;
    }

    public Map<String, Partition> getNameToPartition() {
        return nameToPartition;
    }

    public PruningStatus getPruningStatus() {
        return pruningStatus;
    }
}