Class LookerDataSourceSpecBuilder

LookerDataSourceSpecBuilder

Trình tạo cho LookerDataSourceSpecBuilder.

Ví dụ này cho thấy cách tạo trình tạo Đặc tả nguồn dữ liệu Looker mới.

const lookerDataSourceSpecBuilder =
    SpreadsheetApp.newDataSourceSpec().asLooker();

Phương thức

Phương thứcKiểu dữ liệu trả vềMô tả ngắn
build()DataSourceSpecTạo đặc tả nguồn dữ liệu từ các chế độ cài đặt trong trình tạo này.
copy()DataSourceSpecBuilderTạo DataSourceSpecBuilder dựa trên các chế độ cài đặt của nguồn dữ liệu này.
getExploreName()StringLấy tên của bản khám phá Looker trong mô hình.
getInstanceUrl()StringLấy URL của thực thể Looker.
getModelName()StringLấy tên của mô hình Looker trong thực thể.
getParameters()DataSourceParameter[]Lấy các tham số của nguồn dữ liệu.
getType()DataSourceTypeLấy loại nguồn dữ liệu.
removeAllParameters()LookerDataSourceSpecBuilderXoá tất cả các tham số.
removeParameter(parameterName)LookerDataSourceSpecBuilderXoá tham số đã chỉ định.
setExploreName(exploreName)LookerDataSourceSpecBuilderĐặt tên bản khám phá trong mô hình Looker.
setInstanceUrl(instanceUrl)LookerDataSourceSpecBuilderĐặt URL thực thể cho Looker.
setModelName(modelName)LookerDataSourceSpecBuilderĐặt tên mô hình Looker trong thực thể Looker.
setParameterFromCell(parameterName, sourceCell)LookerDataSourceSpecBuilderThêm một tham số hoặc nếu tham số có tên tồn tại, hãy cập nhật ô nguồn của tham số đó cho trình tạo đặc tả nguồn dữ liệu thuộc loại DataSourceType.BIGQUERY.

Tài liệu chi tiết

build()

Tạo đặc tả nguồn dữ liệu từ các chế độ cài đặt trong trình tạo này. Bạn phải sử dụng as...() để chỉ định loại nguồn dữ liệu trước khi tạo.

Mã mẫu sau đây tạo Đặc tả nguồn dữ liệu BigQuery.

const bigQueryDataSourceSpec = 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();

Mẫu mã sau đây tạo Đặc tả nguồn dữ liệu Looker.

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

Cầu thủ trả bóng

DataSourceSpec – Đặc tả nguồn dữ liệu.


copy()

Tạo DataSourceSpecBuilder dựa trên các chế độ cài đặt của nguồn dữ liệu này.

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

const newSpec = spec.copy();

Cầu thủ trả bóng

DataSourceSpecBuilder – Trình tạo.


getExploreName()

Lấy tên của bản khám phá Looker trong mô hình.

// TODO(developer): Replace the URL with your own.
const ss = SpreadsheetApp.openByUrl(
    'https://docs.google.com/spreadsheets/d/abc123456/edit',
);

const lookerDataSourceSpec = ss.getDataSources()[0].getSpec().asLooker();
const exploreName = lookerDataSourceSpec.getExploreName();
Logger.log(exploreName);

Cầu thủ trả bóng

String – Tên của bản khám phá Looker.


getInstanceUrl()

Lấy URL của thực thể Looker.

// TODO(developer): Replace the URL with your own.
const ss = SpreadsheetApp.openByUrl(
    'https://docs.google.com/spreadsheets/d/abc123456/edit',
);

const lookerDataSourceSpec = ss.getDataSources()[0].getSpec().asLooker();
const instanceUrl = lookerDataSourceSpec.getInstanceUrl();
Logger.log(instanceUrl);

Cầu thủ trả bóng

String – URL của thực thể Looker.


getModelName()

Lấy tên của mô hình Looker trong thực thể.

// TODO(developer): Replace the URL with your own.
const ss = SpreadsheetApp.openByUrl(
    'https://docs.google.com/spreadsheets/d/abc123456/edit',
);

const lookerDataSourceSpec = ss.getDataSources()[0].getSpec().asLooker();
const modelName = lookerDataSourceSpec.getModelName();
Logger.log(modelName);

Cầu thủ trả bóng

String – Tên của mô hình Looker.


getParameters()

Lấy các tham số của nguồn dữ liệu.

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

Phương thức này chỉ dùng được cho nguồn dữ liệu BigQuery.

Cầu thủ trả bóng

DataSourceParameter[] – Danh sách tham số.


getType()

Lấy loại nguồn dữ liệu.

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

Cầu thủ trả bóng

DataSourceType – Loại nguồn dữ liệu.


removeAllParameters()

Xoá tất cả các tham số.

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

Cầu thủ trả bóng

LookerDataSourceSpecBuilder – Trình tạo, để tạo chuỗi.


removeParameter(parameterName)

Xoá tham số đã chỉ định.

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

Tham số

TênLoạiMô tả
parameterNameStringTên của tham số cần xoá.

Cầu thủ trả bóng

LookerDataSourceSpecBuilder – Trình tạo, để tạo chuỗi.


setExploreName(exploreName)

Đặt tên bản khám phá trong mô hình Looker.

const lookerDataSourceSpecBuilder =
    SpreadsheetApp.newDataSourceSpec().asLooker();
// TODO(developer): replace explore name with your own
lookerDataSourceSpecBuilder.setExploreName('my explore name');

Tham số

TênLoạiMô tả
exploreNameStringTên bản khám phá trong mô hình Looker đã chọn.

Cầu thủ trả bóng

LookerDataSourceSpecBuilder – Trình tạo này, để tạo chuỗi.


setInstanceUrl(instanceUrl)

Đặt URL thực thể cho Looker.

const lookerDataSourceSpecBuilder =
    SpreadsheetApp.newDataSourceSpec().asLooker();
// TODO(developer): replace instance url with your own
lookerDataSourceSpecBuilder.setInstanceUrl('my instance url');

Tham số

TênLoạiMô tả
instanceUrlStringURL của thực thể Looker.

Cầu thủ trả bóng

LookerDataSourceSpecBuilder – Trình tạo, để tạo chuỗi.


setModelName(modelName)

Đặt tên mô hình Looker trong thực thể Looker.

const lookerDataSourceSpecBuilder =
    SpreadsheetApp.newDataSourceSpec().asLooker();
// TODO(developer): replace model name with your own
lookerDataSourceSpecBuilder.setModelName('my model name');

Tham số

TênLoạiMô tả
modelNameStringTên mô hình trong thực thể Looker.

Cầu thủ trả bóng

LookerDataSourceSpecBuilder – Trình tạo, để tạo chuỗi.


setParameterFromCell(parameterName, sourceCell)

Thêm một tham số hoặc nếu tham số có tên tồn tại, hãy cập nhật ô nguồn của tham số đó cho trình tạo đặc tả nguồn dữ liệu thuộc loại DataSourceType.BIGQUERY.

Phương thức này chỉ dùng được cho nguồn dữ liệu BigQuery.

const specBuilder = SpreadsheetApp.newDataSourceSpec().asBigQuery();
specBuilder.setParameterFromCell('x', 'A1');
const bigQuerySpec = specBuilder.build();

Tham số

TênLoạiMô tả
parameterNameStringTên tham số.
sourceCellStringÔ nguồn, như được chỉ định trong ký hiệu A1.

Cầu thủ trả bóng

LookerDataSourceSpecBuilder – Trình tạo, để tạo chuỗi.