luoyuxia commented on code in PR #1523: URL: https://github.com/apache/fluss/pull/1523#discussion_r2268390301
########## fluss-lake/fluss-lake-paimon/src/main/java/com/alibaba/fluss/lake/paimon/utils/PredicateConverter.java: ########## @@ -0,0 +1,165 @@ +/* + * Copyright (c) 2025 Alibaba Group Holding Ltd. + * + * Licensed 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 com.alibaba.fluss.lake.paimon.utils; + +import com.alibaba.fluss.predicate.And; +import com.alibaba.fluss.predicate.CompoundPredicate; +import com.alibaba.fluss.predicate.FieldRef; +import com.alibaba.fluss.predicate.FunctionVisitor; +import com.alibaba.fluss.predicate.LeafPredicate; +import com.alibaba.fluss.predicate.Or; +import com.alibaba.fluss.predicate.PredicateVisitor; + +import org.apache.paimon.predicate.Predicate; +import org.apache.paimon.predicate.PredicateBuilder; +import org.apache.paimon.types.RowType; + +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + +/** + * Converts a Fluss {@link com.alibaba.fluss.predicate.Predicate} into a Paimon {@link Predicate}. + * + * <p>This class implements the {@link PredicateVisitor} pattern to traverse a tree of Fluss + * predicates. It handles both leaf-level conditions (like equals, greater than) and compound + * conditions (AND, OR). + */ +public class PredicateConverter implements PredicateVisitor<Predicate> { + + private final PredicateBuilder builder; + private final LeafFunctionConverter converter = new LeafFunctionConverter(); + + public PredicateConverter(RowType rowType) { + this.builder = new PredicateBuilder(rowType); + } + + public static Optional<Predicate> convert( + RowType rowType, com.alibaba.fluss.predicate.Predicate flussPredicate) { + try { + return Optional.of(flussPredicate.visit(new PredicateConverter(rowType))); Review Comment: I think it's fine to create new PredicateConverter every time since actaully it'll only be called once and it helps us to init `PredicateConverter` lazily since when filter push down is not called, we don't need to create `PredicateConverter`. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
