risingwave_expr_impl/table_function/
jsonb.rs1use anyhow::anyhow;
18use risingwave_common::types::JsonbRef;
19use risingwave_expr::{Result, function};
20
21#[function("jsonb_array_elements(jsonb) -> setof jsonb")]
23fn jsonb_array_elements(json: JsonbRef<'_>) -> Result<impl Iterator<Item = JsonbRef<'_>>> {
24 json.array_elements().map_err(|e| anyhow!(e).into())
25}
26
27#[function("jsonb_array_elements_text(jsonb) -> setof varchar")]
29fn jsonb_array_elements_text(json: JsonbRef<'_>) -> Result<impl Iterator<Item = Box<str>> + '_> {
30 let elems = jsonb_array_elements(json)?;
31 Ok(elems.map(|elem| elem.force_string().into()))
32}
33
34#[function("jsonb_object_keys(jsonb) -> setof varchar")]
36fn jsonb_object_keys(json: JsonbRef<'_>) -> Result<impl Iterator<Item = &str>> {
37 json.object_keys().map_err(|e| anyhow!(e).into())
38}
39
40#[function("jsonb_each(jsonb) -> setof struct<key varchar, value jsonb>")]
42fn jsonb_each(json: JsonbRef<'_>) -> Result<impl Iterator<Item = (&str, JsonbRef<'_>)> + '_> {
43 json.object_key_values().map_err(|e| anyhow!(e).into())
44}
45
46#[function("jsonb_each_text(jsonb) -> setof struct<key varchar, value varchar>")]
48fn jsonb_each_text(json: JsonbRef<'_>) -> Result<impl Iterator<Item = (&str, Box<str>)> + '_> {
49 let elems = jsonb_each(json)?;
50 Ok(elems.map(|(k, v)| (k, v.force_string().into())))
51}