deniskuzZ commented on code in PR #5393: URL: https://github.com/apache/hive/pull/5393#discussion_r1740009558
########## iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergStorageHandler.java: ########## @@ -2095,6 +2097,55 @@ public List<Partition> getPartitionsByExpr(org.apache.hadoop.hive.ql.metadata.Ta } } + @Override + public List<Partition> getPartitionsWithFilter(org.apache.hadoop.hive.ql.metadata.Table hmsTable, + ExprNodeDesc filter, boolean currentSpec) { + SearchArgument sarg = ConvertAstToSearchArg.create(conf, (ExprNodeGenericFuncDesc) filter); + Expression exp = HiveIcebergFilterFactory.generateFilterExpression(sarg); + Table table = IcebergTableUtil.getTable(conf, hmsTable.getTTable()); + int tableSpecId = table.spec().specId(); + List<Partition> partitions = Lists.newArrayList(); + + TableScan scan = table.newScan().filter(exp).caseSensitive(false).includeColumnStats().ignoreResiduals(); + + try (CloseableIterable<FileScanTask> tasks = scan.planFiles()) { + tasks.forEach(task -> { + DataFile file = task.file(); + PartitionSpec spec = task.spec(); + if ((currentSpec && file.specId() == tableSpecId) || (!currentSpec && file.specId() != tableSpecId)) { + PartitionData partitionData = IcebergTableUtil.toPartitionData(task.partition(), spec.partitionType()); + String partName = spec.partitionToPath(partitionData); + Map<String, String> partSpecMap = Maps.newLinkedHashMap(); + Warehouse.makeSpecFromName(partSpecMap, new Path(partName), null); + DummyPartition partition = new DummyPartition(hmsTable, partName, partSpecMap); + if (!partitions.contains(partition)) { + partitions.add(partition); + } + } + }); + } catch (IOException ioe) { + LOG.warn("Failed to close task iterable", ioe); + } + partitions.sort(Comparator.comparing(Partition::getName)); + return partitions; + } + + @Override + public boolean isFilterMatching(org.apache.hadoop.hive.ql.metadata.Table hmsTable, ExprNodeDesc filter) { Review Comment: Can this be moved into some util class instead of StorageHandler interface? -- 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: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org For additional commands, e-mail: gitbox-h...@hive.apache.org