Skip to content

Commit

Permalink
Data Explorer: Relax DuckDB post-query checks to allow queries past t…
Browse files Browse the repository at this point in the history
…he end of tables (#5644)

Addresses #5552. The frontend in some of its UI calculations requests
the first 10 rows of data, but there may not be 10 rows available. It
might be good to improve the UI logic, but in the meantime there is no
reason to error when a query requests beyond the end of the table.
  • Loading branch information
wesm authored Dec 6, 2024
1 parent 037a532 commit c46e44b
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions extensions/positron-duckdb/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -840,13 +840,9 @@ END`;

const queryResult = await this.db.runQuery(query);

// Sanity checks
// Sanity check
if (queryResult.numCols !== params.columns.length) {
return 'Incorrect number of columns in query result';
}

if (queryResult.numRows !== numRows) {
return 'Incorrect number of rows in query result';
throw new Error('Incorrect number of columns in query result');
}

const result: TableData = {
Expand Down Expand Up @@ -881,9 +877,12 @@ END`;

const fetchValues = (adapter: (field: Vector<any>, i: number) => ColumnValue) => {
if ('first_index' in spec) {
// There may be fewer rows available than what was requested
const lastIndex = Math.min(spec.last_index, queryResult.numRows - 1);

const columnValues: Array<string | number> = [];
// Value range, we need to extract the actual slice requested
for (let i = spec.first_index; i <= spec.last_index; ++i) {
for (let i = spec.first_index; i <= lastIndex; ++i) {
columnValues.push(adapter(field, i));
}
return columnValues;
Expand Down

0 comments on commit c46e44b

Please sign in to comment.