@@ -53,6 +53,7 @@ const exportJSONFileName = 'data.json';
5353const importFileName = 'data.avro' ;
5454const partialDataFileName = 'partialdata.csv' ;
5555const localFilePath = path . join ( __dirname , `../resources/${ importFileName } ` ) ;
56+ const testExpirationTime = Date . now ( ) + 2 * 60 * 60 * 1000 ; // Add two hours
5657let projectId ;
5758let policyTag0 ;
5859let policyTag1 ;
@@ -266,6 +267,47 @@ describe('Tables', () => {
266267 assert . include ( output , nonexistentTableId ) ;
267268 } ) ;
268269
270+ it ( 'should create/update a table with default collation' , async ( ) => {
271+ const collationTableId = tableId + '_collation_test' ;
272+ const [ table ] = await bigquery
273+ . dataset ( datasetId )
274+ . createTable ( collationTableId , {
275+ schema : [
276+ { name : 'name' , type : 'STRING' } ,
277+ { name : 'nums' , type : 'INTEGER' } ,
278+ ] ,
279+ defaultCollation : 'und:ci' ,
280+ expirationTime : testExpirationTime ,
281+ } ) ;
282+ let [ md ] = await table . getMetadata ( ) ;
283+ assert . equal ( md . defaultCollation , 'und:ci' ) ;
284+ for ( const field of md . schema . fields ) {
285+ if ( field . type === 'STRING' ) {
286+ assert . equal ( field . collation , 'und:ci' ) ;
287+ }
288+ }
289+ // update table collation to case sensitive
290+ md . defaultCollation = '' ;
291+ await table . setMetadata ( md ) ;
292+ [ md ] = await table . getMetadata ( ) ;
293+ assert . equal ( md . defaultCollation , '' ) ;
294+
295+ // add field with different collation
296+ md . schema . fields . push ( {
297+ name : 'another_name' ,
298+ type : 'STRING' ,
299+ collation : 'und:ci' ,
300+ } ) ;
301+ await table . setMetadata ( md ) ;
302+
303+ [ md ] = await table . getMetadata ( ) ;
304+ for ( const field of md . schema . fields ) {
305+ if ( field . type === 'STRING' ) {
306+ assert . equal ( field . collation , 'und:ci' ) ;
307+ }
308+ }
309+ } ) ;
310+
269311 it ( 'should list tables' , async ( ) => {
270312 const output = execSync ( `node listTables.js ${ datasetId } ` ) ;
271313 assert . match ( output , / T a b l e s : / ) ;
0 commit comments