risingwave_expr_impl/scalar/
license.rs

1// Copyright 2025 RisingWave Labs
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Functions for testing whether license-gated features are working.
16
17use 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/// Checks if the given feature is available.
30#[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/// Backward compatibility for `rw_test_paid_tier`.
39#[function("test_feature() -> boolean")]
40pub fn test_paid_tier() -> Result<bool> {
41    test_feature_inner(Feature::TestDummy)
42}
43
44/// Dump the license information.
45#[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}