デバッグ関数

デバッグ関数

名前 説明
EXISTS 値が欠損値でない場合、TRUE を返します
IS_ABSENT 値が欠損値である場合、TRUE を返します
IF_ABSENT 値がない場合は、式に置き換えます
IS_ERROR 基盤となる式でエラーがスローされたかどうかをキャッチして確認します
IF_ERROR エラーがスローされた場合、値を式に置き換えます

EXISTS

構文:

exists(value: ANY) -> BOOLEAN

説明:

value が欠損値でない場合、TRUE を返します。

例:

value exists(value)
0L TRUE
"foo" TRUE
NULL TRUE
ABSENT FALSE
Node.js

例:

const results = await db.pipeline()
  .collection("customers")
  .select(exists(Field.of("orders")))
  .execute();
    

Web

例:

const result = await execute(db.pipeline()
  .collection("books")
  .select(field("rating").exists().as("hasRating"))
);
Swift
let result = try await db.pipeline()
  .collection("books")
  .select([Field("rating").exists().as("hasRating")])
  .execute()

Kotlin

例:

val result = db.pipeline()
    .collection("books")
    .select(field("rating").exists().alias("hasRating"))
    .execute()

Java

例:

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(field("rating").exists().alias("hasRating"))
    .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(Field.of("rating").exists().as_("hasRating"))
    .execute()
)

IS_ABSENT

構文:

is_absent(value: ANY) -> BOOLEAN

説明:

value が欠損値の場合は TRUE、それ以外の場合は FALSE を返します。欠損値は、入力に存在しない値です(ドキュメントに存在しないフィールドなど)。

例:

value is_absent(value)
0L FALSE
"foo" FALSE
NULL FALSE
ABSENT TRUE

IF_ABSENT

構文:

if_absent(value: ANY, replacement: ANY) -> ANY

説明:

value が欠損値の場合、replacement を評価して返します。それ以外の場合は、value を返します。

例:

value replacement if_absent(value, replacement)
5L 0L 5L
NULL 0L NULL
ABSENT 0L 0L

IS_ERROR

構文:

is_error(try: ANY) -> BOOLEAN

説明:

try の評価中にエラーがスローされた場合は、TRUE を返します。一致しない場合、FALSE が返されます。

IF_ERROR

構文:

if_error(try: ANY, catch: ANY) -> ANY

説明:

try の評価中にエラーがスローされた場合は、replacement を評価して返します。それ以外の場合は、try の解決値を返します。