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.
refactor: factor cancellation to base class
- Loading branch information
Showing
8 changed files
with
121 additions
and
129 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,5 +1,17 @@ | ||
import * as vscode from 'vscode'; | ||
import { CancellationToken } from 'vscode'; | ||
import { getLogger } from './logger'; | ||
|
||
export interface ParquetBackend { | ||
toJson(parquetPath: string, token?: vscode.CancellationToken): AsyncGenerator<string>; | ||
export abstract class ParquetBackend { | ||
public async* toJson(parquetPath: string, token?: CancellationToken) { | ||
getLogger().info(`opening ${parquetPath}`) | ||
for await (const line of this.toJsonImpl(parquetPath, token)) { | ||
if (token?.isCancellationRequested) { | ||
getLogger().info(`parsing ${parquetPath} was cancelled by user`); | ||
break; | ||
} | ||
yield line; | ||
} | ||
} | ||
|
||
abstract toJsonImpl(parquetPath: string, token?: CancellationToken): AsyncGenerator<string>; | ||
} |
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
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,33 +1,19 @@ | ||
import * as vscode from 'vscode'; | ||
import { getLogger } from './logger'; | ||
import { CancellationToken } from 'vscode'; | ||
import { ParquetReader } from '@dvirtz/parquets'; | ||
import { ParquetBackend } from './parquet-backend'; | ||
import { jsonSpace } from './settings'; | ||
|
||
export class ParquetsBackend implements ParquetBackend { | ||
public async * toJson(parquetPath: string, token?: vscode.CancellationToken): AsyncGenerator<string> { | ||
const cancelledMessage = `parsing ${parquetPath} was cancelled by user`; | ||
if (token?.isCancellationRequested) { | ||
getLogger().info(cancelledMessage); | ||
return; | ||
} | ||
|
||
getLogger().info(`opening ${parquetPath}`) | ||
try { | ||
const reader = await ParquetReader.openFile(parquetPath); | ||
const cursor = reader.getCursor(); | ||
export class ParquetsBackend extends ParquetBackend { | ||
public async * toJsonImpl(parquetPath: string, _token?: CancellationToken): AsyncGenerator<string> { | ||
const reader = await ParquetReader.openFile(parquetPath); | ||
const cursor = reader.getCursor(); | ||
|
||
// read all records from the file and print them | ||
let record = null; | ||
while (!token?.isCancellationRequested && (record = await cursor.next())) { | ||
yield JSON.stringify(record, null, jsonSpace()); | ||
} | ||
|
||
await reader.close(); | ||
} catch (error) { | ||
const message = `while reading ${parquetPath}: ${error}`; | ||
getLogger().error(message); | ||
throw Error(message); | ||
// read all records from the file and print them | ||
let record = null; | ||
while ((record = await cursor.next())) { | ||
yield JSON.stringify(record, null, jsonSpace()); | ||
} | ||
|
||
await reader.close(); | ||
} | ||
} |
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
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