0
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Power Apps から Azure Databricks に接続する

Last updated at Posted at 2025-06-18

はじめに

2025/6 発表された Microsoft Power Platform から Azure Databricks に接続する機能について検証してみました。
ここではPower Apps から Databricks への接続を試しています。
(2025/6/18 時点ではパブリックプレビュー段階)

前提条件

以下の要件を満たす必要があります。

image.png

また、テーブルに対して作成、更新、および削除を実行するには主キー設定が必要となります。

image.png

Databricks での作業

テーブルの作成

Databricks にて Power Apps から接続するためのテーブルを用意します。
ここでは「顧客名」を主キーに設定しています。

image.png

<サンプルコード>

create_table
# Create a table with primary key constraint
spark.sql("""
CREATE OR REPLACE TABLE {catalog}.{schema}.table_01 (
    `顧客名` STRING NOT NULL,
    `注文日` DATE,
    `合計金額` INT,
    PRIMARY KEY (`顧客名`)
)
""")

# Insert data into the table
spark.sql("""
INSERT INTO {catalog}.{schema}.table_01 (`顧客名`,`注文日`, `合計金額`) VALUES
('高橋次郎', to_date('2023-01-03', 'yyyy-MM-dd'), 2500),
('山田太郎', to_date('2023-01-04', 'yyyy-MM-dd'), 1000),
('田中三郎', to_date('2023-01-05', 'yyyy-MM-dd'), 3000)
""")

SQL ウェアハウスの作成

ここではサーバーレスで作成しています。
後述の接続設定で使用するため、サーバーのホスト名と HTTP パスを控えておきます。

image.png

Power Apps での作業

コネクタの設定

「作成」から「空のキャンバスで開始」を選択してキャンバスアプリを作成します。

image.png

「データの追加」から Azure Databricks コネクタを選択します。

image.png

認証方法を選択します。ここでは OAuth を選択しています。
また、先ほど控えておいたサーバーのホスト名と HTTP パスを入力します。

接続が成功するとテーブルの一覧が表示されるので、アプリでソースとしたいテーブルを選択します。ここでは前述で作成したテーブルを選択しています。

テーブルの表示

「挿入」から「レイアウト」の「データテーブル」を選択して、データソースに Databricks のテーブルを選択すると以下のように表示されます。
Databricks 上のデータと同じことが確認できます。

image.png

データの追加・更新・削除

「テキスト入力」「日付の選択」「リストボックス」を用いて追加・更新・削除したいレコードを定義し、「ボタン」で実行するように作成してみました。

Insert ボタンのアクションに設定した関数
OnSelect
Collect('<データソース>',{顧客名:InsertCustomer.Text,合計金額:Value(InsertTotalAmount.Text),注文日:InsertDate.SelectedDate});
Update ボタンのアクションに設定した関数
OnSelect
Patch('<データソース>', LookUp('<データソース>', 顧客名=UpdateCustomer.SelectedText.Value), {顧客名:UpdateCustomer.SelectedText.Value,合計金額:Value(UpdateTotalAmount.Text),注文日:UpdateDate.SelectedDate});
Delete ボタンのアクションに設定した関数
OnSelect
Remove('データソース', LookUp('データソース', 顧客名=DeleteCustomer.SelectedText.Value));

image.png

プレビューでそれぞれの実行結果を確認します。

  • Insert 結果
    image.png

  • Update 結果
    image.png

  • Delete 結果
    (レコードが削除されたためテーブルにもドロップダウンにも表示されない)
    image.png

また、Databricks 上から確認しても同様に反映されています。

image.png

おわりに

実行時間は数秒であったので、リアルタイムに処理ができそうです。

0
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?