Skip to content

Commit d20fb94

Browse files
committed
use @dvirtz/parquets
Fixes llvm#19
1 parent 31e5d2c commit d20fb94

12 files changed

+248
-53
lines changed

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
Views [Apache Parquet](https://parquet.apache.org/) files as JSON.
66

7-
Requires [parquet-tools](https://mvnrepository.com/artifact/org.apache.parquet/parquet-tools).
8-
97
## Features
108

119
When opening a Parquet file, a JSON presentation of the file will open automatically:
@@ -18,8 +16,10 @@ After closing the JSON view, it is possible to reopen it by clicking on the link
1816

1917
## Requirements
2018

21-
The extension requires [parquet-tools](https://github.com/apache/parquet-mr/tree/master/parquet-tools-deprecated).
22-
It should be in your PATH, or a path can be set in settings.
19+
The extension used to require [parquet-tools](https://mvnrepository.com/artifact/org.apache.parquet/parquet-tools).
20+
Now the extension uses the [parquets](https://github.com/dvirtz/parquets) TypeScript library to do parse the files.
21+
22+
If you still want to use `parquet-tools`, you should set `parquet-viewer.useParquetTools` to `true` and `paruqet-tools` should be in your `PATH`, or pointed by the `parquet-viewer.parquetToolsPath` setting.
2323

2424
![settings](images/settings.png)
2525

@@ -29,10 +29,11 @@ The following setting options are available:
2929

3030
|name|default|description|
3131
|----|-------|-----------|
32-
|`parquet-viewer.parquetToolsPath`|`parquet-tools`| the name of the parquet-tools executable or a path to the parquet-tools jar|
33-
|`parquet-viewer.logPanel`|`false`|whether to write diagnostic logs to an output panel|
32+
|`parquet-viewer.parquetToolsPath`|`parquet-tools`|The name of the parquet-tools executable or a path to the parquet-tools jar|
33+
|`parquet-viewer.logPanel`|`false`|Whether to write diagnostic logs to an output panel|
3434
|`parquet-viewer.logFolder`|empty|Write diagnostic logs under the given directory|
3535
|`parquet-viewer.logLevel`|info|Diagnostic log level. Choose between: `off`, `fatal`, `error`, `warn`, `info`, `debug` or `trace`|
36+
|`parquet-viewer.useParquetTools`|`false`|Use the legacy `parquet-tools` application for reading the files|
3637

3738
### What's new
3839

package-lock.json

Lines changed: 114 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@
6666
"trace"
6767
],
6868
"default": "info"
69+
},
70+
"parquet-viewer.useParquetTools": {
71+
"description": "use legacy parquet-tools application for reading parquet files",
72+
"type": "boolean"
6973
}
7074
}
7175
}
@@ -97,7 +101,8 @@
97101
"@types/chai-as-promised": "^7.1.3",
98102
"@types/glob": "^7.1.3",
99103
"@types/mocha": "^8.0.3",
100-
"@types/node": "^14.14.6",
104+
"@types/node": "^12.20.11",
105+
"@types/thrift": "^0.10.10",
101106
"@types/vscode": "^1.46.0",
102107
"@typescript-eslint/eslint-plugin": "^4.16.1",
103108
"@typescript-eslint/parser": "^4.16.1",
@@ -113,6 +118,7 @@
113118
},
114119
"dependencies": {
115120
"@async-generators/to-array": "^0.1.0",
121+
"@dvirtz/parquets": "^0.11.2-develop.1",
116122
"@vscode-logging/logger": "^1.2.2",
117123
"@vscode-logging/wrapper": "^1.0.0"
118124
}

src/extension.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// Import the module and reference it with the alias vscode in your code below
44
import * as vscode from 'vscode';
55
import { ParquetEditorProvider } from './parquet-editor-provider';
6-
import { ParquetToolsRunner } from './parquet-tools-runner';
76
import { getLogger, initLogger } from './logger';
87

98
// this method is called when your extension is activated
@@ -15,12 +14,5 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
1514
// restart logger on configuration change
1615
vscode.workspace.onDidChangeConfiguration(() => initLogger(context));
1716

