risingwave_expr_impl/scalar/
license.rs1use anyhow::Context;
18use risingwave_common::license::{Feature, LicenseManager};
19use risingwave_common::types::JsonbVal;
20use risingwave_expr::{ExprError, Result, function};
21
22fn test_feature_inner(feature: Feature) -> Result<bool> {
23 feature
24 .check_available()
25 .map_err(|e| ExprError::Internal(anyhow::Error::from(e)))?;
26 Ok(true)
27}
28
29#[function("test_feature(varchar) -> boolean")]
31pub fn test_feature(name: &str) -> Result<bool> {
32 let feature: Feature = name
33 .parse()
34 .with_context(|| format!("no feature named {name}"))?;
35 test_feature_inner(feature)
36}
37
38#[function("test_feature() -> boolean")]
40pub fn test_paid_tier() -> Result<bool> {
41 test_feature_inner(Feature::TestDummy)
42}
43
44#[function("license() -> jsonb")]
46pub fn license() -> Result<JsonbVal> {
47 let license = LicenseManager::get()
48 .license()
49 .map_err(|e| ExprError::Internal(anyhow::Error::from(e)))?;
50
51 let value = jsonbb::to_value(license)
52 .context("failed to serialize license")
53 .map_err(ExprError::Internal)?;
54
55 Ok(JsonbVal::from(value))
56}