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

org.dinky.shaded.paimon.append.AppendOnlyCompactionTask 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.dinky.shaded.paimon.append;

import org.dinky.shaded.paimon.data.BinaryRow;
import org.dinky.shaded.paimon.io.CompactIncrement;
import org.dinky.shaded.paimon.io.DataFileMeta;
import org.dinky.shaded.paimon.io.NewFilesIncrement;
import org.dinky.shaded.paimon.operation.AppendOnlyFileStoreWrite;
import org.dinky.shaded.paimon.table.sink.CommitMessage;
import org.dinky.shaded.paimon.table.sink.CommitMessageImpl;
import org.dinky.shaded.paimon.utils.Preconditions;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/** Compaction task generated by {@link AppendOnlyTableCompactionCoordinator}. */
public class AppendOnlyCompactionTask {

    private final BinaryRow partition;
    private final List compactBefore;
    private final List compactAfter;

    public AppendOnlyCompactionTask(BinaryRow partition, List files) {
        Preconditions.checkArgument(
                files != null && files.size() > 1,
                "AppendOnlyCompactionTask need more than one file input.");
        this.partition = partition;
        compactBefore = new ArrayList<>(files);
        compactAfter = new ArrayList<>();
    }

    public BinaryRow partition() {
        return partition;
    }

    public List compactBefore() {
        return compactBefore;
    }

    public List compactAfter() {
        return compactAfter;
    }

    public CommitMessage doCompact(AppendOnlyFileStoreWrite write) throws Exception {
        compactAfter.addAll(write.compactRewriter(partition, 0).rewrite(compactBefore));
        CompactIncrement compactIncrement =
                new CompactIncrement(compactBefore, compactAfter, Collections.emptyList());
        return new CommitMessageImpl(
                partition,
                0, // bucket 0 is bucket for unaware-bucket table for compatibility with the old
                // design
                NewFilesIncrement.emptyIncrement(),
                compactIncrement);
    }

    public int hashCode() {
        return Objects.hash(partition, compactBefore, compactAfter);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        AppendOnlyCompactionTask that = (AppendOnlyCompactionTask) o;
        return Objects.equals(partition, that.partition)
                && Objects.equals(compactBefore, that.compactBefore)
                && Objects.equals(compactAfter, that.compactAfter);
    }

    @Override
    public String toString() {
        return String.format(
                "CompactionTask {"
                        + "partition = %s, "
                        + "compactBefore = %s, "
                        + "compactAfter = %s}",
                partition, compactBefore, compactAfter);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy