Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
impala::TablePrinter Class Reference

#include <table-printer.h>

Collaboration diagram for impala::TablePrinter:

Public Member Functions

 TablePrinter ()
 
void AddColumn (const std::string &label, bool left_align)
 
void set_max_output_width (int width)
 
void AddRow (const std::vector< std::string > &row)
 Add a row to the table. This must have the same width as labels. More...
 
std::string ToString (const std::string &prefix="") const
 Print to a table with prefix coming before the output. More...
 

Private Member Functions

void PrintRow (std::stringstream *ss, const std::vector< std::string > &row, const std::vector< int > &widths) const
 Helper function to print one row to ss. More...
 

Private Attributes

std::vector< std::string > labels_
 
std::vector< boolleft_align_
 For each column, true if the value should be left aligned, right aligned otherwise. More...
 
int max_output_width_
 -1 to indicate unlimited. More...
 
std::vector< std::vector
< std::string > > 
rows_
 
std::vector< int > max_col_widths_
 

Detailed Description

Utility class to pretty print tables. Rows can be added and at the end printed with fixed with spacing.

Definition at line 27 of file table-printer.h.

Constructor & Destructor Documentation

TablePrinter::TablePrinter ( )

Definition at line 28 of file table-printer.cc.

Member Function Documentation

void TablePrinter::AddColumn ( const std::string &  label,
bool  left_align 
)

Add a column to the table. All calls to AddColumn() must come before any calls to AddRow().

Definition at line 31 of file table-printer.cc.

References labels_, left_align_, and max_col_widths_.

Referenced by impala::PrintExecSummary().

void TablePrinter::AddRow ( const std::vector< std::string > &  row)

Add a row to the table. This must have the same width as labels.

Definition at line 42 of file table-printer.cc.

References labels_, max_col_widths_, and rows_.

Referenced by impala::PrintExecSummary().

void TablePrinter::PrintRow ( std::stringstream *  ss,
const std::vector< std::string > &  row,
const std::vector< int > &  widths 
) const
private

Helper function to print one row to ss.

Definition at line 50 of file table-printer.cc.

References COLUMN_PAD, labels_, and left_align_.

Referenced by ToString().

void TablePrinter::set_max_output_width ( int  width)

Sets the max per column output width (otherwise, columns will be as wide as the largest value). Values longer than this will be cut off.

Definition at line 37 of file table-printer.cc.

References max_output_width_.

Referenced by impala::PrintExecSummary().

string TablePrinter::ToString ( const std::string &  prefix = "") const

Print to a table with prefix coming before the output.

Definition at line 73 of file table-printer.cc.

References COLUMN_PAD, labels_, max_col_widths_, max_output_width_, PrintRow(), and rows_.

Referenced by impala::PrintExecSummary().

Member Data Documentation

std::vector<std::string> impala::TablePrinter::labels_
private

Definition at line 46 of file table-printer.h.

Referenced by AddColumn(), AddRow(), PrintRow(), and ToString().

std::vector<bool> impala::TablePrinter::left_align_
private

For each column, true if the value should be left aligned, right aligned otherwise.

Definition at line 48 of file table-printer.h.

Referenced by AddColumn(), and PrintRow().

std::vector<int> impala::TablePrinter::max_col_widths_
private

Definition at line 54 of file table-printer.h.

Referenced by AddColumn(), AddRow(), and ToString().

int impala::TablePrinter::max_output_width_
private

-1 to indicate unlimited.

Definition at line 51 of file table-printer.h.

Referenced by set_max_output_width(), and ToString().

std::vector<std::vector<std::string> > impala::TablePrinter::rows_
private

Definition at line 53 of file table-printer.h.

Referenced by AddRow(), and ToString().


The documentation for this class was generated from the following files: