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
6 changes: 4 additions & 2 deletions src/bigquery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -588,14 +588,16 @@ export class BigQuery extends Service {
parseJSON?: boolean;
}
) {
// copy schema fields to avoid mutation when filtering selected fields
let schemaFields = schema.fields ? [...schema.fields] : [];
if (options.selectedFields && options.selectedFields!.length > 0) {
const selectedFieldsArray = options.selectedFields!.map(c => {
return c.split('.');
});

const currentFields = selectedFieldsArray.map(c => c.shift());
//filter schema fields based on selected fields.
schema.fields = schema.fields?.filter(
schemaFields = schemaFields.filter(
field =>
currentFields
.map(c => c!.toLowerCase())
Expand All @@ -610,7 +612,7 @@ export class BigQuery extends Service {

function mergeSchema(row: TableRow) {
return row.f!.map((field: TableRowField, index: number) => {
const schemaField = schema.fields![index];
const schemaField = schemaFields[index];
let value = field.v;
if (schemaField.mode === 'REPEATED') {
value = (value as TableRowField[]).map(val => {
Expand Down
10 changes: 6 additions & 4 deletions src/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1830,6 +1830,10 @@ class Table extends ServiceObject {
delete options.wrapIntegers;
const parseJSON = options.parseJSON ? options.parseJSON : false;
delete options.parseJSON;
const selectedFields = options.selectedFields
? options.selectedFields.split(',')
: [];
delete options.selectedFields;
const onComplete = (
err: Error | null,
rows: TableRow[] | null,
Expand All @@ -1841,10 +1845,8 @@ class Table extends ServiceObject {
return;
}
rows = BigQuery.mergeSchemaWithRows_(this.metadata.schema, rows || [], {
wrapIntegers: wrapIntegers,
selectedFields: options.selectedFields
? options.selectedFields!.split(',')
: [],
wrapIntegers,
selectedFields,
parseJSON,
});
callback!(null, rows, nextQuery, resp);
Expand Down
Loading