Skip to content
This repository was archived by the owner on Feb 7, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/bigquery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ export class BigQuery extends Service {
* @returns Fields using their matching names from the table's schema.
*/
static mergeSchemaWithRows_(
schema: TableSchema | TableField,
schema: TableSchema | TableField | undefined,
rows: TableRow[],
options: {
wrapIntegers: boolean | IntegerTypeCastOptions;
Expand All @@ -589,7 +589,7 @@ export class BigQuery extends Service {
}
) {
// deep copy schema fields to avoid mutation
let schemaFields: TableField[] = extend(true, [], schema.fields);
let schemaFields: TableField[] = extend(true, [], schema?.fields);
let selectedFields: string[] = extend(true, [], options.selectedFields);
if (options.selectedFields && options.selectedFields!.length > 0) {
const selectedFieldsArray = options.selectedFields!.map(c => {
Expand Down
12 changes: 12 additions & 0 deletions system-test/bigquery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,18 @@ describe('BigQuery', () => {
});
});

// Empty results sets will not fetch table schema
it('should get the rows from an empty table', async () => {
const emptyTableId = generateName('empty-table');
await dataset.createTable(emptyTableId, {
schema: [{name: 'id', type: 'STRING'}],
});
const emptyTable = dataset.table(emptyTableId);
const [rows] = await emptyTable.getRows();
assert(Array.isArray(rows));
assert.equal(rows.length, 0);
});

it('should get the rows in a table via stream', done => {
table
.createReadStream()
Expand Down