18-
const parquetTools = await ParquetToolsRunner.spawnParquetTools(['-h']);
19-
parquetTools.on('error', async (err: string) => {
20-
const message = `parquet-tools not in PATH ('${err}')`;
21-
getLogger().error(message);
22-
await vscode.window.showErrorMessage(message);
23-
});
24-
2517
context.subscriptions.push(ParquetEditorProvider.register(context));
2618
}

src/parquet-editor-provider.ts

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import * as vscode from "vscode";
22
import * as path from 'path';
33
import { getNonce } from './util';
44
import { Disposable } from "./dispose";
5-
import { ParquetTextDocumentContentProvider } from "./parquet-document-provider";
6-
import { ParquetToolsRunner } from "./parquet-tools-runner";
5+
import { ParquetTextDocumentContentProvider } from './parquet-document-provider';
6+
import { ParquetToolsBackend } from './parquet-tools-backend';
7+
import { ParquetsBackend } from './parquets-backend';
78
import toArray from '@async-generators/to-array';
89
import { getLogger } from './logger';
10+
import { useParquetTools } from "./settings";
911

1012
class DummyDocument extends Disposable implements vscode.CustomDocument {
1113
uri: vscode.Uri;
@@ -24,29 +26,36 @@ class DummyDocument extends Disposable implements vscode.CustomDocument {
2426
);
2527
}
2628

29+
private async * toJson(parquetPath: string, token?: vscode.CancellationToken): AsyncGenerator<string> {
30+
if (useParquetTools()) {
31+
yield* ParquetToolsBackend.toJson(parquetPath, token);
32+
}
33+
34+
yield* ParquetsBackend.toJson(parquetPath, token);
35+
}
36+
2737
public async show() {
2838
getLogger().info(`showing ${this.path}.as.json`);
2939
if (ParquetTextDocumentContentProvider.has(this.path)) {
3040
return await this.open();
3141
}
3242

33-
return await vscode.window.withProgress({
34-
location: vscode.ProgressLocation.Notification,
35-
title: `opening ${path.basename(this.path)}`,
36-
cancellable: true
37-
},
38-
async (progress, token) => {
39-
try {
40-
const json = await toArray(ParquetToolsRunner.toJson(this.path, token));
43+
try {
44+
return await vscode.window.withProgress({
45+
location: vscode.ProgressLocation.Notification,
46+
title: `opening ${path.basename(this.path)}`,
47+
cancellable: true
48+
},
49+
async (progress, token) => {
50+
const json = await toArray(this.toJson(this.path, token));
4151
if (!token.isCancellationRequested) {
4252
ParquetTextDocumentContentProvider.add(this.path, json.join(''));
4353
await this.open();
4454
}
45-
} catch (err) {
46-
getLogger().error(err.message);
47-
await vscode.window.showErrorMessage(err.message);
48-
}
49-
});
55+
});
56+
} catch (err) {
57+
await vscode.window.showErrorMessage(err);
58+
}
5059
}
5160

5261
dispose(): void {
@@ -86,11 +95,19 @@ export class ParquetEditorProvider implements vscode.CustomReadonlyEditorProvide
8695

8796
webviewPanel.webview.html = this.getHtmlForWebview(webviewPanel.webview, document);
8897

89-
webviewPanel.webview.onDidReceiveMessage(_ => document.show());
98+
webviewPanel.webview.onDidReceiveMessage(e => this.onMessage(document, e));
9099

91100
await document.show();
92101
}
93102

103+
private async onMessage(document: DummyDocument, message: string) {
104+
switch (message) {
105+
case 'clicked':
106+
await document.show();
107+
break;
108+
}
109+
}
110+
94111
private getHtmlForWebview(webview: vscode.Webview, document: DummyDocument): string {
95112
// Use a nonce to whitelist which scripts can be run
96113
const nonce = getNonce();
@@ -109,7 +126,7 @@ export class ParquetEditorProvider implements vscode.CustomReadonlyEditorProvide
109126
//# sourceURL=to-json.js
110127
const vscode = acquireVsCodeApi();
111128
document.getElementById('here').addEventListener('click', _ => {
112-
vscode.postMessage();
129+
vscode.postMessage('clicked');
113130
});
114131
</script>
115132
</body>

0 commit comments

Comments
 (0)