forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
replace exec with spawn to support large parquets. fixes llvm#1
- Loading branch information
Showing
5 changed files
with
1,361 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,56 @@ | ||
import { TextDocumentContentProvider, EventEmitter, Uri, window } from "vscode"; | ||
import { exec } from "child_process"; | ||
import { spawn } from "child_process"; | ||
// import { Readable } from "stream"; | ||
// import { tmpdir } from "os"; | ||
// import { createWriteStream, readFile, readFileSync } from 'fs'; | ||
// import { sep } from 'path'; | ||
|
||
|
||
class Json { | ||
data: string = ""; | ||
} | ||
|
||
export class ParquetContentProvider implements TextDocumentContentProvider { | ||
|
||
private jsons: Map<string, Json> = new Map(); | ||
|
||
// emitter and its event | ||
onDidChangeEmitter = new EventEmitter<Uri>(); | ||
onDidChange = this.onDidChangeEmitter.event; | ||
|
||
async provideTextDocumentContent(uri: Uri): Promise<string> { | ||
// simply invoke cowsay, use uri-path as text | ||
return new Promise<string>((resolve, reject) => { | ||
exec('parquet-tools cat -j ' + uri.path, (error, stdout, stderr) => { | ||
if (error) { | ||
const message = `error when running parquet-tools ${error}:\n${stderr}`; | ||
|
||
const path = uri.path.replace(RegExp('\.as\.json$'), ''); | ||
|
||
if (this.jsons.has(path)) { | ||
resolve(this.jsons.get(path)!.data); | ||
} | ||
|
||
var json = new Json; | ||
this.jsons.set(path, json); | ||
|
||
const parquet_tools = spawn('parquet-tools', ['cat', '-j', path]); | ||
// parquet_tools.stdout.pipe(stream) | ||
var stderr: string = ""; | ||
parquet_tools.stderr.on('data', (data) => { | ||
stderr += data; | ||
}); | ||
parquet_tools.stdout.on('data', (data) => { | ||
json.data += data; | ||
this.onDidChangeEmitter.fire(uri); | ||
}); | ||
|
||
parquet_tools.on('close', (code) => { | ||
if (code) { | ||
const message = `error when running parquet-tools ${code}:\n${stderr}`; | ||
window.showErrorMessage(message); | ||
reject(message); | ||
} | ||
|
||
resolve(stdout); | ||
resolve(json.data); | ||
}); | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.