risingwave_frontend/utils/
overwrite_options.rs1use crate::WithOptions;
16use crate::error::{ErrorCode, Result};
17use crate::handler::HandlerArgs;
18
19#[derive(Debug, Clone, Default)]
22pub struct OverwriteOptions {
23 pub source_rate_limit: Option<u32>,
24 pub backfill_rate_limit: Option<u32>,
25 pub dml_rate_limit: Option<u32>,
26 pub sink_rate_limit: Option<u32>,
27}
28
29impl OverwriteOptions {
30 pub(crate) const BACKFILL_RATE_LIMIT_KEY: &'static str = "backfill_rate_limit";
31 pub(crate) const DML_RATE_LIMIT_KEY: &'static str = "dml_rate_limit";
32 pub(crate) const SINK_RATE_LIMIT_KEY: &'static str = "sink_rate_limit";
33 pub(crate) const SOURCE_RATE_LIMIT_KEY: &'static str = "source_rate_limit";
34
35 pub fn new(args: &mut HandlerArgs) -> Result<Self> {
36 let config = args.session.config();
37 let with_options = &mut args.with_options;
38 Ok(Self {
39 source_rate_limit: Self::take_rate_limit(
40 with_options,
41 Self::SOURCE_RATE_LIMIT_KEY,
42 config.source_rate_limit(),
43 )?,
44 backfill_rate_limit: Self::take_rate_limit(
45 with_options,
46 Self::BACKFILL_RATE_LIMIT_KEY,
47 config.backfill_rate_limit(),
48 )?,
49 dml_rate_limit: Self::take_rate_limit(
50 with_options,
51 Self::DML_RATE_LIMIT_KEY,
52 config.dml_rate_limit(),
53 )?,
54 sink_rate_limit: Self::take_rate_limit(
55 with_options,
56 Self::SINK_RATE_LIMIT_KEY,
57 config.sink_rate_limit(),
58 )?,
59 })
60 }
61
62 fn take_rate_limit(
65 with_options: &mut WithOptions,
66 key: &str,
67 session_value: i32,
68 ) -> Result<Option<u32>> {
69 match with_options.remove(key) {
70 Some(value) => value.parse::<u32>().map(Some).map_err(|_| {
71 ErrorCode::InvalidParameterValue(format!(
72 "`{key}` must be a non-negative integer, but got `{value}`"
73 ))
74 .into()
75 }),
76 None => Ok(u32::try_from(session_value).ok()),
77 }
78 }
79}