SourabhBadhya commented on code in PR #4785: URL: https://github.com/apache/hive/pull/4785#discussion_r1381670567
########## iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergStorageHandler.java: ########## @@ -1932,4 +1938,49 @@ public boolean canPerformMetadataDelete(org.apache.hadoop.hive.ql.metadata.Table return false; } } + + @Override + public List<FieldSchema> getPartitionKeys(org.apache.hadoop.hive.ql.metadata.Table hmsTable) { + Table icebergTable = IcebergTableUtil.getTable(conf, hmsTable.getTTable()); + Schema schema = icebergTable.schema(); + List<FieldSchema> hiveSchema = HiveSchemaUtil.convert(schema); + Map<String, String> colNameToColType = hiveSchema.stream() + .collect(Collectors.toMap(FieldSchema::getName, FieldSchema::getType)); + return icebergTable.spec().fields().stream().map(partField -> + new FieldSchema(schema.findColumnName(partField.sourceId()), + colNameToColType.get(schema.findColumnName(partField.sourceId())), + String.format("Transform: %s", partField.transform().toString()))).collect(Collectors.toList()); + } + + @Override + public List<Partition> getPartitionsByExpr(org.apache.hadoop.hive.ql.metadata.Table hmsTable, ExprNodeDesc desc) + throws SemanticException { + Table icebergTable = IcebergTableUtil.getTable(conf, hmsTable.getTTable()); + PartitionSpec pSpec = icebergTable.spec(); + PartitionsTable partitionsTable = (PartitionsTable) MetadataTableUtils + .createMetadataTableInstance(icebergTable, MetadataTableType.PARTITIONS); + SearchArgument sarg = ConvertAstToSearchArg.create(conf, (ExprNodeGenericFuncDesc) desc); + Expression expression = HiveIcebergFilterFactory.generateFilterExpression(sarg); + Set<PartitionData> partitionList = Sets.newHashSet(); + try (CloseableIterable<FileScanTask> fileScanTasks = partitionsTable.newScan().planFiles()) { + fileScanTasks.forEach(task -> + partitionList.addAll(Sets.newHashSet(CloseableIterable.transform(task.asDataTask().rows(), row -> { + StructProjection data = row.get(PART_IDX, StructProjection.class); + PartitionData partitionData = IcebergTableUtil.toPartitionData(data, pSpec.partitionType()); + ResidualEvaluator resEval = ResidualEvaluator.of(pSpec, expression, false); + if (resEval.residualFor(partitionData).isEquivalentTo(Expressions.alwaysTrue())) { + return partitionData; + } else { Review Comment: Done ########## iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergMetaHook.java: ########## @@ -997,6 +1012,66 @@ public void postGetTable(org.apache.hadoop.hive.metastore.api.Table hmsTable) { } } + @Override + public void preDropPartitions(org.apache.hadoop.hive.metastore.api.Table hmsTable, + EnvironmentContext context, + List<org.apache.commons.lang3.tuple.Pair<Integer, byte[]>> partExprs) + throws MetaException { + Table icebergTbl = IcebergTableUtil.getTable(conf, hmsTable); + DeleteFiles deleteFiles = icebergTbl.newDelete(); + List<Expression> expressions = partExprs.stream().map(partExpr -> { + ExprNodeDesc exprNodeDesc = SerializationUtilities + .deserializeObjectWithTypeInformation(partExpr.getRight(), true); + SearchArgument sarg = ConvertAstToSearchArg.create(conf, (ExprNodeGenericFuncDesc) exprNodeDesc); + return HiveIcebergFilterFactory.generateFilterExpression(sarg); + }).collect(Collectors.toList()); + PartitionsTable partitionsTable = (PartitionsTable) MetadataTableUtils + .createMetadataTableInstance(icebergTbl, MetadataTableType.PARTITIONS); + List<PartitionData> partitionList = Lists.newArrayList(); + Expression finalExp = Expressions.alwaysFalse(); + PartitionSpec pSpec = icebergTbl.spec(); + for (int index = 0; index < expressions.size(); index++) { + finalExp = Expressions.or(finalExp, expressions.get(index)); + } + try (CloseableIterable<FileScanTask> fileScanTasks = partitionsTable.newScan().planFiles()) { + fileScanTasks.forEach(task -> + partitionList.addAll(Sets.newHashSet(CloseableIterable.transform(task.asDataTask().rows(), row -> { + StructProjection data = row.get(0, StructProjection.class); + PartitionData partitionData = IcebergTableUtil.toPartitionData(data, pSpec.partitionType()); + boolean required = false; + for (Expression expr : expressions) { + ResidualEvaluator resEval = ResidualEvaluator.of(icebergTbl.spec(), expr, false); + if (resEval.residualFor(partitionData).isEquivalentTo(Expressions.alwaysTrue())) { + required = true; Review Comment: Done -- 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