次の方法で共有


モジュール 2: Data Factory でデータフローを使用してデータを変換する

このモジュールでは、約 25 分でデータフローの作成、変換の適用、Bronze テーブルから Gold レイクハウス テーブルへの生データの移動を行います。

最後のモジュールから Bronze レイクハウス テーブルに読み込まれた生データを使用して、特定の日の各ベンダーとその乗車の割引を含む別のテーブルと組み合わせることで、そのデータを準備および強化できるようになりました。 この最後の Gold レイクハウス テーブルが読み込まれ、使用できる状態になります。

データフローの大まかな手順は次のとおりです。

  • モジュール 1: Data Factory を使用してパイプラインを作成する」の Copy アクティビティによって作成されたレイクハウス テーブルから生データを取得します。
  • レイクハウス テーブルからインポートされたデータを変換します。
  • 割引データを含む CSV ファイルに接続します。
  • 割引データを変換します。
  • 乗車と割引のデータを組み合わせます。
  • Gold レイクハウス テーブルに出力クエリを読み込みます。

レイクハウス テーブルからデータを取得する

  1. サイドバーから [作成] を選択し、[Dataflow Gen2] を選択して新しい Dataflow Gen2 を作成します。 Screenshot showing the Fabric Create page with the Dataflow Gen2 button highlighted.

  2. 新しいデータフロー メニューで、[データの取得] を選択し、[その他...] を選択します。

    Screenshot showing the Dataflow menu with Get data button highlighted and the More... option highlighted from its menu.

  3. [Lakehouse](レイクハウス) コネクタを検索して選択します。

    Screenshot showing the selection of the Lakehouse data source from the Choose data source menu.

  4. [Connect to data source](データ ソースへの接続) ダイアログが表示され、現在サインインしているユーザーに基づいて新しい接続が自動的に作成されます。 [次へ] を選択します。

    Screenshot showing the configuration of the data source settings for your new Lakehouse with your current signed in user, and the Next button selected.

  5. [Choose data](データの選択) ダイアログが表示されます。 ナビゲーション ウィンドウを使用して、前のモジュールで変換先として作成したレイクハウスを見つけ、Tutorial_Lakehouse データ テーブルを選択します。

    Screenshot showing the Lakehouse browser with the workspace, lakehouse, and table created with the Copy activity in module 1.

  6. "(省略可能)" キャンバスにデータが設定されたら、列プロファイル情報を設定できます。これは、データ プロファイルの設定に役立ちます。 適切な変換を適用し、それに基づいて適切なデータ値をターゲットにすることができます。

    これを行うには、リボン ウィンドウで [オプション] を選択し、[列プロファイル] の最初の 3 つのオプションを選択し、[OK] を選択します。

    Screenshot showing the column options selection for your data.

