Apache-pig-size
提供:Dev Guides
Apache Pig-SIZE()
Pig Latinの* SIZE()*関数は、任意のPigデータ型に基づいて要素の数を計算するために使用されます。
構文
以下に、* SIZE()*関数の構文を示します。
戻り値は、Apache Pigのデータ型によって異なります。
Data type | Value |
---|---|
int, long, float, double | For all these types, the size function returns 1. |
Char array | For a char array, the size() function returns the number of characters in the array. |
Byte array | For a bytearray, the size() function returns the number of bytes in the array. |
Tuple | For a tuple, the size() function returns number of fields in the tuple. |
Bag | For a bag, the size() function returns number of tuples in the bag. |
Map | For a map, the size() function returns the number of key/value pairs in the map. |
例
以下に示すように、HDFSディレクトリ /pig_data/ に employee.txt という名前のファイルがあると仮定します。
そして、以下に示すように、このファイルを関係名 employee_data でPigにロードしました。
タイプのサイズの計算
特定の列の型のサイズを計算するには、* SIZE()*関数を使用できます。 以下に示すように、名前タイプのサイズを計算しましょう。
検証
以下に示すように、 DUMP 演算子を使用してリレーション size を確認します。
出力
次の出力が生成され、リレーション size の内容が次のように表示されます。 この例では、 name 列のサイズを計算しました。 varchar型であるため、* SIZE()*関数は各従業員の名前の文字数を示します。