-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #112 from duckdb/jray/row-and-column-objects
row and column objects
- Loading branch information
Showing
8 changed files
with
172 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
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,24 @@ | ||
import { DuckDBDataChunk } from './DuckDBDataChunk'; | ||
import { DuckDBValue } from './values'; | ||
|
||
export function getColumnsObjectFromChunks( | ||
chunks: readonly DuckDBDataChunk[], | ||
columnNames: readonly string[], | ||
): Record<string, DuckDBValue[]> { | ||
const columnsObject: Record<string, DuckDBValue[]> = {}; | ||
for (const columnName of columnNames) { | ||
columnsObject[columnName] = []; | ||
} | ||
if (chunks.length === 0) { | ||
return columnsObject; | ||
} | ||
const columnCount = chunks[0].columnCount; | ||
for (let chunkIndex = 0; chunkIndex < chunks.length; chunkIndex++) { | ||
for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) { | ||
chunks[chunkIndex].visitColumnValues(columnIndex, (value) => | ||
columnsObject[columnNames[columnIndex]].push(value) | ||
); | ||
} | ||
} | ||
return columnsObject; | ||
} |
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,20 @@ | ||
import { DuckDBDataChunk } from './DuckDBDataChunk'; | ||
import { DuckDBValue } from './values'; | ||
|
||
export function getRowObjectsFromChunks( | ||
chunks: readonly DuckDBDataChunk[], | ||
columnNames: readonly string[] | ||
): Record<string, DuckDBValue>[] { | ||
const rowObjects: Record<string, DuckDBValue>[] = []; | ||
for (const chunk of chunks) { | ||
const rowCount = chunk.rowCount; | ||
for (let rowIndex = 0; rowIndex < rowCount; rowIndex++) { | ||
const rowObject: Record<string, DuckDBValue> = {}; | ||
chunk.visitRowValues(rowIndex, (value, _, columnIndex) => { | ||
rowObject[columnNames[columnIndex]] = value; | ||
}); | ||
rowObjects.push(rowObject); | ||
} | ||
} | ||
return rowObjects; | ||
} |
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,10 +1,12 @@ | ||
import { DuckDBDataChunk } from './DuckDBDataChunk'; | ||
import { DuckDBValue } from './values'; | ||
|
||
export function getRowsFromChunks(chunks: readonly DuckDBDataChunk[]): DuckDBValue[][] { | ||
export function getRowsFromChunks( | ||
chunks: readonly DuckDBDataChunk[] | ||
): DuckDBValue[][] { | ||
const rows: DuckDBValue[][] = []; | ||
for (const chunk of chunks) { | ||
chunk.visitRows(row => rows.push(row)); | ||
chunk.visitRows((row) => rows.push(row)); | ||
} | ||
return rows; | ||
} |
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