レイクハウスからインポートされたデータを変換する

  1. 2 番目の列 IpepPickupDatetime の列ヘッダーにあるデータ型アイコンを選択してドロップダウン メニューを表示し、メニューからデータ型を選択して、列の型を [日付と時刻] から [日付] に変換します。 Screenshot showing the selection of the Date data type for the IpepPickupDatetime column.

  2. "(省略可能)" リボンの [ホーム] タブで、[Manage columns](列の管理) グループから [列の選択] オプションを選択します。

    Screenshot showing the Choose columns button on the Home tab of the dataflow editor.

  3. "(省略可能)" [列の選択] ダイアログで、ここにリストされているいくつかの列の選択を解除し、[OK] を選択します。

    • lpepDropoffDatetime
    • puLocationId
    • doLocationId
    • pickupLatitude
    • dropoffLongitude
    • rateCodeID

    Screenshot showing the Choose columns dialog with the identified columns deselected.

  4. storeAndFwdFlag 列のフィルターを選択し、ドロップダウン メニューを並べ替えます。 (警告 "リストが不完全である可能性があります" が表示される場合は、[さらに読み込む] を選択してすべてのデータを表示します)。

    Screenshot showing the filter and sort dialog for the column.

  5. [Y] を選択して、割引が適用された行のみを表示し、[OK] を選択します。

    Screenshot showing the values filter with only 'Y' selected.

  6. [IpepPickupDatetime 列の並べ替えを選択してドロップダウン メニューをフィルター処理し、[日付フィルター] を選択し、[日付] および [日付と時刻] 型に対して提供されている [Between...](間...) フィルターを選択します。

    Screenshot showing the selection of the Date filters option in the column sort and format dropdown.

  7. [行をフィルター] ダイアログで、2015 年 1 月 1 日から 2015 年 1 月 31 日までの日付を選択し、[OK] を選択します。

    Screenshot showing the selection of the dates in January 2015.

割引データを含む CSV ファイルに接続する

次に、乗車のデータを所定の場所に配置して、各日と VendorID のそれぞれの割引が含まれるデータを読み込んで準備した後、それを乗車データと組み合わせます。

  1. データフロー エディター メニューの [ホーム] タブで、[データの取得] オプションを選択し、[Text/CSV](テキスト/CSV) を選択します。

    Screenshot showing the selection of the Get data menu from the Home tab, with Text/CSV highlighted.

  2. [Connect to data source](データ ソースへの接続) ダイアログで、次の詳細を指定します。

    • ファイル パスまたは URL - https://raw.githubusercontent.com/ekote/azure-architect/master/Generated-NYC-Taxi-Green-Discounts.csv
    • 認証の種類 - 匿名

    次へ を選択します。

    Screenshot showing the Text/CSV settings for the connection.

  3. [Preview file data](ファイル データのプレビュー) ダイアログで、[作成] を選択します。

    Screenshot showing the Preview file data dialog with the Create button highlighted.

割引データを変換する

  1. データを確認すると、ヘッダーが最初の行に表示されます。 プレビュー グリッド領域の左上にあるテーブルのコンテキスト メニューを選択し、[Use first row as headers](最初の行をヘッダーとして使用) を選択して、ヘッダーに昇格させます。

    Screenshot showing the selection of the Use first row as headers option from the table context menu.

    Note

    ヘッダーを昇格させると、データフロー エディターの上部にある [Applied steps](適用される手順) ウィンドウに新しい手順が追加されたことを確認できます。

  2. VendorID 列を右クリックし、表示されたコンテキスト メニューから [Unpivot other columns](他の列のピボット解除) オプションを選択します。 これにより、列を属性と値のペアに変換して、列を行にすることができます。

    Screenshot showing the context menu for the VendorID column with the Unpivot other columns selection highlighted.

  3. テーブルのピボットを解除して、Attribute および Value 列の名前を変更します。これを行うには、それぞれをダブルクリックし、AttributeDate に、ValueDiscount に変更します。

    Screenshot showing the table columns after renaming Attribute to Date and Value to Discount.

  4. Date 列のデータ型を変更するには、列名の左側にあるデータ型メニューを選択し、[日付] を選択します。

    Screenshot showing the selection of the Date data type for the Date column.

  5. Discount 列を選択し、メニューの [変換] タブを選択します。 [Number column](数値列) を選択し、サブメニューから [Standard](標準) 数値変換 を選択し、[Divide](除算) を選択します。

    Screenshot showing the selection of the Divide option to transform data in the Discount column.

  6. [Divide](除算) ダイアログで、値 100 を入力します。

    Screenshot showing the Divide dialog with the value 100 entered and the OK button highlighted.

乗車と割引データを組み合わせる

次の手順では、両方のテーブルを結合して、乗車に適用される割引と調整された合計が含まれる 1 つのテーブルにします。

  1. 最初に、[Diagram view](ダイアグラム ビュー) ボタンを切り替えて、両方のクエリを表示できるようにします。

    Screenshot showing the Diagram view toggle button with both queries created in this tutorial displayed.

  2. nyc_taxi クエリを選択し、[ホーム] タブで [Combine](結合) メニューを選択し、[Merge queries](クエリのマージ) を選択し、[Merge queries as new](新規としてクエリをマージ) を選択します。

    Screenshot showing the Merge queries as new selection for the nyc_taxi query.

  3. [Merge](マージ) ダイアログで、[Right table for merge](マージ用の右テーブル) ドロップダウンから Generated-NYC-Taxi-Green-Discounts を選択し、ダイアログの右上にある "電球" アイコンを選択して、2 つのテーブル間の推奨される列マッピングを表示します。

    Screenshot showing the configuration of the Merge dialog with suggested column mappings displayed.

    推奨された 2 つの列マッピング (両方のテーブルの VendorID 列と Date 列のマッピング) を一度に 1 つずつ選択します。 両方のマッピングが追加されると、一致する列ヘッダーが各テーブルで強調表示されます。

  4. 複数のデータ ソースからのデータを結合して結果を表示することを許可するように求めるメッセージが表示されます。 [Merge](マージ) ダイアログで [OK] を選択します。

    Screenshot showing the request to approve combining data from multiple data sources, with the OK button highlighted.

  5. テーブル領域には、最初に次の警告が表示されます。"複数のソースからのデータを結合すると、あるソースから別のソースへのデータが表示される可能性があるため、評価が取り消されました。 データを表示する可能性が問題ない場合は、[続行] を選択してください"。[続行] を選択して、結合されたデータを表示します。

    Screenshot showing the warning about combining data from multiple data sources with the Continue button highlighted.

  6. ダイアグラム ビューで新しいクエリが作成され、新しいマージ クエリと以前に作成した 2 つのクエリとの関係が示されていることに注目してください。 エディターのテーブル ウィンドウを見て、マージ クエリ列リストの右側までスクロールして、テーブル値を持つ新しい列が存在することを確認します。 これは "Generated-NYC-Taxi-Green-Discounts" 列で、その種類は [テーブル] です。 列ヘッダーには、反対方向を向いた 2 つの矢印が付いたアイコンがあり、テーブルから列を選択できます。 Discount を除くすべての列の選択を解除し、[OK] を選択します。

    Screenshot showing the merged query with the column selection menu displayed for the newly generated column Generated-NYC-Taxi-Green-Discounts.

  7. 割引の値が行レベルになったので、新しい列を作成して割引後の合計金額を計算できます。 これを行うには、エディターの上部にある [列を追加] タブを選択し、[標準] グループから [Custom column](カスタム列) を選択します。

    Screenshot showing the Add custom column button highlighted on the General section of the Add column tab.

  8. [Custom column](カスタム列) ダイアログで、Power Query 数式言語 (M とも呼ばれます) を使用して、新しい列の計算方法を定義できます。 [New column name](新しい列名) に「TotalAfterDiscount」を入力し、[データ型][通貨] を選択し、[Custom column formula](カスタム列の式) に次の M 式を指定します。

    if [totalAmount] > 0 then [totalAmount] * ( 1 -[Discount] ) else [totalAmount]

    [OK] をクリックします。

    Screenshot showing the Custom column configuration screen with the New column name, Data type and Custom column formula highlighted.

  9. 新たに作成した TotalAfterDiscount 列を選択し、エディター ウィンドウの上部にある [変換] タブを選択します。 [Number column](数値列) グループで、[Rounding](丸め) ドロップダウンを選択し、[Round...](丸め...) を選択します。

    Screenshot showing the Round... option on the Transform tab of the editor window.

  10. [Rounding](丸め) ダイアログで、小数点以下の桁数として「2」と入力し、[OK] を選択します。

    Screenshot showing the Round dialog with 2 for the number of decimal places and the OK button highlighted.

  11. IpepPickupDatetime のデータ型を [日付] から [日付と時刻] に変更します。

    Screenshot showing the selection of the Date/Time data type for the IpepPickupDatetime column.

  12. 最後に、エディターの右側から [クエリ設定] ウィンドウを展開し (まだ展開されていない場合)、クエリの名前を Merge から Output に変更します。

    Screenshot showing the renaming of the query from Merge to Output.

レイクハウスのテーブルに出力クエリを読み込む

出力クエリが完全に準備され、データを出力する準備ができたので、クエリの出力先を定義できます。

  1. 以前に作成した Output マージ クエリを選択します。 次に、エディターで [ホーム] タブを選択し、[クエリ] グループから [Add data destination](データの出力先を追加) を選択して、レイクハウスを出力先として選択します。

    Screenshot showing the Add data destination button with Lakehouse highlighted.

  2. [Connect to data destination](データの出力先に接続) ダイアログで、接続が既に選択されているはずです。 [次へ] をクリックして続行します。

  3. [Choose destination target](出力先ターゲットを選択) ダイアログで、データを読み込むレイクハウスを参照し、新しいテーブルに nyc_taxi_with_discounts という名前を付けてから、もう一度 [次へ] を選択します。

    Screenshot showing the Choose destination target dialog with Table name nyc_taxi_with_discounts.

  4. [Choose destination settings](出力先の設定を選択) ダイアログで、更新方法を既定の [置き換え] のままにし、列が正しくマップされていることを再確認して、[設定の保存] を選択します。

    Screenshot showing the Choose destination settings dialog with the Save settings button highlighted.

  5. エディターのメイン ウィンドウに戻り、[クエリ設定] ウィンドウで Output テーブルの出力先が表示されていることを確認し、[パブリッシュ] を選択します。

    重要

    ワークスペースに最初の Dataflow Gen2 が作成されると、レイクハウス項目とウェアハウス項目が、関連する SQL 分析エンドポイントおよびセマンティック モデルと共にプロビジョニングされます。 これらの項目はワークスペース内のすべてのデータフローによって共有され、Dataflow Gen2 が動作するために必要であるため、削除しないでください。また、ユーザーが直接使用することを意図したものではありません。 これらの項目は、Dataflow Gen2 の実装の詳細です。 項目はワークスペースには表示されませんが、ノートブック、SQL エンドポイント、レイクハウス、ウェアハウスなどの他のエクスペリエンスでアクセスできる場合があります。 名前のプレフィックスで項目を認識できます。 これらの項目のプレフィックスは "DataflowsStaging" です。

  6. "(省略可能)" ワークスペース ページでデータフローの名前を変更するには、行を選択した後に表示されるデータフロー名の右側にある省略記号を選択し、[プロパティ] を選択します。

    Screenshot showing the Properties option selected on the menu for a dataflow where it can be renamed.

  7. データフローの行を選択した後、更新アイコンを選択します。完了すると、[Data destination](データの出力先) 設定で構成されたとおりに作成された新しいレイクハウス テーブルが表示されます。

    Screenshot showing the selection of the refresh button to refresh the dataflow.

  8. レイクハウスを調べて、そこに読み込まれた新しいテーブルを確認します。

Microsoft Fabric の Data Factory を使用した最初のデータ統合に関するエンドツーエンドのチュートリアルのこの 2 つ目のモジュールでは、次の方法を学習しました。

  • 新しいデータフロー Gen2 を作成する。
  • サンプル データをインポートして変換する。
  • テキスト/CSV データをインポートして変換する。
  • 両方のデータ ソースのデータを新しいクエリにマージする。
  • データを変換し、クエリで新しい列を生成する。
  • クエリの出力先ソースを構成する。
  • 新しいデータフローの名前を変更して更新する。

次のセクションに進み、データ パイプラインを統合します。