Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DO NOT MERGE: BigQuery API stubs #262

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
163 changes: 163 additions & 0 deletions lib/bigquery/dataset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
/*!
* 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.');
};

/**
* 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.');
};

/**
* 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.
*
* @example
*
* var kittens = myDataset.table('my-kittens');
*/
Dataset.prototype.table = function(tableId) {
return new Table({
dataset: this,
id: 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
*
* myDataset.createTable('customers', function(err, table) {
* // Use the table.
* });
*
* 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, function(err, table) {
* // Use the table.
* });
*/
Dataset.prototype.createTable = function(options, callback) {
throw new Error('Not implemented.');
};

/**
* 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 the tables.
* });
*/
Dataset.prototype.getTables = function(options, callback) {
throw new Error('Not implemented.');
};

module.exports = Dataset;
218 changes: 218 additions & 0 deletions lib/bigquery/dataset.table.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
/*!
* 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 {string} tableId - The id of the table.
*/
function Table(tableId) {
if (!(this instanceof Table)) {
return new Table(tableId);
}
this.id = tableId;
}

/**
* 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.');
};

/**
* 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.');
};

/**
* 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} options - The configuration object.
* @param {Function} callback - The callback function.
*
* 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.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 {Function} callback - The callback function.
*
* @example
*
* myTable.delete(function(err) {
* // Deletes table and all its data.
* });
*/
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.');
};

/**
* 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;
Loading