From df2e87a3a38486fb5b676aef2230b70fa0c84d98 Mon Sep 17 00:00:00 2001 From: Ryan Seys Date: Tue, 14 Oct 2014 12:05:40 -0400 Subject: [PATCH 1/5] Bigquery stubs --- lib/bigquery/dataset.js | 106 ++++++++++++++++++++++++++++++++++ lib/bigquery/dataset.table.js | 52 +++++++++++++++++ lib/bigquery/index.js | 94 ++++++++++++++++++++++++++++++ lib/bigquery/job.js | 33 +++++++++++ lib/index.js | 9 +++ test/bigquery/index.js | 30 ++++++++++ 6 files changed, 324 insertions(+) create mode 100644 lib/bigquery/dataset.js create mode 100644 lib/bigquery/dataset.table.js create mode 100644 lib/bigquery/index.js create mode 100644 lib/bigquery/job.js create mode 100644 test/bigquery/index.js diff --git a/lib/bigquery/dataset.js b/lib/bigquery/dataset.js new file mode 100644 index 00000000000..5e0647ac56a --- /dev/null +++ b/lib/bigquery/dataset.js @@ -0,0 +1,106 @@ +/*! + * Copyright 2014 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +'use strict'; + +var Table = require('./dataset.table.js'); + +/** + * Create a Dataset object. + * + * @param {string} datasetId - The id of the Dataset. + */ +function Dataset(datasetId) { + if (!(this instanceof Dataset)) { + return new Dataset(datasetId); + } + this.id = datasetId; +} + +/** + * Sets the metadata of the Dataset object. + * + * @param {object} metadata - Metadata to save on the Dataset. + * @param {Function} callback - The callback function. + * + * @example + * + * var metadata = { + * description: 'kittens dataset' + * }; + * + * myDataset.setMetadata(metadata, function(err) { + * if(!err) { + * // use updated myDataset + * } + * }); + */ +Dataset.prototype.setMetadata = function(metadata, callback) { + throw new Error('Not implemented.'); +}; + +/** + * Get the metadata for the Dataset. + * + * @param {Function} callback - The callback function. + * + * @example + * + * myDataset.getMetadata(function(err, metadata) { + * if(!err) { + * // use metadata object, myDataset is already automatically updated + * } + * }); + */ +Dataset.prototype.getMetadata = function(callback) { + throw new Error('Not implemented.'); +}; + +// options.force will force deletion +Dataset.prototype.delete = function(options, callback) { + throw new Error('Not implemented.'); +}; + +/** + * Return a new instance of reference to an existing Table object. + * + * @param {string} tableId - The id of the table. + * @return {Table} Reference to existing Table object. + */ +Dataset.prototype.table = function(tableId) { + return new Table({ + dataset: this, + id: tableId + }); +}; + +/** + * Create a table given a tableId or configuration object. + * + * @param {string|object} tableId - Table id or configuration object. + * @param {Function} callback - The callback function. + * + * @example + * + * myDataset.createTable('customers', function(err, table) { + * // use the table + * }); + */ +Dataset.prototype.createTable = function(tableId, callback) { + throw new Error('Not implemented.'); +}; + +module.exports = Dataset; diff --git a/lib/bigquery/dataset.table.js b/lib/bigquery/dataset.table.js new file mode 100644 index 00000000000..75755131247 --- /dev/null +++ b/lib/bigquery/dataset.table.js @@ -0,0 +1,52 @@ +/*! + * Copyright 2014 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +'use strict'; + +/** + * Create a Table object. + * @param {object} options - Configuration object. + */ +function Table(options) { + if (!(this instanceof Table)) { + return new Table(options); + } +} + +Table.prototype.setMetadata = function() { + throw new Error('Not implemented.'); +}; + + +Table.prototype.getMetadata = function() { + throw new Error('Not implemented.'); +}; + +/** + * Insert rows into the table. + * + * @param {object|[object]} rows - Rows of data to insert into table. + * @param {Function} callback - The callback function. + * + * @example + * + * myTable.insert() + */ +Table.prototype.insert = function(rows, callback) { + throw new Error('Not implemented.'); +}; + +module.exports = Table; diff --git a/lib/bigquery/index.js b/lib/bigquery/index.js new file mode 100644 index 00000000000..dcfa7bb08d4 --- /dev/null +++ b/lib/bigquery/index.js @@ -0,0 +1,94 @@ +/*! + * Copyright 2014 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! + * @module storage + */ + +'use strict'; + +/** + * @type module:common/connection + * @private + */ +var conn = require('../common/connection.js'); + +/** + * @type module:common/util + * @private + */ +var util = require('../common/util.js'); + +/** + * Required scopes for Google Cloud BigQuery API. + * @const {array} + * @private + */ +var SCOPES = ['https://www.googleapis.com/auth/bigquery']; + +var Dataset = require('./dataset.js'); +var Job = require('./job.js'); + +function BigQuery(config) { + this.config = config || {}; +} + +// Datasets & Tables & Tabledata +BigQuery.prototype.dataset = function(datasetId) { + return new Dataset(datasetId); +}; + +BigQuery.prototype.createDataset = function(datasetId, callback) { + throw new Error('Not implemented.'); +}; + +/** + * List all or some of the BigQuery datasets. + * + * @param {object=} options - Configuration object + * @param {Function} callback - The callback function + * + * @example + * + * bigquery.getDatasets({ + * all: true, + * maxResults: someNumber + * }, + * function(err, datasets) {}); + */ +BigQuery.prototype.getDatasets = function(options, callback) { + throw new Error('Not implemented.'); +}; + +// Jobs +BigQuery.prototype.job = function(jobId) { + return new Job(jobId); +}; + +BigQuery.prototype.createJob = function(jobId, callback) { + throw new Error('Not implemented.'); +}; + +BigQuery.prototype.getJobs = function(callback) { + throw new Error('Not implemented.'); +}; + +// Projects +BigQuery.prototype.getProjects = function(callback) { + throw new Error('Not implemented.'); +}; + +module.exports = BigQuery; diff --git a/lib/bigquery/job.js b/lib/bigquery/job.js new file mode 100644 index 00000000000..267fcd1bd18 --- /dev/null +++ b/lib/bigquery/job.js @@ -0,0 +1,33 @@ +/*! + * Copyright 2014 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +'use strict'; + +function Job(options) { + if (!(this instanceof Job)) { + return new Job(options); + } +} + +Job.prototype.query = function(options, callback) { + throw new Error('Not implemented.'); +}; + +Job.prototype.getResults = function(callback) { + throw new Error('Not implemented.'); +}; + +module.exports = Job; diff --git a/lib/index.js b/lib/index.js index 3d01d7ca23c..19534e28b5f 100644 --- a/lib/index.js +++ b/lib/index.js @@ -44,6 +44,12 @@ var PubSub = require('./pubsub'); */ var Storage = require('./storage'); +/** + * @type {module:bigquery} + * @private + */ +var BigQuery = require('./bigquery'); + /** * There are two key ways to use the `gcloud` module. * @@ -98,6 +104,7 @@ var Storage = require('./storage'); */ function gcloud(config) { return { + bigquery: new BigQuery(config), datastore: new Datastore(config), pubsub: function(options) { options = options || {}; @@ -187,4 +194,6 @@ gcloud.pubsub = function(config) { */ gcloud.storage = Storage; +gcloud.bigquery = BigQuery; + module.exports = gcloud; diff --git a/test/bigquery/index.js b/test/bigquery/index.js new file mode 100644 index 00000000000..3e8ae4331a8 --- /dev/null +++ b/test/bigquery/index.js @@ -0,0 +1,30 @@ +/** + * Copyright 2014 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*global describe, it */ + +'use strict'; + +var assert = require('assert'); + +var gcloud = require('../../'); + + +describe.only('BigQuery', function() { + it('should exist', function() { + assert.equal(typeof gcloud.bigquery, 'function'); + }); +}); From 9ef4bff6646b0cef6e8a37f1782e025547653ed4 Mon Sep 17 00:00:00 2001 From: Ryan Seys Date: Fri, 17 Oct 2014 18:28:07 -0400 Subject: [PATCH 2/5] Add to stubs --- lib/bigquery/dataset.js | 52 ++++++++++++++++-- lib/bigquery/dataset.table.js | 26 ++++++--- lib/bigquery/index.js | 99 ++++++++++++++++++++++++++++++++--- lib/bigquery/job.js | 49 +++++++++++++++-- 4 files changed, 206 insertions(+), 20 deletions(-) diff --git a/lib/bigquery/dataset.js b/lib/bigquery/dataset.js index 5e0647ac56a..5a13f8151c9 100644 --- a/lib/bigquery/dataset.js +++ b/lib/bigquery/dataset.js @@ -69,7 +69,23 @@ Dataset.prototype.getMetadata = function(callback) { throw new Error('Not implemented.'); }; -// options.force will force deletion +/** + * Delete the dataset. + * + * @param {object=} options - The configuration object. + * @param {boolean} options.force - Force delete dataset and all tables. + * @param {Function} callback - The callback function. + * + * @example + * + * myDataset.delete(function(err) { + * // Deletes a dataset only if it does not have any tables. + * }); + * + * myDataset.delete({ force: true }, function(err) { + * // Deletes dataset and any tables it contains. + * }); + */ Dataset.prototype.delete = function(options, callback) { throw new Error('Not implemented.'); }; @@ -90,7 +106,7 @@ Dataset.prototype.table = function(tableId) { /** * Create a table given a tableId or configuration object. * - * @param {string|object} tableId - Table id or configuration object. + * @param {string|object} options - Table id or configuration object. * @param {Function} callback - The callback function. * * @example @@ -98,8 +114,38 @@ Dataset.prototype.table = function(tableId) { * myDataset.createTable('customers', function(err, table) { * // use the table * }); + * + * @example + * + * var tableConfig = { + * id: 'my-kittens' + * schema: { + * fields: [ + * { name: “breed”, type: “STRING” } + * ] + * } + * }; + * + * myDataset.createTable(tableConfig) + */ +Dataset.prototype.createTable = function(options, callback) { + throw new Error('Not implemented.'); +}; + +/** + * Get a list of tables. + * + * @example + * + * var myDataset = bigquery.dataset(datasetId); + * myDataset.getTables(function(err, tables) { + * // use tables + * }); + * + * @param {object=} options - The configuration object. + * @param {Function} callback - The callback function. */ -Dataset.prototype.createTable = function(tableId, callback) { +Dataset.prototype.getTables = function(options, callback) { throw new Error('Not implemented.'); }; diff --git a/lib/bigquery/dataset.table.js b/lib/bigquery/dataset.table.js index 75755131247..3fbff5156c9 100644 --- a/lib/bigquery/dataset.table.js +++ b/lib/bigquery/dataset.table.js @@ -18,19 +18,19 @@ /** * Create a Table object. - * @param {object} options - Configuration object. + * @param {string} tableId - The id of the table. */ -function Table(options) { +function Table(tableId) { if (!(this instanceof Table)) { - return new Table(options); + return new Table(tableId); } + this.id = tableId; } Table.prototype.setMetadata = function() { throw new Error('Not implemented.'); }; - Table.prototype.getMetadata = function() { throw new Error('Not implemented.'); }; @@ -41,11 +41,25 @@ Table.prototype.getMetadata = function() { * @param {object|[object]} rows - Rows of data to insert into table. * @param {Function} callback - The callback function. * + * TODO: Add example. + */ +Table.prototype.insert = function(rows, callback) { + throw new Error('Not implemented.'); +}; + +/** + * Delete a table and all its data. + * + * @param {object=} options - Configuration object. + * @param {Function} callback - The callback function. + * * @example * - * myTable.insert() + * myTable.delete(function(err) { + * // Deletes table and all its data. + * }); */ -Table.prototype.insert = function(rows, callback) { +Table.prototype.delete = function(options, callback) { throw new Error('Not implemented.'); }; diff --git a/lib/bigquery/index.js b/lib/bigquery/index.js index dcfa7bb08d4..561ad4bc023 100644 --- a/lib/bigquery/index.js +++ b/lib/bigquery/index.js @@ -34,6 +34,7 @@ var util = require('../common/util.js'); /** * Required scopes for Google Cloud BigQuery API. + * * @const {array} * @private */ @@ -42,15 +43,36 @@ var SCOPES = ['https://www.googleapis.com/auth/bigquery']; var Dataset = require('./dataset.js'); var Job = require('./job.js'); +/** + * BigQuery API client. + * + * @param {object=} config - The configuration object. + */ function BigQuery(config) { this.config = config || {}; } -// Datasets & Tables & Tabledata +/** + * Create a reference to an existing dataset. + * + * @param {string} datasetId - Id of the dataset. + * @return {Dataset} Reference to existing Dataset. + */ BigQuery.prototype.dataset = function(datasetId) { return new Dataset(datasetId); }; +/** + * Create a dataset. + * @param {string} datasetId - The dataset id. + * @param {Function} callback - The callback function. + * + * @example + * + * bigquery.createDataset('my-kittens', function(err, dataset) { + * // Use the newly created Dataset to create tables. + * }); + */ BigQuery.prototype.createDataset = function(datasetId, callback) { throw new Error('Not implemented.'); }; @@ -58,8 +80,8 @@ BigQuery.prototype.createDataset = function(datasetId, callback) { /** * List all or some of the BigQuery datasets. * - * @param {object=} options - Configuration object - * @param {Function} callback - The callback function + * @param {object=} options - Configuration object. + * @param {Function} callback - The callback function. * * @example * @@ -73,21 +95,82 @@ BigQuery.prototype.getDatasets = function(options, callback) { throw new Error('Not implemented.'); }; -// Jobs +/** + * Create a reference to an existing Job. + * + * @param {string} jobId - Id of the job. + * @return {Job} Reference to existing Job. + * + * @example + * + * var myExistingJob = bigquery.job('my-job-id'); + */ BigQuery.prototype.job = function(jobId) { return new Job(jobId); }; -BigQuery.prototype.createJob = function(jobId, callback) { +/** + * Create a new job. + * + * @param {object} config - The configuration object. + * @param {Function} callback - The callback function. + * + * @example + * + * var config = { + * + * }; + * bigquery.createJob(config, function(err, job) { + * // Use your newly created job. + * }); + */ +BigQuery.prototype.createJob = function(options, callback) { throw new Error('Not implemented.'); }; -BigQuery.prototype.getJobs = function(callback) { +/** + * Get the list of jobs. + * + * @example + * + * bigquery.getJobs(function(err, jobs) { + * // Use list of jobs here. + * }); + * + * var options = { + * limit: 3 // only show max 3 results + * }; + * bigquery.getJobs(options, function(err, jobs) { + * // Use list of jobs here. + * }); + * + * @param {object=} options - Configuration object + * @param {Function} callback - The callback function. + */ +BigQuery.prototype.getJobs = function(options, callback) { throw new Error('Not implemented.'); }; -// Projects -BigQuery.prototype.getProjects = function(callback) { +/** + * Get the list of projects. + * + * @param {object=} options - The configuration object. + * @param {Function} callback - The callback function. + * + * @example + * + * bigquery.getProjects(function(err, projects) { + * // Use list of projects here. + * }); + * + * var options = { + * limit: 3 // only show max 3 results + * }; + * bigquery.getProjects(options, function(err, projects) { + * // Use list of projects here. + * }); + */ +BigQuery.prototype.getProjects = function(options, callback) { throw new Error('Not implemented.'); }; diff --git a/lib/bigquery/job.js b/lib/bigquery/job.js index 267fcd1bd18..32d6efc62c5 100644 --- a/lib/bigquery/job.js +++ b/lib/bigquery/job.js @@ -16,17 +16,60 @@ 'use strict'; -function Job(options) { +/** + * Create a job. + * + * @param {string} jobId - The id of the job. + * @return {Job} The Job object. + */ +function Job(jobId) { if (!(this instanceof Job)) { - return new Job(options); + return new Job(jobId); } + this.id = jobId; } +/** + * Run a query. + * + * var myQuery = { + * query: ‘SELECT * FROM users’, + * dryRun: true, + * maxResults: 123, + * useQueryCache: false, + * + * // automatically concat pages + * // together up to maxResults limit. + * auto: true + * }; + * + * var myJob = bigquery.job(jobId); + * + * myJob.query(myQuery, function(err, results) { + * if(err) { + * // An actual error occurred. + * } + * if(results.timedout) { + * // No results because job still going... + * } else { + * // Results returned. + * } + * }); + * + * @param {object} options - The configuration object. + * @param {Function} callback - The callback function. + */ Job.prototype.query = function(options, callback) { throw new Error('Not implemented.'); }; -Job.prototype.getResults = function(callback) { +/** + * Get the results of a job. + * + * @param {object=} options - The configuration object. + * @param {Function} callback - The callback function. + */ +Job.prototype.getResults = function(options, callback) { throw new Error('Not implemented.'); }; From 55bfcecd474f795ca76b42a21237c8e6aeaa6d92 Mon Sep 17 00:00:00 2001 From: Ryan Seys Date: Sat, 18 Oct 2014 01:08:01 -0400 Subject: [PATCH 3/5] Update stubs --- lib/bigquery/dataset.js | 19 +++-- lib/bigquery/dataset.table.js | 142 ++++++++++++++++++++++++++++++++-- lib/bigquery/index.js | 32 ++++++++ 3 files changed, 180 insertions(+), 13 deletions(-) diff --git a/lib/bigquery/dataset.js b/lib/bigquery/dataset.js index 5a13f8151c9..092b7b5b13b 100644 --- a/lib/bigquery/dataset.js +++ b/lib/bigquery/dataset.js @@ -107,6 +107,16 @@ Dataset.prototype.table = function(tableId) { * Create a table given a tableId or configuration object. * * @param {string|object} options - Table id or configuration object. + * @param {string} options.id - The id of the table. + * @param {string|object} options.schema - A comma-separated list of name:type + * pairs. Valid types are "string", + * "integer", "float", "boolean", and + * "timestamp". If the type is omitted, + * it is assumed to be "string". Example: + * name:string, age:integer Schemas can + * also be specified as a JSON array of + * fields, which allows for nested and + * repeated fields. * @param {Function} callback - The callback function. * * @example @@ -118,12 +128,9 @@ Dataset.prototype.table = function(tableId) { * @example * * var tableConfig = { - * id: 'my-kittens' - * schema: { - * fields: [ - * { name: “breed”, type: “STRING” } - * ] - * } + * id: 'my-kittens', + * // breed and name are defaulted to type = string + * schema: 'id:integer,breed,name,dob:timestamp' // or json nested fields * }; * * myDataset.createTable(tableConfig) diff --git a/lib/bigquery/dataset.table.js b/lib/bigquery/dataset.table.js index 3fbff5156c9..d6b507b7aaa 100644 --- a/lib/bigquery/dataset.table.js +++ b/lib/bigquery/dataset.table.js @@ -18,6 +18,7 @@ /** * Create a Table object. + * * @param {string} tableId - The id of the table. */ function Table(tableId) { @@ -27,30 +28,105 @@ function Table(tableId) { this.id = tableId; } -Table.prototype.setMetadata = function() { +/** + * Set the metadata on the table. + * + * TODO: Figure out what metadata can *actually* be set. + * TODO: Can columns be added? Removed? + * + * @param {object} metadata - The metadata key/value object to set. + * @param {Function} callback - The callback function. + */ +Table.prototype.setMetadata = function(metadata, callback) { throw new Error('Not implemented.'); }; -Table.prototype.getMetadata = function() { +/** + * Return the metadata associated with the Table. + * + * @param {Function} callback - The callback function. + * + * @example + * + * myTable.getMetadata(function(err, metadata) { + * // Use Table metadata here. + * }); + */ +Table.prototype.getMetadata = function(callback) { throw new Error('Not implemented.'); }; /** - * Insert rows into the table. + * Load data from a filename, gs:// url, readable stream, or raw string. + * By loading data this way, you create a load job that will run your + * data load asynchronously. If you would like instantaneous access to + * your data in BigQuery, insert it using Table#insert(). * - * @param {object|[object]} rows - Rows of data to insert into table. + * @param {object} options - The configuration object. * @param {Function} callback - The callback function. * - * TODO: Add example. + * TODO: Decide on param key names here for different types of data input. + * var options = { + * url: 'gs://my-bucket/my-data.csv', + * filename: '/Users/ryanseys/my-data.csv', + * data: 'hello,world,123', + * + * format: 'csv', // or json + * delimiter: ';', + * skipHeaderRows: 1, + * numErrorsAllowed: 0, + * allowQuotedNewlines: false, + * allowJaggedRows: false, + * ignoreUnknowns: false + * // these options will change as necessary + * }; + * */ -Table.prototype.insert = function(rows, callback) { +Table.prototype.load = function(options, callback) { + throw new Error('Not implemented.'); +}; + +/** + * Create a write stream out of the table to allow data to be loaded + * via a piped stream. + * + * @return {WritableStream} The writable stream object. + * + * @example + * + * var bigDataTable = myTable.createWriteStream({ type: 'csv' }); + * fs.createReadStream('big-data.csv').pipe(bigDataTable); + */ +Table.prototype.createWriteStream = function(options) { + throw new Error('Not implemented.'); +}; + +/** + * Export table to Google Cloud Storage. + * + * @param {object} options - The configuration object. + * @param {Function} callback - The callback function. + * + * @example + * + * var exportedFile = storage.bucket('my-bucket').file('export.csv'); + * var options = { + * format: 'json', + * gzip: true, // or false (default) + * dest: exportedFile // or 'gs://my-bucket/export.csv' (accepts wildcards) + * }; + * myTable.export(options, function(err) { + * // Exported! + * }); + */ +Table.prototype.export = function(options, callback) { throw new Error('Not implemented.'); }; /** * Delete a table and all its data. * - * @param {object=} options - Configuration object. + * @param {object=} options - Configuration object. * @param {Function} callback - The callback function. * * @example @@ -63,4 +139,56 @@ Table.prototype.delete = function(options, callback) { throw new Error('Not implemented.'); }; +/** + * Retrieves table data from a specified set of rows. + * + * @param {object=} options - The configuration object. + * @param {Function} callback - The callback function. + * + * @example + * + * var options = { + * maxResults: 123, + * startIndex: 0, + * pageToken: 'token' + * // TODO: We should automatically handle pagination. + * }; + * myTable.getRows(options, function(err, rows) { + * // Use rows here. + * }); + */ +Table.prototype.getRows = function(options, callback) { + throw new Error('Not implemented.'); +}; + +/** + * Stream data into BigQuery one record at a time without running a load job. + * + * There are more strict quota limits using this method so it is highly + * recommended that you load data into BigQuery using Table#load() instead. + * The one advantage to using this method is that data is immediately + * available in BigQuery, where as Table#load()-ing may take time to process. + * + * @param {object} options - The configuration object. + * @param {Function} callback - The callback function. + * + * @example + * + * myTable.insert({ dept: 'FILM', code: '1001', capacity: 42 }, function(err) { + * // Inserted the row. + * }); + * + * var rows = [ + * { dept: 'FILM', code: '1001', capacity: 42 }, + * { dept: 'PHIL', code: '1002', capacity: 84 }, + * ]; + * + * myTable.insert(rows, function(err) { + * // Inserted the rows. + * }); + */ +Table.prototype.insert = function(options, callback) { + throw new Error('Not implemented.'); +}; + module.exports = Table; diff --git a/lib/bigquery/index.js b/lib/bigquery/index.js index 561ad4bc023..b396dfe3624 100644 --- a/lib/bigquery/index.js +++ b/lib/bigquery/index.js @@ -174,4 +174,36 @@ BigQuery.prototype.getProjects = function(options, callback) { throw new Error('Not implemented.'); }; +/** + * Run a query in BigQuery. + * + * var myQuery = { + * query: ‘SELECT * FROM users’, + * dryRun: true, + * maxResults: 123, + * useQueryCache: false, + * + * // Automatically concat pages together up to maxResults limit. + * auto: true + * }; + * + * bigquery.query(myQuery, function(err, results) { + * if(err) { + * // An actual error occurred. + * } + * if(!results.jobCompleted) { + * // No results because job still going... + * } else { + * // Results is just what was returned from BigQuery for now. + * // TODO: Is there a better format that we can return results in? + * } + * }); + * + * @param {object} options - The configuration object. + * @param {Function} callback - The callback function. + */ +BigQuery.prototype.query = function(options, callback) { + throw new Error('Not implemented.'); +}; + module.exports = BigQuery; From aa18ea70eae539d2822a58d34add6ae028b192fd Mon Sep 17 00:00:00 2001 From: Ryan Seys Date: Sat, 18 Oct 2014 03:05:29 -0400 Subject: [PATCH 4/5] Fix test and add Table#copy --- lib/bigquery/dataset.table.js | 24 ++++++++++++++++++++++++ test/bigquery/index.js | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/bigquery/dataset.table.js b/lib/bigquery/dataset.table.js index d6b507b7aaa..063ad3b8130 100644 --- a/lib/bigquery/dataset.table.js +++ b/lib/bigquery/dataset.table.js @@ -191,4 +191,28 @@ Table.prototype.insert = function(options, callback) { throw new Error('Not implemented.'); }; +/** + * Copy data from one table to another, optionally creating that table. + * + * @param {object|string} options - The dest table or configuration object. + * @param {Function} callback - The callback function. + * + * @example + * + * myTable.copy(destTable, function(err, job) { + * // Job created to copy data. + * }); + * + * var options = { + * dest: destTable, + * allowCreate: false // default is true + * }; + * myTable.copy(options, function(err, job) { + * // Job created to copy data. + * }); + */ +Table.prototype.copy = function(options, callback) { + throw new Error('Not implemented.'); +}; + module.exports = Table; diff --git a/test/bigquery/index.js b/test/bigquery/index.js index 3e8ae4331a8..335f2e722f4 100644 --- a/test/bigquery/index.js +++ b/test/bigquery/index.js @@ -23,7 +23,7 @@ var assert = require('assert'); var gcloud = require('../../'); -describe.only('BigQuery', function() { +describe('BigQuery', function() { it('should exist', function() { assert.equal(typeof gcloud.bigquery, 'function'); }); From 8e98d35657bf7b08f026e30e9174f7e2e1a4ecaa Mon Sep 17 00:00:00 2001 From: Ryan Seys Date: Sat, 18 Oct 2014 03:16:27 -0400 Subject: [PATCH 5/5] Add Job#getMetadata and clean up --- lib/bigquery/dataset.js | 20 ++++++++++++-------- lib/bigquery/index.js | 2 +- lib/bigquery/job.js | 15 +++++++++++++++ 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/lib/bigquery/dataset.js b/lib/bigquery/dataset.js index 092b7b5b13b..82a648dd84c 100644 --- a/lib/bigquery/dataset.js +++ b/lib/bigquery/dataset.js @@ -95,6 +95,10 @@ Dataset.prototype.delete = function(options, callback) { * * @param {string} tableId - The id of the table. * @return {Table} Reference to existing Table object. + * + * @example + * + * var kittens = myDataset.table('my-kittens'); */ Dataset.prototype.table = function(tableId) { return new Table({ @@ -122,18 +126,18 @@ Dataset.prototype.table = function(tableId) { * @example * * myDataset.createTable('customers', function(err, table) { - * // use the table + * // Use the table. * }); * - * @example - * * var tableConfig = { * id: 'my-kittens', * // breed and name are defaulted to type = string * schema: 'id:integer,breed,name,dob:timestamp' // or json nested fields * }; * - * myDataset.createTable(tableConfig) + * myDataset.createTable(tableConfig, function(err, table) { + * // Use the table. + * }); */ Dataset.prototype.createTable = function(options, callback) { throw new Error('Not implemented.'); @@ -142,15 +146,15 @@ Dataset.prototype.createTable = function(options, callback) { /** * Get a list of tables. * + * @param {object=} options - The configuration object. + * @param {Function} callback - The callback function. + * * @example * * var myDataset = bigquery.dataset(datasetId); * myDataset.getTables(function(err, tables) { - * // use tables + * // Use the tables. * }); - * - * @param {object=} options - The configuration object. - * @param {Function} callback - The callback function. */ Dataset.prototype.getTables = function(options, callback) { throw new Error('Not implemented.'); diff --git a/lib/bigquery/index.js b/lib/bigquery/index.js index b396dfe3624..bc056ce9ffc 100644 --- a/lib/bigquery/index.js +++ b/lib/bigquery/index.js @@ -199,7 +199,7 @@ BigQuery.prototype.getProjects = function(options, callback) { * } * }); * - * @param {object} options - The configuration object. + * @param {object} options - The configuration object. * @param {Function} callback - The callback function. */ BigQuery.prototype.query = function(options, callback) { diff --git a/lib/bigquery/job.js b/lib/bigquery/job.js index 32d6efc62c5..56625566572 100644 --- a/lib/bigquery/job.js +++ b/lib/bigquery/job.js @@ -29,6 +29,21 @@ function Job(jobId) { this.id = jobId; } +/** + * Get the Job resource for the job. + * + * @param {Function} callback - The callback function. + * + * @example + * + * myJob.getMetadata(function(err, metadata) { + * // Use the metadata (myJob has been updated too). + * }); + */ +Job.prototype.getMetadata = function(callback) { + throw new Error('Not implemented.'); +}; + /** * Run a query. *