Class DataSourceSpecBuilder

  • DataSourceSpecBuilder is used to create a specification for data sources connected to a database.

  • To start building a specification, use SpreadsheetApp.newDataSourceSpec().

  • Specific database types like BigQuery and Looker have dedicated builder methods like asBigQuery() and asLooker().

  • The build() method is used to finalize the specification from the builder's settings.

DataSourceSpecBuilder

The builder forDataSourceSpec. To create a specification for certain type, useas...() method. To create a new builder, useSpreadsheetApp.newDataSourceSpec(). To use the specification, seeDataSourceTable.

Only use this class with data that's connected to a database.

This example shows how to build a BigQuery data source specification.

constspec=SpreadsheetApp.newDataSourceSpec().asBigQuery().setProjectId('big_query_project').setRawQuery('select @FIELD from table limit @LIMIT').setParameterFromCell('FIELD','Sheet1!A1').setParameterFromCell('LIMIT','namedRangeCell').build();

This example shows how to build a Looker data source specification. It returns aLookerDataSourceSpec object after usingbuild().

constspec=SpreadsheetApp.newDataSourceSpec().asLooker().setInstanceUrl('https://looker_instance_url.com').setModelName('model_name').setExploreName('explore_name').build();

Methods

MethodReturn typeBrief description
asBigQuery()BigQueryDataSourceSpecBuilderGets the builder for BigQuery data source.
asLooker()LookerDataSourceSpecBuilderGets the builder for Looker data source.
build()DataSourceSpecBuilds a data source specification from the settings in this builder.
copy()DataSourceSpecBuilderCreates aDataSourceSpecBuilder based on this data source's settings.
getParameters()DataSourceParameter[]Gets the parameters of the data source.
getType()DataSourceTypeGets the type of the data source.
removeAllParameters()DataSourceSpecBuilderRemoves all the parameters.
removeParameter(parameterName)DataSourceSpecBuilderRemoves the specified parameter.
setParameterFromCell(parameterName, sourceCell)DataSourceSpecBuilderAdds a parameter, or if the parameter with the name exists, updates its source cell for datasource spec builders of typeDataSourceType.BIGQUERY.

Detailed documentation

asBigQuery()

Gets the builder for BigQuery data source.

Return

BigQueryDataSourceSpecBuilder — The BigQuery data source specification builder.


asLooker()

Gets the builder for Looker data source.

constspec=SpreadsheetApp.newDataSourceSpec().asLooker().setInstanceUrl('https://looker_instance_url.com').setModelName('model_name').setExploreName('explore_name').build();

Return

LookerDataSourceSpecBuilder — The Looker data source specification builder.


build()

Builds a data source specification from the settings in this builder. Must useas...()to specify a data source type before building.

The following code sample builds a BigQuery DataSource Spec.

constbigQueryDataSourceSpec=SpreadsheetApp.newDataSourceSpec().asBigQuery();// TODO(developer): Replace with the required dataset, project and table IDs.bigQueryDataSourceSpec.setDatasetId('my data set id');bigQueryDataSourceSpec.setProjectId('my project id');bigQueryDataSourceSpec.setTableId('my table id');bigQueryDataSourceSpec.build();

The following code sample builds a Looker DataSource Spec.

constlookerDataSourceSpecBuilder=SpreadsheetApp.newDataSourceSpec().asLooker();constlookerSpec=lookerDataSourceSpecBuilder.setExploreName('my explore name').setInstanceUrl('my instance url').setModelName('my model name').build();

Return

DataSourceSpec — The data source specification.


copy()

Creates aDataSourceSpecBuilder based on this data source's settings.

// TODO(developer): Replace the URL with your own.constss=SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit',);constspec=ss.getDataSources()[0].getSpec();constnewSpec=spec.copy();

Return

DataSourceSpecBuilder — The builder.


getParameters()

Gets the parameters of the data source.

// TODO(developer): Replace the URL with your own.constss=SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit',);constspec=ss.getDataSources()[0].getSpec();constparameters=spec.getParameters();

This method is only available for BigQuery data sources.

Return

DataSourceParameter[] — The parameter list.


getType()

Gets the type of the data source.

// TODO(developer): Replace the URL with your own.constss=SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit',);constspec=ss.getDataSources()[0].getSpec();consttype=spec.getType();

Return

DataSourceType — The data source type.


removeAllParameters()

Removes all the parameters.

constspecBuilder=SpreadsheetApp.newDataSourceSpec();specBuilder.removeAllParameters();

Return

DataSourceSpecBuilder — The builder, for chaining.


removeParameter(parameterName)

Removes the specified parameter.

constspecBuilder=SpreadsheetApp.newDataSourceSpec();specBuilder.removeParameter('x');

Parameters

NameTypeDescription
parameterNameStringThe name of the parameter to remove.

Return

DataSourceSpecBuilder — The builder, for chaining.


setParameterFromCell(parameterName, sourceCell)

Adds a parameter, or if the parameter with the name exists, updates its source cell for datasource spec builders of typeDataSourceType.BIGQUERY.

This method is only available for BigQuery data sources.

constspecBuilder=SpreadsheetApp.newDataSourceSpec().asBigQuery();specBuilder.setParameterFromCell('x','A1');constbigQuerySpec=specBuilder.build();

Parameters

NameTypeDescription
parameterNameStringThe parameter name.
sourceCellStringThe source cell, as specified in A1 notation.

Return

DataSourceSpecBuilder — The builder, for chaining.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-11 UTC.