Skip to content

Commit 9f09f32

Browse files
AndyCrossazurecoder
authored andcommitted
Parq full (tensorflow#90)
* tensorflow#89 Remove fold/sheet limits so a full dataset can be output, albeit still limited by DisplayMinWidth/column concatenation at header width * Update Readme with arguments
1 parent 17c2a7f commit 9f09f32

File tree

5 files changed

+112
-3
lines changed

5 files changed

+112
-3
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,14 @@ using(Stream fileStream = File.OpenWrite("c:\\test.parquet"))
8686

8787
This tools gives a simple data inspector which lists out the columns found in a Parquet data set and the data values for those columns.
8888

89-
To use, run ```dotnet parq.dll InputFilePath=path/to/file.parquet DisplayMinWidth=10```
89+
To use, run ```dotnet parq.dll Mode=interactive InputFilePath=path/to/file.parquet DisplayMinWidth=10```
90+
91+
Arguments include:
92+
* Mode (defaults to Interactive)
93+
* Interactive - breaks the dataset row-wise into folds and column-wise into sheets. Use the keyboard arrows to navigate the dataset
94+
* Full - displays all rows and columns of the dataset with no pause for user input. Limits the cell contents to the width of the header
95+
* InputFilePath - path to the input parquet file
96+
* DisplayMinWidth - as noted earlier, the interactive and full mode both display column contents up to the width of the header as we don't currently enumerate cell contents before beginning to draw. Setting DisplayMinWidth allows for long cell contents to be display.
9097

9198
![Parq](doc/img/parq.png)
9299

src/parq/AppSettings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ class AppSettings : SettingsContainer
1111

1212
public readonly Option<int> DisplayMinWidth = new Option<int>(10);
1313

14+
public readonly Option<string> Mode = new Option<string>("interactive");
15+
1416
//singleton
1517
private static AppSettings instance;
1618
public static AppSettings Instance => instance ?? (instance = new AppSettings());
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
using parq.Display.Models;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
6+
namespace parq.Display.Views
7+
{
8+
/// <summary>
9+
/// Displays to the Console window a navigatable (2D) data set
10+
/// </summary>
11+
public class FullConsoleView
12+
{
13+
private const string verticalSeparator = "|";
14+
private const string horizontalSeparator = "-";
15+
16+
public void Draw(ViewModel viewModel)
17+
{
18+
Console.Clear();
19+
20+
DrawSheet(viewModel);
21+
22+
}
23+
24+
private void DrawSheet(ViewModel viewModel)
25+
{
26+
Console.Clear();
27+
DrawLine(viewModel.Columns);
28+
WriteHeaderLine(viewModel.Columns);
29+
DrawLine(viewModel.Columns);
30+
WriteValues(viewModel);
31+
DrawLine(viewModel.Columns);
32+
WriteSummary(viewModel);
33+
34+
}
35+
36+
private void WriteSummary(ViewModel viewModel)
37+
{
38+
Console.WriteLine("Showing {0} Columns with {1} Rows.", viewModel.Columns.Count(), viewModel.RowCount);
39+
}
40+
private void WriteHeaderLine(IEnumerable<ColumnDetails> columnDetails)
41+
{
42+
Console.Write(verticalSeparator);
43+
foreach (string name in columnDetails.Select(cd => cd.columnName))
44+
{
45+
if (name.Length < AppSettings.Instance.DisplayMinWidth.Value)
46+
{
47+
for (int i = 0; i < AppSettings.Instance.DisplayMinWidth.Value - name.Length; i++)
48+
{
49+
Console.Write(" ");
50+
}
51+
}
52+
Console.Write(name);
53+
Console.Write(verticalSeparator);
54+
}
55+
Console.Write(Environment.NewLine);
56+
}
57+
58+
private void WriteValues(ViewModel viewModel)
59+
{
60+
for (int i = 0; i < viewModel.Rows.Count(); i++)
61+
{
62+
var row = viewModel.Rows.ElementAt(i);
63+
Console.Write(verticalSeparator);
64+
for (int j = 0; j < row.Length; j++)
65+
{
66+
var header = viewModel.Columns.ElementAt(j);
67+
68+
Console.Write(header.GetFormattedValue(row[j]));
69+
Console.Write(verticalSeparator);
70+
}
71+
Console.WriteLine();
72+
}
73+
}
74+
private void DrawLine(IEnumerable<ColumnDetails> columns)
75+
{
76+
Console.Write(verticalSeparator);
77+
foreach (int item in columns.Select(d => d.columnWidth))
78+
{
79+
for (int i = 0; i < item; i++)
80+
{
81+
Console.Write(horizontalSeparator);
82+
}
83+
Console.Write(verticalSeparator);
84+
}
85+
Console.Write(Environment.NewLine);
86+
}
87+
}
88+
}

src/parq/Display/Views/ConsoleView.cs renamed to src/parq/Display/Views/InteractiveConsoleView.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace parq.Display.Views
88
/// <summary>
99
/// Displays to the Console window a navigatable (2D) data set
1010
/// </summary>
11-
public class ConsoleView
11+
public class InteractiveConsoleView
1212
{
1313
private const string verticalSeparator = "|";
1414
private const string horizontalSeparator = "-";

src/parq/Program.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,19 @@ static void Main(string[] args)
4646
// After reading the column types give a printed list of the layout of the columns
4747
var display = new DisplayController();
4848
var viewModel = display.Get(dataSet);
49-
new ConsoleView().Draw(viewModel);
49+
50+
if (string.Compare(AppSettings.Instance.Mode, "interactive", true) == 0)
51+
{
52+
new InteractiveConsoleView().Draw(viewModel);
53+
}
54+
else if (string.Compare(AppSettings.Instance.Mode, "full", true) == 0)
55+
{
56+
new FullConsoleView().Draw(viewModel);
57+
}
58+
else if (string.Compare(AppSettings.Instance.Mode, "schema", true) == 0)
59+
{
60+
61+
}
5062

5163
}
5264
}

0 commit comments

Comments
 (0)