Google BigQuery
Organiza tus páginas con colecciones Guarda y categoriza el contenido según tus preferencias.
Crear un conjunto de datos de 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); }
Crear una tabla de datos de 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); }
Importar datos a una tabla de datos de 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)); } }
Ejecutar una consulta en una tabla de datos de 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(',')); } } }
Salvo que se indique lo contrario, el contenido de esta página está sujeto a la licencia Atribución 4.0 de Creative Commons, y los ejemplos de código están sujetos a la licencia Apache 2.0. Para obtener más información, consulta las políticas del sitio de Google Developers. Java es una marca registrada de Oracle o sus afiliados.
Última actualización: 2025-08-21 (UTC)
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Falta la información que necesito","missingTheInformationINeed","thumb-down"],["Muy complicado o demasiados pasos","tooComplicatedTooManySteps","thumb-down"],["Desactualizado","outOfDate","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Problema con las muestras o los códigos","samplesCodeIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2025-08-21 (UTC)"],[[["\u003cp\u003eThis webpage demonstrates how to create a BigQuery dataset using Google Apps Script.\u003c/p\u003e\n"],["\u003cp\u003eThe code snippets showcase creating and populating a BigQuery table with sample fruit and price data.\u003c/p\u003e\n"],["\u003cp\u003eFunctionality is provided to import data and subsequently query the table using Google Apps Script.\u003c/p\u003e\n"],["\u003cp\u003eProvided examples include defining a schema, inserting rows, and running SQL-like queries to retrieve data.\u003c/p\u003e\n"]]],[],null,["# Google BigQuery\n\nCreate a BigQuery data set\n--------------------------\n\n```gdscript\nfunction createDataSet() {\n // Replace this value with the project ID listed in the Google\n // Cloud Platform project.\n var projectId = 'INSERT_PROJECT_ID_HERE';\n\n var dataSetId = 'INSERT_DATASET_ID_HERE';\n\n var dataSet = BigQuery.newDataset();\n dataSet.id = dataSetId;\n dataSet.friendlyName = 'Fruit prices';\n dataSet.datasetReference = BigQuery.newDatasetReference();\n dataSet.datasetReference.projectId = projectId;\n dataSet.datasetReference.datasetId = dataSetId;\n\n dataSet = BigQuery.Datasets.insert(dataSet, projectId);\n console.log('Data set with ID = %s, Name = %s created.', dataSet.id,\n dataSet.friendlyName);\n}\n```\n\nCreate a BigQuery data table\n----------------------------\n\n```gdscript\nfunction createTable() {\n // Replace this value with the project ID listed in the Google\n // Cloud Platform project.\n var projectId = 'INSERT_PROJECT_ID_HERE';\n\n var dataSetId = 'INSERT_DATASET_ID_HERE';\n var tableId = 'INSERT_TABLE_ID_HERE';\n\n var table = BigQuery.newTable();\n var schema = BigQuery.newTableSchema();\n\n var nameFieldSchema = BigQuery.newTableFieldSchema();\n nameFieldSchema.description = 'Name';\n nameFieldSchema.name = 'Name';\n nameFieldSchema.type = 'STRING';\n\n var ageFieldSchema = BigQuery.newTableFieldSchema();\n ageFieldSchema.description = 'Price';\n ageFieldSchema.name = 'Price';\n ageFieldSchema.type = 'FLOAT';\n\n schema.fields = [\n nameFieldSchema, ageFieldSchema\n ];\n\n table.schema = schema;\n table.id = tableId;\n table.friendlyName = 'Fruit prices';\n\n table.tableReference = BigQuery.newTableReference();\n table.tableReference.datasetId = dataSetId;\n table.tableReference.projectId = projectId;\n table.tableReference.tableId = tableId;\n\n table = BigQuery.Tables.insert(table, projectId, dataSetId);\n\n console.log('Data table with ID = %s, Name = %s created.',\n table.id, table.friendlyName);\n}\n```\n\nImport into BigQuery data table\n-------------------------------\n\n```transact-sql\nfunction importData() {\n // Replace this value with the project ID listed in the Google\n // Cloud Platform project.\n var projectId = 'INSERT_PROJECT_ID_HERE';\n\n var dataSetId = 'INSERT_DATASET_ID_HERE';\n var tableId = 'INSERT_TABLE_ID_HERE';\n\n var insertAllRequest = BigQuery.newTableDataInsertAllRequest();\n insertAllRequest.rows = [];\n\n var row1 = BigQuery.newTableDataInsertAllRequestRows();\n row1.insertId = 1;\n row1.json = {\n 'Name': 'Orange',\n 'Price': 3.34\n };\n insertAllRequest.rows.push(row1);\n\n var row2 = BigQuery.newTableDataInsertAllRequestRows();\n row2.insertId = 2;\n row2.json = {\n 'Name': 'Grape',\n 'Price': 5.48\n };\n insertAllRequest.rows.push(row2);\n\n var row3 = BigQuery.newTableDataInsertAllRequestRows();\n row3.insertId = 3;\n row3.json = {\n 'Name': 'Apple',\n 'Price': 2.50\n };\n insertAllRequest.rows.push(row3);\n\n var result = BigQuery.Tabledata.insertAll(insertAllRequest, projectId,\n dataSetId, tableId);\n\n if (result.insertErrors != null) {\n var allErrors = [];\n\n for (var i = 0; i \u003c result.insertErrors.length; i++) {\n var insertError = result.insertErrors[i];\n allErrors.push(Utilities.formatString('Error inserting item: %s',\n insertError.index));\n\n for (var j = 0; j \u003c insertError.errors.length; j++) {\n var error = insertError.errors[j];\n allErrors.push(Utilities.formatString('- ' + error));\n }\n }\n console.log(allErrors.join('\\n'));\n } else {\n console.log(Utilities.formatString('%s data rows inserted successfully.',\n insertAllRequest.rows.length));\n }\n}\n```\n\nRun query against BigQuery data table\n-------------------------------------\n\n```transact-sql\nfunction queryDataTable() {\n // Replace this value with the project ID listed in the Google\n // Cloud Platform project.\n var projectId = 'INSERT_PROJECT_ID_HERE';\n\n var dataSetId = 'INSERT_DATASET_ID_HERE';\n var tableId = 'INSERT_TABLE_ID_HERE';\n\n var fullTableName = projectId + ':' + dataSetId + '.' + tableId;\n\n var queryRequest = BigQuery.newQueryRequest();\n queryRequest.query = 'select Name, Price from [' + fullTableName + '];';\n var query = BigQuery.Jobs.query(queryRequest, projectId);\n\n if (query.jobComplete) {\n for (var i = 0; i \u003c query.rows.length; i++) {\n var row = query.rows[i];\n var values = [];\n for (var j = 0; j \u003c row.f.length; j++) {\n values.push(row.f[j].v);\n }\n console.log(values.join(','));\n }\n }\n}\n```"]]