-
Notifications
You must be signed in to change notification settings - Fork 990
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[core] support file index filter push down
- Loading branch information
1 parent
7400979
commit 7766f69
Showing
38 changed files
with
1,102 additions
and
11 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
...on/src/main/java/org/apache/paimon/fileindex/FileIndexFilterFallbackPredicateVisitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* 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.paimon.fileindex; | ||
|
||
import org.apache.paimon.predicate.CompoundPredicate; | ||
import org.apache.paimon.predicate.FieldRef; | ||
import org.apache.paimon.predicate.LeafPredicate; | ||
import org.apache.paimon.predicate.Predicate; | ||
import org.apache.paimon.predicate.PredicateVisitor; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
|
||
/** Visit the predicate and extract the file index fallback predicate. */ | ||
public class FileIndexFilterFallbackPredicateVisitor | ||
implements PredicateVisitor<Optional<Predicate>> { | ||
|
||
private final Set<FieldRef> fields; | ||
|
||
public FileIndexFilterFallbackPredicateVisitor(Set<FieldRef> fields) { | ||
this.fields = fields; | ||
} | ||
|
||
@Override | ||
public Optional<Predicate> visit(LeafPredicate predicate) { | ||
if (fields.contains(predicate.fieldRef())) { | ||
return Optional.empty(); | ||
} | ||
return Optional.of(predicate); | ||
} | ||
|
||
@Override | ||
public Optional<Predicate> visit(CompoundPredicate predicate) { | ||
List<Predicate> converted = new ArrayList<>(); | ||
for (Predicate child : predicate.children()) { | ||
child.visit(this).ifPresent(converted::add); | ||
} | ||
if (converted.isEmpty()) { | ||
return Optional.empty(); | ||
} | ||
if (converted.size() == 1) { | ||
return Optional.of(converted.get(0)); | ||
} | ||
return Optional.of(new CompoundPredicate(predicate.function(), converted)); | ||
} | ||
} |
103 changes: 103 additions & 0 deletions
103
paimon-common/src/main/java/org/apache/paimon/fileindex/FileIndexFilterPushDownAnalyzer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* 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.paimon.fileindex; | ||
|
||
import org.apache.paimon.predicate.FieldRef; | ||
import org.apache.paimon.predicate.FunctionVisitor; | ||
|
||
import java.util.List; | ||
|
||
/** Visit the predicate and check if file index can be filter push down. */ | ||
public abstract class FileIndexFilterPushDownAnalyzer implements FunctionVisitor<Boolean> { | ||
|
||
@Override | ||
public Boolean visitIsNotNull(FieldRef fieldRef) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public Boolean visitIsNull(FieldRef fieldRef) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public Boolean visitStartsWith(FieldRef fieldRef, Object literal) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public Boolean visitEndsWith(FieldRef fieldRef, Object literal) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public Boolean visitContains(FieldRef fieldRef, Object literal) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public Boolean visitLessThan(FieldRef fieldRef, Object literal) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public Boolean visitGreaterOrEqual(FieldRef fieldRef, Object literal) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public Boolean visitNotEqual(FieldRef fieldRef, Object literal) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public Boolean visitLessOrEqual(FieldRef fieldRef, Object literal) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public Boolean visitEqual(FieldRef fieldRef, Object literal) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public Boolean visitGreaterThan(FieldRef fieldRef, Object literal) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public Boolean visitIn(FieldRef fieldRef, List<Object> literals) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public Boolean visitNotIn(FieldRef fieldRef, List<Object> literals) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public Boolean visitAnd(List<Boolean> children) { | ||
throw new UnsupportedOperationException("Should not invoke this"); | ||
} | ||
|
||
@Override | ||
public Boolean visitOr(List<Boolean> children) { | ||
throw new UnsupportedOperationException("Should not invoke this"); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
paimon-common/src/main/java/org/apache/paimon/fileindex/FileIndexFilterPushDownVisitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* 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.paimon.fileindex; | ||
|
||
import org.apache.paimon.annotation.VisibleForTesting; | ||
import org.apache.paimon.predicate.CompoundPredicate; | ||
import org.apache.paimon.predicate.LeafPredicate; | ||
import org.apache.paimon.predicate.Predicate; | ||
import org.apache.paimon.predicate.PredicateVisitor; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** Visit the predicate and check if index can push down the predicate. */ | ||
public class FileIndexFilterPushDownVisitor implements PredicateVisitor<Boolean> { | ||
|
||
private final Map<String, List<FileIndexFilterPushDownAnalyzer>> analyzers; | ||
|
||
public FileIndexFilterPushDownVisitor() { | ||
this(Collections.emptyMap()); | ||
} | ||
|
||
public FileIndexFilterPushDownVisitor( | ||
Map<String, List<FileIndexFilterPushDownAnalyzer>> analyzers) { | ||
this.analyzers = analyzers; | ||
} | ||
|
||
@Override | ||
public Boolean visit(LeafPredicate predicate) { | ||
List<FileIndexFilterPushDownAnalyzer> analyzers = | ||
this.analyzers.getOrDefault(predicate.fieldName(), Collections.emptyList()); | ||
for (FileIndexFilterPushDownAnalyzer analyzer : analyzers) { | ||
if (analyzer.visit(predicate)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public Boolean visit(CompoundPredicate predicate) { | ||
for (Predicate child : predicate.children()) { | ||
Boolean matched = child.visit(this); | ||
if (!matched) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
@VisibleForTesting | ||
public Map<String, List<FileIndexFilterPushDownAnalyzer>> getAnalyzers() { | ||
return analyzers; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.