Class Dataset (5.10.0)

Interact with your BigQuery dataset. Create a Dataset instance with or .

Inheritance

ServiceObject > Dataset

Package

@google-cloud/bigquery

Example


const {BigQuery} = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
const dataset = bigquery.dataset('institutions');

Constructors

(constructor)(bigQuery, id, options)

constructor(bigQuery: BigQuery, id: string, options?: DatasetOptions);

Constructs a new instance of the Dataset class

Parameters
NameDescription
bigQuery BigQuery
id string
options DatasetOptions

Properties

bigQuery

bigQuery: BigQuery;

location

location?: string;

Methods

createQueryJob(options)

createQueryJob(options: string | Query): Promise<JobResponse>;

Run a query as a job. No results are immediately returned. Instead, your callback will be executed with a Job object that you must ping for the results. See the Job documentation for explanations of how to check on the status of the job.

See for full documentation of this method.

Parameter
NameDescription
options string | Query

See for full documentation of this method.

Returns
TypeDescription
Promise<JobResponse>

{Promise

createQueryJob(options, callback)

createQueryJob(options: string | Query, callback: JobCallback): void;
Parameters
NameDescription
options string | Query
callback JobCallback
Returns
TypeDescription
void

createQueryStream(options)

createQueryStream(options: Query | string): Duplex;

Run a query scoped to your dataset as a readable object stream.

See for full documentation of this method.

Parameter
NameDescription
options Query | string

See for full documentation of this method.

Returns
TypeDescription
Duplex

{stream}

createRoutine(id, config)

createRoutine(id: string, config: RoutineMetadata): Promise<RoutineResponse>;
Parameters
NameDescription
id string

The routine ID.

config RoutineMetadata

A [routine resource]https://cloud.google.com/bigquery/docs/reference/rest/v2/routines#Routine.

Returns
TypeDescription
Promise<RoutineResponse>

{Promise

Examples

const {BigQuery} = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
const dataset = bigquery.dataset('my-dataset');

const id = 'my-routine';
const config = {
  arguments: [{
    name: 'x',
    dataType: {
      typeKind: 'INT64'
    }
  }],
  definitionBody: 'x * 3',
  routineType: 'SCALAR_FUNCTION',
  returnType: {
    typeKind: 'INT64'
  }
};

dataset.createRoutine(id, config, (err, routine, apiResponse) => {
  if (!err) {
    // The routine was created successfully.
  }
});

If the callback is omitted a Promise will be returned


const [routine, apiResponse] = await dataset.createRoutine(id, config);

createRoutine(id, config, callback)

createRoutine(id: string, config: RoutineMetadata, callback: RoutineCallback): void;
Parameters
NameDescription
id string
config RoutineMetadata
callback RoutineCallback
Returns
TypeDescription
void

createTable(id, options)

createTable(id: string, options: TableMetadata): Promise<TableResponse>;

Create a Table given a tableId or configuration object.

See Tables: insert API Documentation

Parameters
NameDescription
id string

Table id.

options TableMetadata

See a Table resource.

Returns
TypeDescription
Promise<TableResponse>

{Promise

Example

const {BigQuery} = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
const dataset = bigquery.dataset('institutions');

const tableId = 'institution_data';

const options = {
  // From the data.gov CSV dataset (http://goo.gl/kSE7z6):
  schema: 'UNITID,INSTNM,ADDR,CITY,STABBR,ZIP,FIPS,OBEREG,CHFNM,...'
};

dataset.createTable(tableId, options, (err, table, apiResponse) => {});

//-
// If the callback is omitted, we'll return a Promise.
//-
dataset.createTable(tableId, options).then((data) => {
  const table = data[0];
  const apiResponse = data[1];
});

createTable(id, options, callback)

createTable(id: string, options: TableMetadata, callback: TableCallback): void;
Parameters
NameDescription
id string
options TableMetadata
callback TableCallback
Returns
TypeDescription
void

createTable(id, callback)

createTable(id: string, callback: TableCallback): void;
Parameters
NameDescription
id string
callback TableCallback
Returns
TypeDescription
void

delete(options)

delete(options?: DatasetDeleteOptions): Promise<[Metadata]>;

Delete the dataset.

See Datasets: delete API Documentation

Parameter
NameDescription
options DatasetDeleteOptions

The configuration object.

Returns
TypeDescription
Promise<[Metadata]>

{Promise

Example

const {BigQuery} = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
const dataset = bigquery.dataset('institutions');

//-
// Delete the dataset, only if it does not have any tables.
//-
dataset.delete((err, apiResponse) => {});

//-
// Delete the dataset and any tables it contains.
//-
dataset.delete({ force: true }, (err, apiResponse) => {});

//-
// If the callback is omitted, we'll return a Promise.
//-
dataset.delete().then((data) => {
  const apiResponse = data[0];
});

delete(options, callback)

delete(options: DatasetDeleteOptions, callback: DeleteCallback): void;
Parameters
NameDescription
options DatasetDeleteOptions
callback DeleteCallback
Returns
TypeDescription
void

delete(callback)

delete(callback: DeleteCallback): void;
Parameter
NameDescription
callback DeleteCallback
Returns
TypeDescription
void

getModels(options)

getModels(options?: GetModelsOptions): Promise<GetModelsResponse>;

Get a list of Model resources.

See Models: list API Documentation

Parameter
NameDescription
options GetModelsOptions

Configuration object.

Returns
TypeDescription
Promise<GetModelsResponse>

{Promise

Examples

const {BigQuery} = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
const dataset = bigquery.dataset('institutions');

dataset.getModels((err, models) => {
  // models is an array of `Model` objects.
});

To control how many API requests are made and page through the results manually, set autoPaginate to false.


function manualPaginationCallback(err, models, nextQuery, apiResponse) {
  if (nextQuery) {
    // More results exist.
    dataset.getModels(nextQuery, manualPaginationCallback);
  }
}

dataset.getModels({
  autoPaginate: false
}, manualPaginationCallback);

If the callback is omitted, we'll return a Promise.


dataset.getModels().then((data) => {
  const models = data[0];
});

getModels(options, callback)

getModels(options: GetModelsOptions, callback: GetModelsCallback): void;
Parameters
NameDescription
options GetModelsOptions
callback GetModelsCallback
Returns
TypeDescription
void

getModels(callback)

getModels(callback: GetModelsCallback): void;
Parameter
NameDescription
callback GetModelsCallback
Returns
TypeDescription
void

getModelsStream(options)

getModelsStream(options?: GetModelsOptions): ResourceStream<Model>;
Parameter
NameDescription
options GetModelsOptions
Returns
TypeDescription
ResourceStream<Model>

getRoutines(options)

getRoutines(options?: GetRoutinesOptions): Promise<GetRoutinesResponse>;

Get a list of routines.

See Routines: list API Documentation

Parameter
NameDescription
options GetRoutinesOptions

Request options.

Returns
TypeDescription
Promise<GetRoutinesResponse>

{Promise

Examples

const {BigQuery} = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
const dataset = bigquery.dataset('institutions');

dataset.getRoutines((err, routines) => {
  // routines is an array of `Routine` objects.
});

To control how many API requests are made and page through the results manually, set autoPaginate to false.


function manualPaginationCallback(err, routines, nextQuery, apiResponse) {
  if (nextQuery) {
    // More results exist.
    dataset.getRoutines(nextQuery, manualPaginationCallback);
  }
}

dataset.getRoutines({
  autoPaginate: false
}, manualPaginationCallback);

If the callback is omitted a Promise will be returned


const [routines] = await dataset.getRoutines();

getRoutines(options, callback)

getRoutines(options: GetRoutinesOptions, callback: GetRoutinesCallback): void;
Parameters
NameDescription
options GetRoutinesOptions
callback GetRoutinesCallback
Returns
TypeDescription
void

getRoutines(callback)

getRoutines(callback: GetRoutinesCallback): void;
Parameter
NameDescription
callback GetRoutinesCallback
Returns
TypeDescription
void

getRoutinesStream(options)

getRoutinesStream(options?: GetRoutinesOptions): ResourceStream<Routine>;
Parameter
NameDescription
options GetRoutinesOptions
Returns
TypeDescription
ResourceStream<Routine>

getTables(options)

getTables(options?: GetTablesOptions): Promise<GetTablesResponse>;

Get a list of Table resources.

See Tables: list API Documentation

Parameter
NameDescription
options GetTablesOptions

Configuration object.

Returns
TypeDescription
Promise<GetTablesResponse>

{Promise

Example

const {BigQuery} = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
const dataset = bigquery.dataset('institutions');

dataset.getTables((err, tables) => {
  // tables is an array of `Table` objects.
});

//-
// To control how many API requests are made and page through the results
// manually, set `autoPaginate` to `false`.
//-
function manualPaginationCallback(err, tables, nextQuery, apiResponse) {
  if (nextQuery) {
    // More results exist.
    dataset.getTables(nextQuery, manualPaginationCallback);
  }
}

dataset.getTables({
  autoPaginate: false
}, manualPaginationCallback);

//-
// If the callback is omitted, we'll return a Promise.
//-
dataset.getTables().then((data) => {
  const tables = data[0];
});

getTables(options, callback)

getTables(options: GetTablesOptions, callback: GetTablesCallback): void;
Parameters
NameDescription
options GetTablesOptions
callback GetTablesCallback
Returns
TypeDescription
void

getTables(callback)

getTables(callback: GetTablesCallback): void;
Parameter
NameDescription
callback GetTablesCallback
Returns
TypeDescription
void

getTablesStream(options)

getTablesStream(options?: GetTablesOptions): ResourceStream<Table>;
Parameter
NameDescription
options GetTablesOptions
Returns
TypeDescription
ResourceStream<Table>

model(id)

model(id: string): Model;

Create a Model object.

Parameter
NameDescription
id string

The ID of the model. {Model}

Returns
TypeDescription
Model
Example

const {BigQuery} = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
const dataset = bigquery.dataset('institutions');

const model = dataset.model('my-model');

query(options)

query(options: Query): Promise<QueryRowsResponse>;

Run a query scoped to your dataset.

See for full documentation of this method.

Parameter
NameDescription
options Query

See for full documentation of this method.

Returns
TypeDescription
Promise<QueryRowsResponse>

{Promise

query(options)

query(options: string): Promise<QueryRowsResponse>;
Parameter
NameDescription
options string
Returns
TypeDescription
Promise<QueryRowsResponse>

query(options, callback)

query(options: Query, callback: SimpleQueryRowsCallback): void;
Parameters
NameDescription
options Query
callback SimpleQueryRowsCallback
Returns
TypeDescription
void

query(options, callback)

query(options: string, callback: SimpleQueryRowsCallback): void;
Parameters
NameDescription
options string
callback SimpleQueryRowsCallback
Returns
TypeDescription
void

routine(id)

routine(id: string): Routine;

Create a Routine object.

Parameter
NameDescription
id string

The ID of the routine.

Returns
TypeDescription
Routine

{Routine}

Example

const {BigQuery} = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
const dataset = bigquery.dataset('institutions');

const routine = dataset.routine('my_routine');

table(id, options)

table(id: string, options?: TableOptions): Table;

Create a Table object.

Parameters
NameDescription
id string

The ID of the table.

options TableOptions

Table options.

Returns
TypeDescription
Table
Example

const {BigQuery} = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
const dataset = bigquery.dataset('institutions');

const institutions = dataset.table('institution_data');