@@ -40,7 +40,7 @@ import {TEST_INSTANCE_NAME} from './mockserver/mockinstanceadmin';
4040import * as mockDatabaseAdmin from './mockserver/mockdatabaseadmin' ;
4141import * as sinon from 'sinon' ;
4242import { google } from '../protos/protos' ;
43- import { ExecuteSqlRequest , RunResponse } from '../src/transaction' ;
43+ import { ExecuteSqlRequest , ReadRequest , RunResponse } from '../src/transaction' ;
4444import { Row } from '../src/partial-result-stream' ;
4545import { GetDatabaseOperationsOptions } from '../src/instance' ;
4646import {
@@ -1390,6 +1390,89 @@ describe('Spanner with mock server', () => {
13901390 }
13911391 } ) ;
13921392
1393+ it ( 'should return the results correctly when last field is present in PartialResultSet for query' , async ( ) => {
1394+ // Setup a query result with more than maxQueued (10) PartialResultSets.
1395+ // None of the PartialResultSets include a resume token.
1396+ const sql = 'SELECT C1 FROM TestTable' ;
1397+ const fields = [
1398+ protobuf . StructType . Field . create ( {
1399+ name : 'C1' ,
1400+ type : protobuf . Type . create ( { code : protobuf . TypeCode . STRING } ) ,
1401+ } ) ,
1402+ ] ;
1403+ const metadata = new protobuf . ResultSetMetadata ( {
1404+ rowType : new protobuf . StructType ( {
1405+ fields,
1406+ } ) ,
1407+ } ) ;
1408+ const results : PartialResultSet [ ] = [ ] ;
1409+ for ( let i = 0 ; i < 2 ; i ++ ) {
1410+ results . push (
1411+ PartialResultSet . create ( {
1412+ metadata,
1413+ values : [ { stringValue : `V${ i } ` } ] ,
1414+ last : i === 1 ,
1415+ } ) ,
1416+ ) ;
1417+ }
1418+ spannerMock . putStatementResult (
1419+ sql ,
1420+ mock . StatementResult . resultSet ( results ) ,
1421+ ) ;
1422+
1423+ const database = newTestDatabase ( ) ;
1424+ const [ rows ] = await database . run ( sql ) ;
1425+ assert . equal ( rows . length , 2 ) ;
1426+ await database . close ( ) ;
1427+ } ) ;
1428+
1429+ it ( 'should return the results correctly when last field is present in PartialResultSet for read' , async ( ) => {
1430+ // Setup a query result with more than maxQueued (10) PartialResultSets.
1431+ // None of the PartialResultSets include a resume token.
1432+ const fields = [
1433+ protobuf . StructType . Field . create ( {
1434+ name : 'C1' ,
1435+ type : protobuf . Type . create ( { code : protobuf . TypeCode . STRING } ) ,
1436+ } ) ,
1437+ ] ;
1438+ const metadata = new protobuf . ResultSetMetadata ( {
1439+ rowType : new protobuf . StructType ( {
1440+ fields,
1441+ } ) ,
1442+ } ) ;
1443+ const results : PartialResultSet [ ] = [ ] ;
1444+ for ( let i = 0 ; i < 2 ; i ++ ) {
1445+ results . push (
1446+ PartialResultSet . create ( {
1447+ metadata,
1448+ values : [ { stringValue : `V${ i } ` } ] ,
1449+ last : i === 0 ,
1450+ } ) ,
1451+ ) ;
1452+ }
1453+ const request = {
1454+ table : 'TestTable' ,
1455+ keySet : {
1456+ keys : [ ] ,
1457+ all : true ,
1458+ ranges : [ ] ,
1459+ } ,
1460+ } ;
1461+ spannerMock . putReadRequestResult (
1462+ request ,
1463+ mock . ReadRequestResult . resultSet ( results ) ,
1464+ ) ;
1465+
1466+ const database = newTestDatabase ( ) ;
1467+ const table = database . table ( 'TestTable' ) ;
1468+ const query = {
1469+ columns : [ 'C1' ] ,
1470+ } ;
1471+ const [ rows ] = await table . read ( query ) ;
1472+ assert . equal ( rows . length , 1 ) ;
1473+ await database . close ( ) ;
1474+ } ) ;
1475+
13931476 it ( 'should handle missing parameters in query' , async ( ) => {
13941477 const sql =
13951478 'SELECT * FROM tableId WHERE namedParameter = @namedParameter' ;
0 commit comments