MCPcopy Create free account
hub / github.com/apache/pig / DisplayTable

Method DisplayTable

src/org/apache/pig/pen/util/DisplayExamples.java:194–258  ·  view source on GitHub ↗
(String[][] table, Operator op, DataBag bag,
            StringBuffer output)

Source from the content-addressed store, hash-verified

192 }
193
194 static void DisplayTable(String[][] table, Operator op, DataBag bag,
195 StringBuffer output) throws FrontendException {
196 if (op instanceof LOStore && ((LOStore) op).isTmpStore())
197 return;
198
199 int cols = ((LogicalRelationalOperator)op).getSchema().getFields().size();
200 List<LogicalSchema.LogicalFieldSchema> fields = ((LogicalRelationalOperator)op).getSchema().getFields();
201 int rows = (int) bag.size();
202 int[] maxColSizes = new int[cols];
203 for (int i = 0; i < cols; ++i) {
204 maxColSizes[i] = fields.get(i).toString().length();
205 if (maxColSizes[i] < 5)
206 maxColSizes[i] = 5;
207 }
208 int total = 0;
209 final String alias = ((LogicalRelationalOperator)op).getAlias();
210 int aliasLength = (op instanceof LOStore ? alias.length() + 12 : alias.length() + 4);
211 for (int j = 0; j < cols; ++j) {
212 for (int i = 0; i < rows; ++i) {
213 int length = table[i][j].length();
214 if (length > maxColSizes[j])
215 maxColSizes[j] = length;
216 }
217 total += maxColSizes[j];
218 }
219
220 // Note of limit reset
221 if (op instanceof LOLimit) {
222 output.append("\nThe limit now in use, " + ((LOLimit)op).getLimit() + ", may have been changed for ILLUSTRATE purpose.\n");
223 }
224
225 // Display the schema first
226 output
227 .append(AddSpaces(total + 3 * (cols + 1) + aliasLength + 1,
228 false)
229 + "\n");
230 if (op instanceof LOStore)
231 output.append("| Store : " + alias + AddSpaces(4, true) + " | ");
232 else
233 output.append("| " + alias + AddSpaces(4, true) + " | ");
234 for (int i = 0; i < cols; ++i) {
235 String field = fields.get(i).toString(false);
236 output.append(field
237 + AddSpaces(maxColSizes[i] - field.length(), true) + " | ");
238 }
239 output.append("\n"
240 + AddSpaces(total + 3 * (cols + 1) + aliasLength + 1, false)
241 + "\n");
242 // now start displaying the data
243 for (int i = 0; i < rows; ++i) {
244 output.append("| " + AddSpaces(aliasLength, true) + " | ");
245 for (int j = 0; j < cols; ++j) {
246 String str = table[i][j];
247 output.append(str
248 + AddSpaces(maxColSizes[j] - str.length(), true)
249 + " | ");
250 }
251 output.append("\n");

Callers 1

printTabularMethod · 0.95

Calls 11

AddSpacesMethod · 0.95
lengthMethod · 0.80
sizeMethod · 0.65
getSchemaMethod · 0.65
getMethod · 0.65
getAliasMethod · 0.65
appendMethod · 0.65
isTmpStoreMethod · 0.45
getFieldsMethod · 0.45
toStringMethod · 0.45
getLimitMethod · 0.45

Tested by

no test coverage detected