-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move JSON creation to base class
- Loading branch information
Showing
5 changed files
with
24 additions
and
24 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
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,17 +1,31 @@ | ||
import { CancellationToken } from 'vscode'; | ||
import { getLogger } from '../logger'; | ||
import { jsonSpace } from '../settings'; | ||
|
||
export abstract class ParquetBackend { | ||
public async* toJson(parquetPath: string, token?: CancellationToken) { | ||
|
||
function bigIntToJson(value: bigint) { | ||
// serialize as a number if it's in bounds, otherwise as a string | ||
if (value <= BigInt(Number.MAX_SAFE_INTEGER) && value >= BigInt(Number.MIN_SAFE_INTEGER)) { | ||
return Number(value); | ||
} | ||
return value.toString(); | ||
} | ||
|
||
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; | ||
yield JSON.stringify(line, (key, value) => { | ||
return typeof value === 'bigint' | ||
? bigIntToJson(value) | ||
: value // return everything else unchanged | ||
}, jsonSpace()); | ||
} | ||
} | ||
|
||
abstract toJsonImpl(parquetPath: string, token?: CancellationToken): AsyncGenerator<string>; | ||
abstract toJsonImpl(parquetPath: string, token?: CancellationToken): AsyncGenerator<object>; | ||
} |
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