Bigquery add columns to table schema

前端 未结 5 2044
-上瘾入骨i
-上瘾入骨i 2020-12-01 10:50

I am trying to add new column to BigQuery existing table. I have tried bq command tool and API approach. I get following error when making call to Tables.update().

5条回答
  •  庸人自扰
    2020-12-01 11:40

    Example using the BigQuery Node JS API:

    const fieldDefinition = {
        name: 'nestedColumn',
        type: 'RECORD',
        mode: 'REPEATED',
        fields: [
            {name: 'id', type: 'INTEGER', mode: 'NULLABLE'},
            {name: 'amount', type: 'INTEGER', mode: 'NULLABLE'},
        ],
    }; 
    
    const table = bigQuery.dataset('dataset1').table('source_table_name');
    const metaDataResult = await table.getMetadata();
    const metaData = metaDataResult[0];
    
    const fields = metaData.schema.fields;
    fields.push(fieldDefinition);
    
    await table.setMetadata({schema: {fields}});
    

提交回复
热议问题