メインコンテンツまでスキップ
バージョン: 2.1

Cube データ ソース

概要

Cube は、チームがメトリックを一度定義し、ダッシュボードやアプリケーション全体で一貫して提供できるようにする、分析 API とデータ アプリケーション向けのセマンティック レイヤーです。このトピックでは、Reveal アプリケーションで Cube データ ソースに接続して、データを視覚化および分析する方法について説明します。

前提条件

Reveal で Cube データ ソースを構成する前に、以下を準備してください:

  • https://your-cube-host/cubejs-api/v1 のような、到達可能な Cube REST API エンドポイント
  • Reveal ユーザーがクエリできる、少なくとも 1 つの公開済み Cube モデル
  • Cube デプロイで認証が必要な場合は、JWT などの Bearer Token 戦略

サーバーの構成

インストール

手順 1 - Reveal Cube コネクタ パッケージをインストールします。

ASP.NET アプリケーションの場合、Cube サポートを有効にするには、別の NuGet パッケージをインストールする必要があります。

dotnet add package Reveal.Sdk.Data.Cube

手順 2 - アプリケーションに Cube データ ソースを登録します。

builder.Services.AddControllers().AddReveal(builder =>
{
builder.DataSources.RegisterCube();
});

接続の構成

// Create a data source provider
public class DataSourceProvider : IRVDataSourceProvider
{
public async Task<RVDataSourceItem> ChangeDataSourceItemAsync(IRVUserContext userContext, string dashboardId, RVDataSourceItem dataSourceItem)
{
// Required: Update the underlying data source
await ChangeDataSourceAsync(userContext, dataSourceItem.DataSource);

if (dataSourceItem is RVCubeDataSourceItem cubeItem)
{
// Configure specific item properties if needed
if (cubeItem.Id == "cube_orders")
{
cubeItem.Cube = "orders";
}
}

return dataSourceItem;
}

public Task<RVDashboardDataSource> ChangeDataSourceAsync(IRVUserContext userContext, RVDashboardDataSource dataSource)
{
if (dataSource is RVCubeDataSource cubeDataSource)
{
// Configure connection properties
cubeDataSource.Url = "https://your-cube-host/cubejs-api/v1";
}

return Task.FromResult(dataSource);
}
}
重要

ChangeDataSourceAsync メソッドでデータ ソースに加えた変更は、ChangeDataSourceItemAsync メソッドには引き継がれません。両方のメソッドでデータ ソースのプロパティを更新する必要があります。上記の例のように、ChangeDataSourceItemAsync メソッド内で ChangeDataSourceAsync メソッドを呼び出し、データ ソース項目の基になるデータ ソースをパラメーターとして渡すことをお勧めします。

認証

Cube の認証は通常、Cube API に対して発行された JWT などの Bearer Token を使用して処理します。詳細については、認証 トピックを参照してください。

public class AuthenticationProvider : IRVAuthenticationProvider
{
public Task<IRVDataSourceCredential> ResolveCredentialsAsync(IRVUserContext userContext, RVDashboardDataSource dataSource)
{
IRVDataSourceCredential userCredential = null;

if (dataSource is RVCubeDataSource)
{
// Use Bearer Token
userCredential = new RVBearerTokenDataSourceCredential("your_jwt_token", "your_userid");
}

return Task.FromResult(userCredential);
}
}

クライアント側の実装

クライアント側では、データ ソースに対して ID、title、subtitle などの基本的なプロパティだけを指定します。実際の接続構成はサーバー側で行われます。

データ ソースの作成

手順 1 - RevealView.onDataSourcesRequested イベントのイベント ハンドラーを追加します。

const revealView = new RevealView("#revealView");
revealView.onDataSourcesRequested = (callback) => {
// Add data source here
callback(new RevealDataSources([], [], false));
};

手順 2 - RevealView.onDataSourcesRequested イベント ハンドラーで、RVCubeDataSource オブジェクトの新しいインスタンスを作成します。titlesubtitle プロパティを設定します。RVCubeDataSource オブジェクトを作成したら、それをデータ ソース コレクションに追加します。

revealView.onDataSourcesRequested = (callback) => {
const cubeDS = new RVCubeDataSource();
cubeDS.title = "Cube";
cubeDS.subtitle = "Data Source";

callback(new RevealDataSources([cubeDS], [], false));
};

データ ソース項目の作成

データ ソース項目は、ユーザーが表示形式のために選択できる Cube データ ソース内の特定の Cube モデルを表します。クライアント側では、ID、タイトル、サブタイトルを指定するだけです。

revealView.onDataSourcesRequested = (callback) => {
// Create the data source
const cubeDS = new RVCubeDataSource();
cubeDS.title = "My Cube Datasource";
cubeDS.subtitle = "Cube";

// Create a data source item
const cubeDSI = new RVCubeDataSourceItem(cubeDS);
cubeDSI.id = "cube_orders";
cubeDSI.title = "My Cube Datasource Item";
cubeDSI.subtitle = "Cube";

callback(new RevealDataSources([cubeDS], [cubeDSI], false));
};

その他のリソース

API リファレンス