Skip to content

Commit 0512e52

Browse files
authored
Merge pull request #43 from mukunku/v2.3.3
v2.3.3
2 parents a67b1ff + 2ed5130 commit 0512e52

15 files changed

+512
-17
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ If you'd like to add any new features feel free to send a pull request.
1313
Some Key Features:
1414
* Run simple sql-like queries on chunks of the file
1515
* Generate ansi sql schema for opened files
16+
* View parquet file metadata
1617

1718
# Limitations
1819
This application can only open Parquet files located on the Windows machine the app is running on. It cannot connect to HDFS to read parquet data.

src/ParquetFileViewer/Helpers/ExtensionMethods.cs

+33-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
using System.Collections.Generic;
1+
using Newtonsoft.Json;
2+
using Newtonsoft.Json.Linq;
3+
using System;
4+
using System.Collections.Generic;
25
using System.Data;
3-
using System.Windows.Forms;
6+
using System.IO;
47

58
namespace ParquetFileViewer.Helpers
69
{
@@ -20,5 +23,33 @@ public static IList<string> GetColumnNames(this DataTable datatable)
2023
}
2124
return columns;
2225
}
26+
27+
public static string FormatJSON(this string input)
28+
{
29+
if (input == null)
30+
return null;
31+
32+
try
33+
{
34+
return JValue.Parse(input).ToString(Formatting.Indented);
35+
}
36+
catch (Exception)
37+
{
38+
//malformed json detected
39+
return input;
40+
}
41+
}
42+
43+
public static string Base64Encode(this string plainText)
44+
{
45+
var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText);
46+
return Convert.ToBase64String(plainTextBytes);
47+
}
48+
49+
public static string Base64Decode(this string base64EncodedData)
50+
{
51+
var base64EncodedBytes = Convert.FromBase64String(base64EncodedData);
52+
return System.Text.Encoding.UTF8.GetString(base64EncodedBytes);
53+
}
2354
}
2455
}

src/ParquetFileViewer/Helpers/UtilityMethods.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ private static void ProcessRowGroup(DataTable dataTable, ParquetRowGroupReader g
108108
else if (field.DataType == Parquet.Data.DataType.DateTimeOffset)
109109
dataTable.Rows[rowIndex][field.Name] = ((DateTimeOffset)value).DateTime;
110110
else if (field.DataType == Parquet.Data.DataType.Int64
111-
&& logicalType.TIMESTAMP != null)
111+
&& logicalType?.TIMESTAMP != null)
112112
{
113113
int divideBy = 0;
114114
if (logicalType.TIMESTAMP.Unit.NANOS != null)
@@ -168,7 +168,7 @@ public static Type ParquetNetTypeToCSharpType(Parquet.Thrift.SchemaElement thrif
168168
columnType = typeof(int);
169169
break;
170170
case Parquet.Data.DataType.Int64:
171-
columnType = thriftSchema.LogicalType.TIMESTAMP != null ? typeof(DateTime) : typeof(long);
171+
columnType = thriftSchema.LogicalType?.TIMESTAMP != null ? typeof(DateTime) : typeof(long);
172172
break;
173173
case Parquet.Data.DataType.UnsignedByte:
174174
columnType = typeof(byte);

src/ParquetFileViewer/MainForm.Designer.cs

+35-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ParquetFileViewer/MainForm.cs

+21
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ private string OpenFilePath
4444
this.openFilePath = value;
4545
this.changeFieldsMenuStripButton.Enabled = false;
4646
this.getSQLCreateTableScriptToolStripMenuItem.Enabled = false;
47+
this.saveAsToolStripMenuItem.Enabled = false;
48+
this.metadataViewerToolStripMenuItem.Enabled = false;
4749
this.recordCountStatusBarLabel.Text = "0";
4850
this.totalRowCountStatusBarLabel.Text = "0";
4951
this.MainDataSource.Clear();
@@ -57,7 +59,9 @@ private string OpenFilePath
5759
{
5860
this.Text = string.Concat("Open File: ", value);
5961
this.changeFieldsMenuStripButton.Enabled = true;
62+
this.saveAsToolStripMenuItem.Enabled = true;
6063
this.getSQLCreateTableScriptToolStripMenuItem.Enabled = true;
64+
this.metadataViewerToolStripMenuItem.Enabled = true;
6165
}
6266
}
6367
}
@@ -953,5 +957,22 @@ private void MultithreadedParquetEngineToolStripMenuItem_Click(object sender, Ev
953957
this.ShowError(ex);
954958
}
955959
}
960+
961+
private void MetadataViewerToolStripMenuItem_Click(object sender, EventArgs e)
962+
{
963+
try
964+
{
965+
using (Stream parquetStream = new FileStream(this.OpenFilePath, FileMode.Open, FileAccess.Read))
966+
using (var parquetReader = new ParquetReader(parquetStream, new ParquetOptions() { TreatByteArrayAsString = true }))
967+
using (var metadataViewer = new MetadataViewer(parquetReader))
968+
{
969+
metadataViewer.ShowDialog(this);
970+
}
971+
}
972+
catch(Exception ex)
973+
{
974+
this.ShowError(ex);
975+
}
976+
}
956977
}
957978
}

