File tree 2 files changed +31
-0
lines changed
2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -1005,6 +1005,8 @@ export class BigQuery extends Service {
1005
1005
'GEOGRAPHY' ,
1006
1006
'ARRAY' ,
1007
1007
'STRUCT' ,
1008
+ 'JSON' ,
1009
+ 'RANGE' ,
1008
1010
] ;
1009
1011
1010
1012
if ( is . array ( providedType ) ) {
@@ -1182,6 +1184,8 @@ export class BigQuery extends Service {
1182
1184
} ,
1183
1185
{ }
1184
1186
) ;
1187
+ } else if ( typeName === 'JSON' && is . object ( value ) ) {
1188
+ queryParameter . parameterValue ! . value = JSON . stringify ( value ) ;
1185
1189
} else {
1186
1190
queryParameter . parameterValue ! . value = BigQuery . _getValue (
1187
1191
value ,
Original file line number Diff line number Diff line change @@ -1521,6 +1521,33 @@ describe('BigQuery', () => {
1521
1521
assert . deepStrictEqual ( param , expectedParam ) ;
1522
1522
} ) ;
1523
1523
1524
+ it ( 'should format JSON types' , ( ) => {
1525
+ const typeName = 'JSON' ;
1526
+ const value = {
1527
+ foo : 'bar' ,
1528
+ } ;
1529
+ const strValue = JSON . stringify ( value ) ;
1530
+ assert . deepStrictEqual ( BigQuery . valueToQueryParameter_ ( value , typeName ) , {
1531
+ parameterType : {
1532
+ type : typeName ,
1533
+ } ,
1534
+ parameterValue : {
1535
+ value : strValue ,
1536
+ } ,
1537
+ } ) ;
1538
+ assert . deepStrictEqual (
1539
+ BigQuery . valueToQueryParameter_ ( strValue , typeName ) ,
1540
+ {
1541
+ parameterType : {
1542
+ type : typeName ,
1543
+ } ,
1544
+ parameterValue : {
1545
+ value : strValue ,
1546
+ } ,
1547
+ }
1548
+ ) ;
1549
+ } ) ;
1550
+
1524
1551
it ( 'should format all other types' , ( ) => {
1525
1552
const typeName = 'ANY-TYPE' ;
1526
1553
sandbox . stub ( BigQuery , 'getTypeDescriptorFromValue_' ) . returns ( {
You can’t perform that action at this time.
0 commit comments