/** * Returns statistics on this table as a tabular result set. Used for the SHOW TABLE STATS * statement. The schema of the returned TResultSet is set inside this method. */ public TResultSet getTableStats() { TResultSet result = new TResultSet(); TResultSetMetadata resultSchema = new TResultSetMetadata(); result.setSchema(resultSchema); for (int i = 0; i < numClusteringCols_; ++i) { // Add the partition-key values as strings for simplicity. Column partCol = colsByPos_.get(i); TColumn colDesc = new TColumn(partCol.getName(), partCol.getType().toThrift()); resultSchema.addToColumns(colDesc); } resultSchema.addToColumns(new TColumn("#Rows", ColumnType.BIGINT.toThrift())); resultSchema.addToColumns(new TColumn("#Files", ColumnType.BIGINT.toThrift())); resultSchema.addToColumns(new TColumn("Size", ColumnType.STRING.toThrift())); resultSchema.addToColumns(new TColumn("Format", ColumnType.STRING.toThrift())); // Pretty print partitions and their stats. ArrayList<HdfsPartition> orderedPartitions = Lists.newArrayList(partitions_); Collections.sort(orderedPartitions); for (HdfsPartition p : orderedPartitions) { // Ignore dummy default partition. if (p.getId() == ImpalaInternalServiceConstants.DEFAULT_PARTITION_ID) continue; TResultRowBuilder rowBuilder = new TResultRowBuilder(); // Add the partition-key values (as strings for simplicity). for (LiteralExpr expr : p.getPartitionValues()) { rowBuilder.add(expr.getStringValue()); } // Add number of rows, files, bytes and the file format. rowBuilder .add(p.getNumRows()) .add(p.getFileDescriptors().size()) .addBytes(p.getSize()) .add(p.getInputFormatDescriptor().getFileFormat().toString()); result.addToRows(rowBuilder.get()); } // For partitioned tables add a summary row at the bottom. if (numClusteringCols_ > 0) { TResultRowBuilder rowBuilder = new TResultRowBuilder(); int numEmptyCells = numClusteringCols_ - 1; rowBuilder.add("Total"); for (int i = 0; i < numEmptyCells; ++i) { rowBuilder.add(""); } // Total num rows, files, and bytes (leave format empty). rowBuilder.add(numRows_).add(numHdfsFiles_).addBytes(totalHdfsBytes_).add(""); result.addToRows(rowBuilder.get()); } return result; }