src/ParquetFileViewer/MainForm.resx

+15
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,21 @@
165165
r00Cgk/n38S7wBwC04u4UGxHrMHF4CbEJtyDLj5fCDIzhljfSxzeavRgyw4Zj9t64GvvQ0d3P3pfD2Kv
166166
2QqNvgFxDN6urYdWmyMElJMnevh60obRktA701PRtGlg1DOdSkXwzrisaMG/RZLWAE60OMW5fNhvAAAA
167167
AElFTkSuQmCC
168+
</value>
169+
</data>
170+
<data name="saveAsToolStripMenuItem.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
171+
<value>
172+
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO
173+
wwAADsMBx2+oZAAAAjJJREFUOE+tkt9Lk1EYx99/oftugi66rakxnIvV4C3XUJYNw4qwH2+kWZou00TF
174+
yjRq/oJshUsnrVaTcFKRP8AUKRFlKlmauaIlDjXFJoLB1/OcvXlcRRfRF56bl/fzOed5ziP9lzx/FgaV
175+
r3UJLd5FPHTPo6kxhLuOadTVfoH9VgDXyydRWjKOwoK3yMsdwflzfqi4JBHY1QnU1qzgb1leWYUptQuH
176+
Up/yUnFJ8j5Z4ILKim/qr7+H4ND8MnZZXkCjUWA96BEC94M5Ligt+ar+Hp2f8MfgAmLMPhRcmsIBS7MQ
177+
OBtmuOCi7YOKiGyEhydC2CZ7kZM9huQkpxDU3w5yQdbZERWL5Fe4zx/EZoMbijIAs9khBDXVn7lAOTWg
178+
on+GO/s/YVN8Iw4feYXExDohuFE5hY52sKcEjh1/A+vRXj5tGhj1TNemkyNwN1KsLyHLdiG4UjaBNh/Y
179+
DgDNrh/s3b+j/NosHyoNjHrOzPCvw/uTW2E0VgjB5cIxeB4B952rbHHCMKVlR5Ul3Ya0M0UROInB+zww
180+
GMqEwJY3ymCguirMTyaIfUaMTsbg+xmMTs5Cyb2KPaYWDut2u6DXFwkBraXjDtavTQKCT+ffxLvAHALT
181+
i7hQbEeswcXgJsQm3IMuPl8IMjOGWN9LHN5q9GDLDhmP23rga+9DR3c/el8PYq/ZCo2+AXEM3q6th1ab
182+
IwSUkyd6+HrShtGS0DvTU9G0aWDUM51KRfDOuKxowb9FktYATrQ4xbl82G8AAAAASUVORK5CYII=
168183
</value>
169184
</data>
170185
<metadata name="FileSchemaBackgroundWorker.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">

src/ParquetFileViewer/MetadataViewer.Designer.cs

+116
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)