File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -580,7 +580,7 @@ export class BigQuery extends Service {
580580 * @returns Fields using their matching names from the table's schema.
581581 */
582582 static mergeSchemaWithRows_ (
583- schema : TableSchema | TableField ,
583+ schema : TableSchema | TableField | undefined ,
584584 rows : TableRow [ ] ,
585585 options : {
586586 wrapIntegers : boolean | IntegerTypeCastOptions ;
@@ -589,7 +589,7 @@ export class BigQuery extends Service {
589589 }
590590 ) {
591591 // deep copy schema fields to avoid mutation
592- let schemaFields : TableField [ ] = extend ( true , [ ] , schema . fields ) ;
592+ let schemaFields : TableField [ ] = extend ( true , [ ] , schema ? .fields ) ;
593593 let selectedFields : string [ ] = extend ( true , [ ] , options . selectedFields ) ;
594594 if ( options . selectedFields && options . selectedFields ! . length > 0 ) {
595595 const selectedFieldsArray = options . selectedFields ! . map ( c => {
Original file line number Diff line number Diff line change @@ -896,6 +896,18 @@ describe('BigQuery', () => {
896896 } ) ;
897897 } ) ;
898898
899+ // Empty results sets will not fetch table schema
900+ it ( 'should get the rows from an empty table' , async ( ) => {
901+ const emptyTableId = generateName ( 'empty-table' ) ;
902+ await dataset . createTable ( emptyTableId , {
903+ schema : [ { name : 'id' , type : 'STRING' } ] ,
904+ } ) ;
905+ const emptyTable = dataset . table ( emptyTableId ) ;
906+ const [ rows ] = await emptyTable . getRows ( ) ;
907+ assert ( Array . isArray ( rows ) ) ;
908+ assert . equal ( rows . length , 0 ) ;
909+ } ) ;
910+
899911 it ( 'should get the rows in a table via stream' , done => {
900912 table
901913 . createReadStream ( )
You can’t perform that action at this time.
0 commit comments