|
27 | 27 | import org.apache.paimon.fs.FileIO; |
28 | 28 | import org.apache.paimon.io.DataFileMeta; |
29 | 29 | import org.apache.paimon.io.DataFilePathFactory; |
30 | | -import org.apache.paimon.predicate.Equal; |
31 | | -import org.apache.paimon.predicate.In; |
32 | | -import org.apache.paimon.predicate.LeafBinaryFunction; |
33 | 30 | import org.apache.paimon.predicate.LeafPredicate; |
34 | 31 | import org.apache.paimon.predicate.LeafPredicateExtractor; |
35 | 32 | import org.apache.paimon.predicate.Predicate; |
36 | | -import org.apache.paimon.predicate.PredicateBuilder; |
37 | 33 | import org.apache.paimon.reader.RecordReader; |
38 | 34 | import org.apache.paimon.schema.SchemaManager; |
39 | 35 | import org.apache.paimon.schema.TableSchema; |
|
52 | 48 | import org.apache.paimon.types.IntType; |
53 | 49 | import org.apache.paimon.types.RowType; |
54 | 50 | import org.apache.paimon.utils.IteratorRecordReader; |
| 51 | +import org.apache.paimon.utils.PartitionPredicateHelper; |
55 | 52 | import org.apache.paimon.utils.ProjectedRow; |
56 | 53 | import org.apache.paimon.utils.RowDataToObjectArrayConverter; |
57 | 54 | import org.apache.paimon.utils.SerializationUtils; |
58 | | -import org.apache.paimon.utils.TypeUtils; |
59 | 55 |
|
60 | 56 | import org.apache.paimon.shade.guava30.com.google.common.collect.Iterators; |
61 | 57 |
|
|
66 | 62 | import java.util.Collections; |
67 | 63 | import java.util.HashMap; |
68 | 64 | import java.util.Iterator; |
69 | | -import java.util.LinkedHashMap; |
70 | 65 | import java.util.List; |
71 | 66 | import java.util.Map; |
72 | 67 | import java.util.function.Function; |
@@ -171,89 +166,20 @@ public InnerTableScan withFilter(Predicate pushdown) { |
171 | 166 | @Override |
172 | 167 | public Plan innerPlan() { |
173 | 168 | SnapshotReader snapshotReader = fileStoreTable.newSnapshotReader(); |
174 | | - if (partitionPredicate != null) { |
175 | | - List<String> partitionKeys = fileStoreTable.partitionKeys(); |
176 | | - RowType partitionType = fileStoreTable.schema().logicalPartitionType(); |
177 | | - if (partitionPredicate.function() instanceof Equal) { |
178 | | - LinkedHashMap<String, String> partSpec = |
179 | | - parsePartitionSpec( |
180 | | - partitionPredicate.literals().get(0).toString(), partitionKeys); |
181 | | - if (partSpec == null) { |
182 | | - return Collections::emptyList; |
183 | | - } |
184 | | - snapshotReader.withPartitionFilter(partSpec); |
185 | | - } else if (partitionPredicate.function() instanceof In) { |
186 | | - List<Predicate> orPredicates = new ArrayList<>(); |
187 | | - PredicateBuilder partBuilder = new PredicateBuilder(partitionType); |
188 | | - for (Object literal : partitionPredicate.literals()) { |
189 | | - LinkedHashMap<String, String> partSpec = |
190 | | - parsePartitionSpec(literal.toString(), partitionKeys); |
191 | | - if (partSpec == null) { |
192 | | - continue; |
193 | | - } |
194 | | - List<Predicate> andPredicates = new ArrayList<>(); |
195 | | - for (int i = 0; i < partitionKeys.size(); i++) { |
196 | | - Object value = |
197 | | - TypeUtils.castFromString( |
198 | | - partSpec.get(partitionKeys.get(i)), |
199 | | - partitionType.getTypeAt(i)); |
200 | | - andPredicates.add(partBuilder.equal(i, value)); |
201 | | - } |
202 | | - orPredicates.add(PredicateBuilder.and(andPredicates)); |
203 | | - } |
204 | | - if (!orPredicates.isEmpty()) { |
205 | | - snapshotReader.withPartitionFilter(PredicateBuilder.or(orPredicates)); |
206 | | - } |
207 | | - } else if (partitionPredicate.function() instanceof LeafBinaryFunction) { |
208 | | - LinkedHashMap<String, String> partSpec = |
209 | | - parsePartitionSpec( |
210 | | - partitionPredicate.literals().get(0).toString(), partitionKeys); |
211 | | - if (partSpec != null) { |
212 | | - PredicateBuilder partBuilder = new PredicateBuilder(partitionType); |
213 | | - List<Predicate> predicates = new ArrayList<>(); |
214 | | - for (int i = 0; i < partitionKeys.size(); i++) { |
215 | | - Object value = |
216 | | - TypeUtils.castFromString( |
217 | | - partSpec.get(partitionKeys.get(i)), |
218 | | - partitionType.getTypeAt(i)); |
219 | | - predicates.add( |
220 | | - new LeafPredicate( |
221 | | - partitionPredicate.function(), |
222 | | - partitionType.getTypeAt(i), |
223 | | - i, |
224 | | - partitionKeys.get(i), |
225 | | - Collections.singletonList(value))); |
226 | | - } |
227 | | - snapshotReader.withPartitionFilter(PredicateBuilder.and(predicates)); |
228 | | - } |
229 | | - } |
| 169 | + List<String> partitionKeys = fileStoreTable.partitionKeys(); |
| 170 | + RowType partitionType = fileStoreTable.schema().logicalPartitionType(); |
| 171 | + boolean hasResults = |
| 172 | + PartitionPredicateHelper.applyPartitionFilter( |
| 173 | + snapshotReader, partitionPredicate, partitionKeys, partitionType); |
| 174 | + if (!hasResults) { |
| 175 | + return Collections::emptyList; |
230 | 176 | } |
231 | 177 |
|
232 | 178 | return () -> |
233 | 179 | snapshotReader.partitions().stream() |
234 | 180 | .map(p -> new FilesTable.FilesSplit(p, bucketPredicate, levelPredicate)) |
235 | 181 | .collect(Collectors.toList()); |
236 | 182 | } |
237 | | - |
238 | | - @Nullable |
239 | | - private LinkedHashMap<String, String> parsePartitionSpec( |
240 | | - String partitionStr, List<String> partitionKeys) { |
241 | | - if (partitionStr.startsWith("{")) { |
242 | | - partitionStr = partitionStr.substring(1); |
243 | | - } |
244 | | - if (partitionStr.endsWith("}")) { |
245 | | - partitionStr = partitionStr.substring(0, partitionStr.length() - 1); |
246 | | - } |
247 | | - String[] partFields = partitionStr.split(", "); |
248 | | - if (partitionKeys.size() != partFields.length) { |
249 | | - return null; |
250 | | - } |
251 | | - LinkedHashMap<String, String> partSpec = new LinkedHashMap<>(); |
252 | | - for (int i = 0; i < partitionKeys.size(); i++) { |
253 | | - partSpec.put(partitionKeys.get(i), partFields[i]); |
254 | | - } |
255 | | - return partSpec; |
256 | | - } |
257 | 183 | } |
258 | 184 |
|
259 | 185 | private static class FileKeyRangesRead implements InnerTableRead { |
|
0 commit comments