OceanBase
English日本語简体中文
ドキュメントホーム
製品
エコシステム
リリース

データベース

OceanBase CloudOceanBaseデータベース

データベース

OceanBase CloudOceanBaseデータベース
OceanBase CloudOceanBaseデータベース

OceanBase Cloud

  • エコシステム統合の概要
  • データベースバージョニング
    • Liquibaseを使用したOceanBaseデータベースのバージョン管理
    • Flywayを使用したOceanBase Cloudデータベースのバージョン管理
  • データ統合
    • Canalを使用したデータの同期
    • dbtを使用したOceanBaseデータの分析
    • Debezium
    • Flinkによるデータの同期
    • AWS Glueを使用したOceanBaseデータの移行
    • Informatica CloudとOceanBaseデータベースの連携ガイド
    • OceanBaseデータベースとKafkaの統合に関するベストプラクティス
    • Maxwell
    • SeaTunnel
    • DataWorks
    • Apache NiFiによるOceanBase Cloudの統合
  • SQL 開発
    • DataGripでOceanBase Cloudデータベースに接続する
    • DBeaverでOceanBase Cloudに接続する
    • NavicatでOceanBase Cloudに接続する
    • TablePlusでOceanBase Cloudデータベースに接続する
  • オーケストレーション
    • DolphinScheduler
    • LinkisとOceanBaseデータベースの連携
    • AirflowとOceanBaseデータベースの連携
  • 可視化
    • GrafanaでOceanBase Cloudの監視ダッシュボードデータを表示する
    • Power BIでOceanBase Cloudに接続してデータを取得する
    • Quick BIでOceanBase Cloudに接続する
    • SupersetとOceanBase Cloudを使用したデータ分析
    • TableauからOceanBase Cloudに接続する
  • オブザーバビリティ
    • Datadogを使用したOceanBase Cloudインスタンスの監視
    • Prometheusを使用したOceanBaseデータの監視
  • データベース管理
    • BytebaseによるOceanBaseインスタンスの管理
  • AI
    • OceanBase Cloud VectorとLlamaIndexの連携
    • OceanBase Cloud VectorとDifyの連携
    • OceanBase Cloud VectorとLangChainの連携
    • OceanBase Cloud VectorとQwenの連携
    • OceanBase Cloud VectorとOpenAIの連携
    • OceanBase Cloudとn8nの連携
    • OceanBase MCP ServerとTraeの連携
    • OceanBase Cloud VectorとSpring AI Alibabaの連携
    • OceanBase MCP ServerとClineの連携
    • OceanBase MCP ServerとCursorの連携
    • OceanBase MCP ServerとContinueの連携
    • Google GenAI ToolboxとOceanBase MCP Serverの統合
    • OceanBase Cloud VectorとCamelAIの連携
    • OceanBase Cloud VectorとFirecrawlの連携
    • OceanBase Cloud VectorとHugging Faceの連携
    • OceanBase Cloud VectorとOllamaの連携
    • OceanBase Cloud VectorとGoogle Geminiの連携
    • OceanBase Cloud VectorとCloudflare Workers AIの連携
    • OceanBase MCP ServerとQoderの連携
    • OceanBase MCP ServerとOpenCodeの連携
    • OceanBase MCP ServerとClaude Codeの連携
    • OceanBase MCP ServerとGitHub Copilotの連携
    • OceanBase MCP ServerとCodexの連携
    • OceanBase Cloud VectorとJina AIの連携
    • OceanBase MCP ServerとAugment Codeの連携
    • OceanBase MCP ServerとKiroの連携
  • 開発ツール
    • Cloudflare WorkersでOceanBase Cloudに接続する
    • VercelでOceanBase Cloudに接続する

PDF をダウンロード

ドキュメントフィードバック
  1. ドキュメントセンター
  2. OceanBase Cloud

dbtを使用したOceanBaseデータの分析

最終更新:2026-10-09 09:10:54

前提条件
dbt-oceanbaseのインストール
プロジェクトの設定
テストデータの準備

dbt(data build tool)は、SQLを通じてデータ変換を実現し、コマンドをテーブルやビューに変換できるオープンソースのデータ変換ツールです。本記事では、dbt-oceanbaseを使用してOceanBaseデータベース内のデータを分析する方法について説明します。

前提条件

dbtを使用する前に、dbt-oceanbaseがインストールされていることを確認してください。

dbt-oceanbaseのインストール

dbt-oceanbaseは現在PyPIには公開されていないため、リポジトリからインストールする必要があります。リリース後はpipを使用してインストールできます。以下のコマンドを使用して、dbt-oceanbaseをインストールします:

git clone https://github.com/oceanbase/dbt-oceanbase.git --branch dev/1.0.x
cd dbt-oceanbase
pip3 install .

説明

dbt-oceanbaseをインストールすると、dbt-coreも自動的にインストールされます。

以下のコマンドを使用して、インストール済みのdbtのバージョンを確認します:

pip list|grep dbt

dbt-adapters 1.3.1
dbt-common 1.4.0
dbt-core 1.8.3
dbt-extractor 0.5.1
dbt-oceanbase 1.0.0
dbt-semantic-interfaces 0.5.1

期待される実行結果:

dbt-adapters                1.3.1
dbt-common                  1.4.0
dbt-core                    1.8.3
dbt-extractor               0.5.1
dbt-oceanbase               1.0.0
dbt-semantic-interfaces     0.5.1

プロジェクトの設定

