Google BigQuery
    
    
      
    
    
      
      使用集合让一切井井有条
    
    
      
      根据您的偏好保存内容并对其进行分类。
    
  
    
  
      
    
  
  
  
  
  
    
    
    
  
  
    
    
    
创建 BigQuery 数据集
function createDataSet() {
  // Replace this value with the project ID listed in the Google
  // Cloud Platform project.
  var projectId = 'INSERT_PROJECT_ID_HERE';
  var dataSetId = 'INSERT_DATASET_ID_HERE';
  var dataSet = BigQuery.newDataset();
  dataSet.id = dataSetId;
  dataSet.friendlyName = 'Fruit prices';
  dataSet.datasetReference = BigQuery.newDatasetReference();
  dataSet.datasetReference.projectId = projectId;
  dataSet.datasetReference.datasetId = dataSetId;
  dataSet = BigQuery.Datasets.insert(dataSet, projectId);
  console.log('Data set with ID = %s, Name = %s created.', dataSet.id,
      dataSet.friendlyName);
}
创建 BigQuery 数据表
function createTable() {
  // Replace this value with the project ID listed in the Google
  // Cloud Platform project.
  var projectId = 'INSERT_PROJECT_ID_HERE';
  var dataSetId = 'INSERT_DATASET_ID_HERE';
  var tableId = 'INSERT_TABLE_ID_HERE';
  var table = BigQuery.newTable();
  var schema = BigQuery.newTableSchema();
  var nameFieldSchema = BigQuery.newTableFieldSchema();
  nameFieldSchema.description = 'Name';
  nameFieldSchema.name = 'Name';
  nameFieldSchema.type = 'STRING';
  var ageFieldSchema = BigQuery.newTableFieldSchema();
  ageFieldSchema.description = 'Price';
  ageFieldSchema.name = 'Price';
  ageFieldSchema.type = 'FLOAT';
  schema.fields = [
    nameFieldSchema, ageFieldSchema
  ];
  table.schema = schema;
  table.id = tableId;
  table.friendlyName = 'Fruit prices';
  table.tableReference = BigQuery.newTableReference();
  table.tableReference.datasetId = dataSetId;
  table.tableReference.projectId = projectId;
  table.tableReference.tableId = tableId;
  table = BigQuery.Tables.insert(table, projectId, dataSetId);
  console.log('Data table with ID = %s, Name = %s created.',
      table.id, table.friendlyName);
}
导入 BigQuery 数据表
function importData() {
  // Replace this value with the project ID listed in the Google
  // Cloud Platform project.
  var projectId = 'INSERT_PROJECT_ID_HERE';
  var dataSetId = 'INSERT_DATASET_ID_HERE';
  var tableId = 'INSERT_TABLE_ID_HERE';
  var insertAllRequest = BigQuery.newTableDataInsertAllRequest();
  insertAllRequest.rows = [];
  var row1 = BigQuery.newTableDataInsertAllRequestRows();
  row1.insertId = 1;
  row1.json = {
    'Name': 'Orange',
    'Price': 3.34
  };
  insertAllRequest.rows.push(row1);
  var row2 = BigQuery.newTableDataInsertAllRequestRows();
  row2.insertId = 2;
  row2.json = {
    'Name': 'Grape',
    'Price': 5.48
  };
  insertAllRequest.rows.push(row2);
  var row3 = BigQuery.newTableDataInsertAllRequestRows();
  row3.insertId = 3;
  row3.json = {
    'Name': 'Apple',
    'Price': 2.50
  };
  insertAllRequest.rows.push(row3);
  var result = BigQuery.Tabledata.insertAll(insertAllRequest, projectId,
      dataSetId, tableId);
  if (result.insertErrors != null) {
    var allErrors = [];
    for (var i = 0; i < result.insertErrors.length; i++) {
      var insertError = result.insertErrors[i];
      allErrors.push(Utilities.formatString('Error inserting item: %s',
          insertError.index));
      for (var j = 0; j < insertError.errors.length; j++) {
        var error = insertError.errors[j];
        allErrors.push(Utilities.formatString('- ' + error));
      }
    }
    console.log(allErrors.join('\n'));
  } else {
    console.log(Utilities.formatString('%s data rows inserted successfully.',
        insertAllRequest.rows.length));
  }
}
针对 BigQuery 数据表运行查询
function queryDataTable() {
  // Replace this value with the project ID listed in the Google
  // Cloud Platform project.
  var projectId = 'INSERT_PROJECT_ID_HERE';
  var dataSetId = 'INSERT_DATASET_ID_HERE';
  var tableId = 'INSERT_TABLE_ID_HERE';
  var fullTableName = projectId + ':' + dataSetId + '.' + tableId;
  var queryRequest = BigQuery.newQueryRequest();
  queryRequest.query = 'select Name, Price from [' + fullTableName + '];';
  var query = BigQuery.Jobs.query(queryRequest, projectId);
  if (query.jobComplete) {
    for (var i = 0; i < query.rows.length; i++) {
      var row = query.rows[i];
      var values = [];
      for (var j = 0; j < row.f.length; j++) {
        values.push(row.f[j].v);
      }
      console.log(values.join(','));
    }
  }
}
  
  
  
  
    
  
 
  
    
      
      
    
    
      
    
    
  
       
    
    
      
    
  
  
  如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
  最后更新时间 (UTC):2025-08-21。
  
  
  
    
      [[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-21。"],[],[]]