null 演算子
is null および is not null は、値が null であるかどうかを確認するために使用します。is null は、値が null の場合に True を返します。is not null は、値が null でない場合に True を返します。
この例では、null でない Sub_Category 項目を含む行と、各項目を含む行の数が返されます。
1q = load "Superstore";
2q = filter q by 'Sub_Category' is not null;
3q = group q by 'Sub_Category';
4q = foreach q generate 'Sub_Category' as 'Sub_Category', count() as 'count';
5q = limit q 2000;| サブカテゴリ | 行数 |
|---|---|
| Accessories | 775 |
| Appliances | 466 |
| Art | 796 |
| Binders | 1,523 |
| Bookcases | 228 |
| Chairs | 617 |
| Copiers | 68 |
| Envelopes | 254 |
| Fasteners | 217 |
| Furnishings | 957 |
| Labels | 364 |
| Machines | 115 |
| Paper | 1,370 |
| Phones | 889 |
| Storage | 846 |
| Supplies | 190 |
| Tables | 319 |
case を使用して null 値を置換する
選択した値で null 値を置換するには、case を使用します。この例では、null の Sub-Category 項目に「Empty」というラベルが付けられます。
1q = load "Superstore";
2q = group q by 'Sub_Category';
3q = foreach q generate case when 'Sub_Category' is null then "Empty" else 'Sub_Category' end as 'Sub_Category', count() as 'count';
4q = limit q 2000;| サブカテゴリ | 行数 |
|---|---|
| Accessories | 775 |
| Appliances | 466 |
| Art | 796 |
| Binders | 1,523 |
| Bookcases | 228 |
| Chairs | 617 |
| Copiers | 68 |
| Envelopes | 254 |
| Fasteners | 217 |
| Furnishings | 957 |
| Labels | 364 |
| Machines | 115 |
| Paper | 1,370 |
| Phones | 889 |
| Storage | 846 |
| Supplies | 190 |
| Tables | 319 |
| Empty | 4 |