現在のディレクトリで、以下のコマンドを使用して新しいプロジェクトを初期化します:

dbt init dbtexample

その後、プロンプトに従ってOceanBaseデータベースの接続情報を入力します。

期待される実行結果:

06:00:31  Running with dbt=1.8.3
06:00:31  Your new dbt project "dbtexample" was created!

For more information on how to configure the profiles.yml file,
please consult the dbt documentation here:

https://docs.getdbt.com/docs/configure-your-profile

One more thing:

Need help? Don't hesitate to reach out to us via GitHub issues or on Slack:

https://community.getdbt.com/

Happy modeling!

06:00:31  Setting up your profile.
Which database would you like to use?
[1] oceanbase_mysql

(Don't see the one you want? https://docs.getdbt.com/docs/available-adapters)

Enter a number: 1
host (hostname for the instance): xx.xxx.xxx.xx
port: 2503
user (username@tenant#cluster): username@tenant#cluster
pass (password):
database (default database that dbt will build objects in): test
threads (1 or more) [1]:
06:02:20  Profile dbtexample written to /Users/username/.dbt/profiles.yml using target's profile_template.yml and your supplied values. Run 'dbt debug' to validate the connection.

入力が完了したら、以下のコマンドを使用してdbt接続を検証します:

dbt debug

期待される実行結果:

06:02:35 Running with dbt=1.8.3
06:02:35 dbt version: 1.8.3
06:02:35 python version: 3.11.5
06:02:35 python path: /Users/username/miniconda3/bin/python
06:02:35 os info: macOS-14.2.1-arm64-arm-64bit
06:02:35 Using profiles dir at /Users/username/.dbt
06:02:35 Using profiles.yml file at /Users/username/.dbt/profiles.yml
06:02:35 Using dbt_project.yml file at /Users/username/projects/dbtexample/dbt_project.yml
06:02:35 adapter type: oceanbase_mysql
06:02:35 adapter version: 1.0.0
06:02:35 Configuration:
06:02:35   profiles.yml file [OK found and valid]
06:02:35   dbt_project.yml file [OK found and valid]
06:02:35 Required dependencies:
06:02:35  - git [OK found]

06:02:35 Connection:
06:02:35   host: xx.xxx.xxx.xx
06:02:35   port: 2503
06:02:35   user: username
06:02:35   retries: 1
06:02:35   schema: test
06:02:35   database: test
06:02:35 Registered adapter: oceanbase_mysql=1.0.0
06:02:36  Connection test: [OK connection ok]

06:02:36 All checks passed!

テストデータの準備

以下のコマンドを使用して、dbt公式サイトからサンプルデータをダウンロードします:

wget https://dbt-tutorial-public.s3-us-west-2.amazonaws.com/jaffle_shop_customers.csv
wget https://dbt-tutorial-public.s3-us-west-2.amazonaws.com/jaffle_shop_orders.csv
wget https://dbt-tutorial-public.s3-us-west-2.amazonaws.com/stripe_payments.csv

データをdbtexample/seeds/ディレクトリに配置します。

以下のコマンドを使用して、データをインポートします:

dbt seed

(オプション) 以下のコマンドを使用して、不要なmodels/exampleを削除します:

# optional 
rm -rf  models/example/ 

modelsディレクトリ内に新しいファイルcustomers.sqlを作成し、以下の内容を書き込みます:

{{
  config(
    materialized='view'
  )
}}

with customers as (

    select
        id as customer_id,
        first_name,
        last_name

    from jaffle_shop_customers

),

orders as (

    select
        id as order_id,
        user_id as customer_id,
        order_date,
        status

    from jaffle_shop_orders

),

customer_orders as (

    select
        customer_id,

        min(order_date) as first_order_date,
        max(order_date) as most_recent_order_date,
        count(order_id) as number_of_orders

    from orders

    group by 1

),

final as (

    select
        customers.customer_id,
        customers.first_name,
        customers.last_name,
        customer_orders.first_order_date,
        customer_orders.most_recent_order_date,
        coalesce(customer_orders.number_of_orders, 0) as number_of_orders

    from customers

    left join customer_orders using (customer_id)

)

select * from final 

以下のコマンドを使用して、models配下のファイルを自動的に検出し実行します:

dbt run

期待される実行結果は次のとおりです:

06:37:08  Running with dbt=1.8.3
06:37:08  Registered adapter: oceanbase_mysql=1.0.0
06:37:08  [WARNING]: Configuration paths exist in your dbt_project.yml file which do not apply to any resources.
There are 1 unused configuration paths:
- models.dbtexample.example
06:37:08  Found 1 model, 393 macros
06:37:08
06:37:10  Concurrency: 1 threads (target='dev')
06:37:10
06:37:10  1 of 1 START sql view model customers ........................................ [RUN]
06:37:11  1 of 1 OK created sql view model customers .............................. [SUCCESS-1 in 1.25s]
06:37:12
06:37:12  Finished running 1 view model in 0 hours 0 minutes and 3.79 seconds (3.79s).
06:37:12
06:37:12  Completed successfully
06:37:12
06:37:12  Done. PASS=1 WARN=0 ERROR=0 SKIP=0 TOTAL=1

上記のコマンドが正常に実行され、ビューが作成されたことが確認できます。OceanBaseデータベースで確認することができます。

前のトピック

Canalを使用したデータの同期
前へ

次のトピック

Debezium
次へ
このページの内容
前提条件
dbt-oceanbaseのインストール
プロジェクトの設定
テストデータの準備