saihemanth-cloudera commented on code in PR #5523: URL: https://github.com/apache/hive/pull/5523#discussion_r1847097987
########## iceberg/iceberg-handler/src/main/java/org/apache/iceberg/metasummary/MetadataSummary.java: ########## @@ -0,0 +1,155 @@ +/* + * 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.iceberg.metasummary; + +import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; +import org.apache.commons.collections4.IteratorUtils; +import org.apache.hadoop.hive.metastore.metasummary.MetadataTableSummary; +import org.apache.hadoop.hive.metastore.metasummary.SummaryMapBuilder; +import org.apache.iceberg.FileScanTask; +import org.apache.iceberg.ManifestFile; +import org.apache.iceberg.MetadataTableType; +import org.apache.iceberg.MetadataTableUtils; +import org.apache.iceberg.PartitionsTable; +import org.apache.iceberg.ScanTask; +import org.apache.iceberg.SnapshotRef; +import org.apache.iceberg.SnapshotSummary; +import org.apache.iceberg.Table; +import org.apache.iceberg.io.CloseableIterable; +import org.apache.iceberg.relocated.com.google.common.collect.Lists; +import org.apache.iceberg.types.Types; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static org.apache.iceberg.TableProperties.SNAPSHOT_COUNT; + +/** + * Collect the metadata summary for the table, like the number of snapshots, data files + * or the partition count. + */ +public class MetadataSummary extends IcebergSummaryRetriever { + private static final Logger LOG = LoggerFactory.getLogger(MetadataSummary.class); + public static final String SNAPSHOT_MAX_AGE = "snapshotMaxAge"; + public static final String SNAPSHOT_MIN_KEEP = "snapshotMinKeep"; + public static final String NUM_SNAPSHOTS = "numSnapshots"; + public static final String NUM_MANIFESTS = "numManifests"; + public static final String NUM_METADATA_FILES = "numMetadataFiles"; + public static final String MANIFESTS_SIZE = "manifestsSize"; + public static final String NUM_BRANCHES = "numBranches"; + public static final String NUM_TAGS = "numTags"; + + @Override + public List<String> getFieldNames() { + if (formatJson) { + return Collections.singletonList("metadata"); + } + return Arrays.asList(NUM_SNAPSHOTS, NUM_METADATA_FILES, NUM_MANIFESTS, + MANIFESTS_SIZE, SNAPSHOT_MAX_AGE, SNAPSHOT_MIN_KEEP, NUM_BRANCHES, NUM_TAGS); + } + + @Override + public void getMetaSummary(Table table, MetadataTableSummary metaSummary) { + basicMetadataSummary(table, metaSummary); + SummaryMapBuilder builder = new SummaryMapBuilder(); + Table metadataEntries = MetadataTableUtils + .createMetadataTableInstance(table, MetadataTableType.METADATA_LOG_ENTRIES); + try (CloseableIterable<ScanTask> iterable = metadataEntries.newBatchScan().planFiles()) { + List<?> files = Lists.newArrayList(CloseableIterable.transform(iterable, + t -> ((FileScanTask) t).file())); + builder.add(NUM_METADATA_FILES, files.size()); + } catch (IOException e) { + LOG.warn("Error while listing the metadata files, table: " + table.name(), e); + builder.add(NUM_METADATA_FILES, 1); Review Comment: Why are we adding 1 file count in case of error? Instead, should we log the error, and proceed with reading other files? -- 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