-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PECO-238] Initial CloudFetch implementation
Signed-off-by: Levko Kravets <[email protected]>
- Loading branch information
1 parent
6de01cb
commit 1731abd
Showing
11 changed files
with
316 additions
and
25 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
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
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Buffer } from 'buffer'; | ||
import fetch from 'node-fetch'; | ||
import { TRowSet, TSparkArrowResultLink } from '../../thrift/TCLIService_types'; | ||
import ArrowResult from './ArrowResult'; | ||
|
||
export default class CloudFetchResult extends ArrowResult { | ||
protected batchesToRows(batches: Array<Buffer>) { | ||
if (batches.length === 1) { | ||
return super.batchesToRows(batches); | ||
} | ||
|
||
const results: Array<Array<any>> = []; | ||
|
||
for (const batch of batches) { | ||
results.push(super.batchesToRows([batch])); | ||
} | ||
|
||
return results.flat(1); | ||
} | ||
|
||
protected async getBatches(data: Array<TRowSet>): Promise<Array<Buffer>> { | ||
const tasks: Array<Promise<Buffer>> = []; | ||
|
||
data?.forEach((item) => { | ||
item.resultLinks?.forEach((link) => { | ||
tasks.push(this.downloadLink(link)); | ||
}); | ||
}); | ||
|
||
return await Promise.all(tasks); | ||
} | ||
|
||
private async downloadLink(link: TSparkArrowResultLink): Promise<Buffer> { | ||
// TODO: Process expired links | ||
const response = await fetch(link.fileLink); | ||
if (!response.ok) { | ||
throw new Error(`CloudFetch HTTP error ${response.status} ${response.statusText}`); | ||
} | ||
|
||
const result = await response.arrayBuffer(); | ||
return Buffer.from(result); | ||
} | ||
} |
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,5 @@ | ||
import { TRowSet } from '../../thrift/TCLIService_types'; | ||
|
||
export default interface IOperationResult { | ||
getValue(data?: Array<TRowSet>): any; | ||
getValue(data?: Array<TRowSet>): Promise<any>; | ||
} |
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.