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

org.dinky.shaded.paimon.predicate.CompoundPredicate 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.predicate;

import org.dinky.shaded.paimon.data.InternalRow;
import org.dinky.shaded.paimon.format.FieldStats;

import java.io.Serializable;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

/**
 * Non-leaf node in a {@link Predicate} tree. Its evaluation result depends on the results of its
 * children.
 */
public class CompoundPredicate implements Predicate {

    private final Function function;
    private final List children;

    public CompoundPredicate(Function function, List children) {
        this.function = function;
        this.children = children;
    }

    public Function function() {
        return function;
    }

    public List children() {
        return children;
    }

    @Override
    public boolean test(Object[] values) {
        return function.test(values, children);
    }

    @Override
    public boolean test(InternalRow row) {
        return function.test(row, children);
    }

    @Override
    public boolean test(long rowCount, FieldStats[] fieldStats) {
        return function.test(rowCount, fieldStats, children);
    }

    @Override
    public Optional negate() {
        return function.negate(children);
    }

    @Override
    public  T visit(PredicateVisitor visitor) {
        return visitor.visit(this);
    }

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof CompoundPredicate)) {
            return false;
        }
        CompoundPredicate that = (CompoundPredicate) o;
        return Objects.equals(function, that.function) && Objects.equals(children, that.children);
    }

    /** Evaluate the predicate result based on multiple {@link Predicate}s. */
    public abstract static class Function implements Serializable {

        public abstract boolean test(Object[] values, List children);

        public abstract boolean test(InternalRow row, List children);

        public abstract boolean test(
                long rowCount, FieldStats[] fieldStats, List children);

        public abstract Optional negate(List children);

        public abstract  T visit(FunctionVisitor visitor, List children);

        @Override
        public int hashCode() {
            return this.getClass().getName().hashCode();
        }

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




© 2015 - 2025 Weber Informatics LLC | Privacy Policy