0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Azure Data Factory - Data Flow で null値をセットする方法

Posted at

#はじめに

Azure Data Factory や Azure Synapse Pipeline のData Flow を使ってデータ加工するときに
ある列の値をゼロでもなくブランクでもなく明示的に null 値にする方法です。
普通に null() と設定してエラーなって困った人は意外と多いと思います。筆者もその経験者の1人です。

#方法

Data Flow の派生列、集約、ウィンドウ等のモジュール内で使える式ビルダーで、
null 変換したい列のデータ型に合わて toXXXXX() の中に null() をセットします
例1)toString(null())
例2)toInteger(null())
   iif(length({年}) == 0, toString(null()), {年})
Dataflow01_02.PNG

#補足:どんなときに null() 変換をつかうのか?

例えばこんなとき null() 変換が必要でした
例1)
やりたいこと:
後続処理でFill(値埋め)したいが、値にブランク('')が入っており、Fillのためのcoalesce関数が効かない
方法:
①前段でブランク値をnull値に変換してから
Dataflow01_02.PNG
②ウィンドウ(window)モジュールでcoalesce関数を使ってFillする
Dataflow01_03.PNG
Fill実装の参考:https://techcommunity.microsoft.com/t5/azure-data-factory-blog/implement-fill-down-in-adf-and-synapse-data-flows/ba-p/2013406

例2)
やりたいこと:
 ある項目の平均値を算出したいが、値が999のデータは無視して平均値を出したい
 ※ゼロ(0)に変換すると平均値として計算されてしまうので、無視する場合はnull値に設定するのがポイント
方法:
 集約(aggregate)モジュールの式ビルダーにて以下のように式を設定する 
Dataflow01_01.PNG

#参考
https://docs.microsoft.com/ja-jp/azure/data-factory/concepts-data-flow-expression-builder

0
2
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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?