isNull、isEmpty、isBlank
isNull operator は、文字列をチェックしてブール値を返します。文字列が null であれば true を返し、文字列が null でなければ false を返します。
isNull に加えて次の operator があります。
- isEmpty operator は、文字列が次に該当するかどうかを確認します。
- 文字が含まれていない
- 空白スペースのみである
- isBlank operator は、文字列が次に該当するかどうかを確認します。
- 文字が含まれていない
- 空白スペースのみである
- null である
フィールドが null である理由
フィールドに null 値が格納される理由は次の通りです。
isNull、isEmpty、isBlank を使用するケース
isNull(<string>)
<string>
の値が「null」であるかどうかを確認します。
isNull(null) = true
isNull("") = false
isNull(" ") = false
isNull("bob") = false
isNull(" bob ") = false
文字列が null であれば true
を返します。
isEmpty(<string>)
<string>
の値が文字も空白スペースも含まない空の文字列であるかどうかをチェックします。
isEmpty(null) = true
isEmpty("") = true
isEmpty(" ") = false
isEmpty("bob") = false
isEmpty(" bob ") = false
文字列が null または空であれば true
を返します。
isBlank(<string>)
値が null、空、または空白スペース文字のみを含むかどうかをチェックします。
isBlank(null) = true
isBlank("") = true
isBlank(" ") = true
isBlank("bob") = false
isBlank(" bob ") = false
文字列が null、空、または空白スペースのみであれば true
を返します。
例
ジオ ルックアップ クエリを実行し、ジオ データベースに格納されていないリモート IP アドレスを検索。
この場合、その IP アドレスには country_code
が関連付けられておらず、フィールド値が null になります。
次のようなクエリを実行した場合:
| parse "remote_ip=*]" as remote_ip
| lookup country_code from geo://location on ip = remote_ip
| if (isNull(country_code), "unknown", country_code) as country_code
isNull
operator によって country_code
のフィールド値がチェックされ、true
が返されると、if
operator によって値が文字列 unknown
に置き換えられます。
where を使用して null 値をチェックします。
ルックアップ オペレーションで返される null 値を探すには、次のようなクエリを実行します。
| parse "example_ip=*]" as ip
| lookup country_name, city from geo://location on ip = ip
| where isNull(country_name)