fix: Remove unused Rust code in generated_types

pull/24376/head
Carol (Nichols || Goulding) 2022-05-04 15:16:13 -04:00
parent e6e0655b31
commit 91961273c2
No known key found for this signature in database
GPG Key ID: E907EE5A736F87D4
4 changed files with 0 additions and 449 deletions

View File

@ -1,213 +0,0 @@
use crate::google::{FieldViolationExt, FromOptionalField, OptionalField};
use std::convert::{TryFrom, TryInto};
use std::num::{NonZeroU32, NonZeroU64, NonZeroUsize};
use data_types::database_rules::{
LifecycleRules, MaxActiveCompactions, DEFAULT_CATALOG_TRANSACTIONS_UNTIL_CHECKPOINT,
DEFAULT_CATALOG_TRANSACTION_PRUNE_AGE, DEFAULT_LATE_ARRIVE_WINDOW_SECONDS,
DEFAULT_MUB_ROW_THRESHOLD, DEFAULT_PERSIST_AGE_THRESHOLD_SECONDS,
DEFAULT_PERSIST_ROW_THRESHOLD, DEFAULT_WORKER_BACKOFF_MILLIS,
};
use crate::google::FieldViolation;
use crate::influxdata::iox::management::v1 as management;
impl From<LifecycleRules> for management::LifecycleRules {
fn from(config: LifecycleRules) -> Self {
Self {
buffer_size_soft: config
.buffer_size_soft
.map(|x| x.get() as u64)
.unwrap_or_default(),
buffer_size_hard: config
.buffer_size_hard
.map(|x| x.get() as u64)
.unwrap_or_default(),
persist: config.persist,
immutable: config.immutable,
worker_backoff_millis: config.worker_backoff_millis.get(),
max_active_compactions_cfg: Some(config.max_active_compactions.into()),
catalog_transactions_until_checkpoint: config
.catalog_transactions_until_checkpoint
.get(),
catalog_transaction_prune_age: Some(config.catalog_transaction_prune_age.into()),
late_arrive_window_seconds: config.late_arrive_window_seconds.get(),
persist_row_threshold: config.persist_row_threshold.get() as u64,
persist_age_threshold_seconds: config.persist_age_threshold_seconds.get(),
mub_row_threshold: config.mub_row_threshold.get() as u64,
parquet_cache_limit: config
.parquet_cache_limit
.map(|v| v.get())
.unwrap_or_default(),
}
}
}
impl From<MaxActiveCompactions> for management::lifecycle_rules::MaxActiveCompactionsCfg {
fn from(max: MaxActiveCompactions) -> Self {
match max {
MaxActiveCompactions::MaxActiveCompactions(n) => Self::MaxActiveCompactions(n.get()),
MaxActiveCompactions::MaxActiveCompactionsCpuFraction { fraction, .. } => {
Self::MaxActiveCompactionsCpuFraction(fraction)
}
}
}
}
impl TryFrom<management::LifecycleRules> for LifecycleRules {
type Error = FieldViolation;
fn try_from(proto: management::LifecycleRules) -> Result<Self, Self::Error> {
let persist_age_threshold_seconds = NonZeroU32::new(proto.persist_age_threshold_seconds)
.unwrap_or_else(|| NonZeroU32::new(DEFAULT_PERSIST_AGE_THRESHOLD_SECONDS).unwrap());
let late_arrive_window_seconds = NonZeroU32::new(proto.late_arrive_window_seconds)
.unwrap_or_else(|| NonZeroU32::new(DEFAULT_LATE_ARRIVE_WINDOW_SECONDS).unwrap());
if persist_age_threshold_seconds < late_arrive_window_seconds {
return Err(FieldViolation {
field: "persist_age_threshold_seconds".to_string(),
description:
"persist_age_threshold_seconds must not be less than late_arrive_window_seconds"
.to_string(),
});
}
Ok(Self {
buffer_size_soft: (proto.buffer_size_soft as usize).try_into().ok(),
buffer_size_hard: (proto.buffer_size_hard as usize).try_into().ok(),
persist: proto.persist,
immutable: proto.immutable,
worker_backoff_millis: NonZeroU64::new(proto.worker_backoff_millis)
.unwrap_or_else(|| NonZeroU64::new(DEFAULT_WORKER_BACKOFF_MILLIS).unwrap()),
max_active_compactions: proto
.max_active_compactions_cfg
.optional("max_active_compactions")?
.unwrap_or_default(),
catalog_transactions_until_checkpoint: NonZeroU64::new(
proto.catalog_transactions_until_checkpoint,
)
.unwrap_or_else(|| {
NonZeroU64::new(DEFAULT_CATALOG_TRANSACTIONS_UNTIL_CHECKPOINT).unwrap()
}),
catalog_transaction_prune_age: match proto.catalog_transaction_prune_age {
Some(d) => d.try_into().scope("catalog_transaction_prune_age")?,
None => DEFAULT_CATALOG_TRANSACTION_PRUNE_AGE,
},
late_arrive_window_seconds,
persist_row_threshold: NonZeroUsize::new(proto.persist_row_threshold as usize)
.unwrap_or_else(|| {
NonZeroUsize::new(DEFAULT_PERSIST_ROW_THRESHOLD as usize).unwrap()
}),
persist_age_threshold_seconds,
mub_row_threshold: NonZeroUsize::new(proto.mub_row_threshold as usize)
.unwrap_or_else(|| NonZeroUsize::new(DEFAULT_MUB_ROW_THRESHOLD).unwrap()),
parquet_cache_limit: NonZeroU64::new(proto.parquet_cache_limit),
})
}
}
impl TryFrom<management::lifecycle_rules::MaxActiveCompactionsCfg> for MaxActiveCompactions {
type Error = FieldViolation;
fn try_from(
value: management::lifecycle_rules::MaxActiveCompactionsCfg,
) -> Result<Self, Self::Error> {
use management::lifecycle_rules::MaxActiveCompactionsCfg::*;
Ok(match value {
MaxActiveCompactions(n) => {
Self::MaxActiveCompactions(NonZeroU32::new(n).unwrap_field("")?)
}
MaxActiveCompactionsCpuFraction(fraction) => Self::new(fraction),
})
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn lifecycle_rules() {
let mut protobuf = management::LifecycleRules {
buffer_size_soft: 353,
buffer_size_hard: 232,
persist: true,
immutable: true,
worker_backoff_millis: 1000,
max_active_compactions_cfg: Some(
management::lifecycle_rules::MaxActiveCompactionsCfg::MaxActiveCompactions(8),
),
catalog_transactions_until_checkpoint: 10,
catalog_transaction_prune_age: Some(pbjson_types::Duration {
seconds: 11,
nanos: 22,
}),
late_arrive_window_seconds: 23,
persist_row_threshold: 57,
persist_age_threshold_seconds: 60,
mub_row_threshold: 3454,
parquet_cache_limit: 10,
};
let config: LifecycleRules = protobuf.clone().try_into().unwrap();
let back: management::LifecycleRules = config.clone().into();
assert_eq!(
config.buffer_size_soft.unwrap().get(),
protobuf.buffer_size_soft as usize
);
assert_eq!(
config.buffer_size_hard.unwrap().get(),
protobuf.buffer_size_hard as usize
);
assert_eq!(config.immutable, protobuf.immutable);
assert_eq!(back.buffer_size_soft, protobuf.buffer_size_soft);
assert_eq!(back.buffer_size_hard, protobuf.buffer_size_hard);
assert_eq!(back.immutable, protobuf.immutable);
assert_eq!(back.worker_backoff_millis, protobuf.worker_backoff_millis);
assert_eq!(
back.max_active_compactions_cfg,
protobuf.max_active_compactions_cfg
);
assert_eq!(
back.catalog_transactions_until_checkpoint,
protobuf.catalog_transactions_until_checkpoint
);
assert_eq!(
back.catalog_transaction_prune_age,
protobuf.catalog_transaction_prune_age
);
assert_eq!(
back.late_arrive_window_seconds,
protobuf.late_arrive_window_seconds
);
assert_eq!(back.persist_row_threshold, protobuf.persist_row_threshold);
assert_eq!(
back.persist_age_threshold_seconds,
protobuf.persist_age_threshold_seconds
);
assert_eq!(back.mub_row_threshold, protobuf.mub_row_threshold);
assert_eq!(
config.parquet_cache_limit.unwrap().get(),
protobuf.parquet_cache_limit
);
assert_eq!(back.parquet_cache_limit, protobuf.parquet_cache_limit);
protobuf.late_arrive_window_seconds = 20;
protobuf.persist_age_threshold_seconds = 4;
let e = LifecycleRules::try_from(protobuf).unwrap_err().to_string();
assert_eq!(e, "Violation for field \"persist_age_threshold_seconds\": persist_age_threshold_seconds must not be less than late_arrive_window_seconds");
}
#[test]
fn lifecycle_rules_default() {
let protobuf = management::LifecycleRules::default();
let config: LifecycleRules = protobuf.try_into().unwrap();
assert_eq!(config, LifecycleRules::default());
assert_eq!(config.max_active_compactions.get(), num_cpus::get() as u32);
}
}

View File

@ -1,181 +0,0 @@
use std::convert::TryFrom;
use data_types::database_rules::{PartitionTemplate, RegexCapture, StrftimeColumn, TemplatePart};
use crate::google::protobuf::Empty;
use crate::google::{FieldViolation, FromOptionalField, FromRepeatedField, NonEmptyString};
use crate::influxdata::iox::management::v1 as management;
impl From<PartitionTemplate> for management::PartitionTemplate {
fn from(pt: PartitionTemplate) -> Self {
Self {
parts: pt.parts.into_iter().map(Into::into).collect(),
}
}
}
impl TryFrom<management::PartitionTemplate> for PartitionTemplate {
type Error = FieldViolation;
fn try_from(proto: management::PartitionTemplate) -> Result<Self, Self::Error> {
let parts = proto.parts.repeated("parts")?;
Ok(Self { parts })
}
}
impl From<TemplatePart> for management::partition_template::part::Part {
fn from(part: TemplatePart) -> Self {
use management::partition_template::part::ColumnFormat;
match part {
TemplatePart::Table => Self::Table(Empty {}),
TemplatePart::Column(column) => Self::Column(column),
TemplatePart::RegexCapture(RegexCapture { column, regex }) => {
Self::Regex(ColumnFormat {
column,
format: regex,
})
}
TemplatePart::StrftimeColumn(StrftimeColumn { column, format }) => {
Self::StrfTime(ColumnFormat { column, format })
}
TemplatePart::TimeFormat(format) => Self::Time(format),
}
}
}
impl TryFrom<management::partition_template::part::Part> for TemplatePart {
type Error = FieldViolation;
fn try_from(proto: management::partition_template::part::Part) -> Result<Self, Self::Error> {
use management::partition_template::part::{ColumnFormat, Part};
Ok(match proto {
Part::Table(_) => Self::Table,
Part::Column(column) => Self::Column(column.non_empty("column")?),
Part::Regex(ColumnFormat { column, format }) => Self::RegexCapture(RegexCapture {
column: column.non_empty("regex.column")?,
regex: format.non_empty("regex.format")?,
}),
Part::StrfTime(ColumnFormat { column, format }) => {
Self::StrftimeColumn(StrftimeColumn {
column: column.non_empty("strf_time.column")?,
format: format.non_empty("strf_time.format")?,
})
}
Part::Time(format) => Self::TimeFormat(format.non_empty("time")?),
})
}
}
impl From<TemplatePart> for management::partition_template::Part {
fn from(part: TemplatePart) -> Self {
Self {
part: Some(part.into()),
}
}
}
impl TryFrom<management::partition_template::Part> for TemplatePart {
type Error = FieldViolation;
fn try_from(proto: management::partition_template::Part) -> Result<Self, Self::Error> {
proto.part.required("part")
}
}
#[cfg(test)]
mod tests {
use super::*;
use data_types::database_rules::DatabaseRules;
use std::convert::TryInto;
#[test]
fn test_partition_template_default() {
let protobuf = management::DatabaseRules {
name: "database".to_string(),
partition_template: Some(management::PartitionTemplate { parts: vec![] }),
..Default::default()
};
let rules: DatabaseRules = protobuf.clone().try_into().unwrap();
let back: management::DatabaseRules = rules.clone().into();
assert_eq!(rules.partition_template.parts.len(), 0);
assert_eq!(protobuf.partition_template, back.partition_template);
}
#[test]
fn test_partition_template_no_part() {
let protobuf = management::DatabaseRules {
name: "database".to_string(),
partition_template: Some(management::PartitionTemplate {
parts: vec![Default::default()],
}),
..Default::default()
};
let res: Result<DatabaseRules, _> = protobuf.try_into();
let err = res.expect_err("expected failure");
assert_eq!(&err.field, "partition_template.parts.0.part");
assert_eq!(&err.description, "Field is required");
}
#[test]
fn test_partition_template() {
use management::partition_template::part::{ColumnFormat, Part};
let protobuf = management::PartitionTemplate {
parts: vec![
management::partition_template::Part {
part: Some(Part::Time("time".to_string())),
},
management::partition_template::Part {
part: Some(Part::Table(Empty {})),
},
management::partition_template::Part {
part: Some(Part::Regex(ColumnFormat {
column: "column".to_string(),
format: "format".to_string(),
})),
},
],
};
let pt: PartitionTemplate = protobuf.clone().try_into().unwrap();
let back: management::PartitionTemplate = pt.clone().into();
assert_eq!(
pt.parts,
vec![
TemplatePart::TimeFormat("time".to_string()),
TemplatePart::Table,
TemplatePart::RegexCapture(RegexCapture {
column: "column".to_string(),
regex: "format".to_string()
})
]
);
assert_eq!(protobuf, back);
}
#[test]
fn test_partition_template_empty() {
use management::partition_template::part::{ColumnFormat, Part};
let protobuf = management::PartitionTemplate {
parts: vec![management::partition_template::Part {
part: Some(Part::Regex(ColumnFormat {
..Default::default()
})),
}],
};
let res: Result<PartitionTemplate, _> = protobuf.try_into();
let err = res.expect_err("expected failure");
assert_eq!(&err.field, "parts.0.part.regex.column");
assert_eq!(&err.description, "Field is required");
}
}

View File

@ -215,8 +215,6 @@ pub mod google;
pub mod delete_predicate;
#[cfg(any(feature = "data_types_conversions", test))]
pub mod ingester;
#[cfg(any(feature = "data_types_conversions", test))]
pub mod write_buffer;
pub use prost::{DecodeError, EncodeError};

View File

@ -1,53 +0,0 @@
use crate::{
google::{FieldViolation, FromOptionalField},
influxdata::iox::write_buffer::v1 as write_buffer,
};
use data_types::write_buffer::{
WriteBufferConnection, WriteBufferCreationConfig, DEFAULT_N_SEQUENCERS,
};
use std::{convert::TryFrom, num::NonZeroU32};
impl From<WriteBufferConnection> for write_buffer::WriteBufferConnection {
fn from(v: WriteBufferConnection) -> Self {
Self {
r#type: v.type_,
connection: v.connection,
connection_config: v.connection_config.into_iter().collect(),
creation_config: v.creation_config.map(|x| x.into()),
}
}
}
impl From<WriteBufferCreationConfig> for write_buffer::WriteBufferCreationConfig {
fn from(v: WriteBufferCreationConfig) -> Self {
Self {
n_sequencers: v.n_sequencers.get(),
options: v.options.into_iter().collect(),
}
}
}
impl TryFrom<write_buffer::WriteBufferConnection> for WriteBufferConnection {
type Error = FieldViolation;
fn try_from(proto: write_buffer::WriteBufferConnection) -> Result<Self, Self::Error> {
Ok(Self {
type_: proto.r#type,
connection: proto.connection,
connection_config: proto.connection_config.into_iter().collect(),
creation_config: proto.creation_config.optional("creation_config")?,
})
}
}
impl TryFrom<write_buffer::WriteBufferCreationConfig> for WriteBufferCreationConfig {
type Error = FieldViolation;
fn try_from(proto: write_buffer::WriteBufferCreationConfig) -> Result<Self, Self::Error> {
Ok(Self {
n_sequencers: NonZeroU32::try_from(proto.n_sequencers)
.unwrap_or_else(|_| NonZeroU32::try_from(DEFAULT_N_SEQUENCERS).unwrap()),
options: proto.options.into_iter().collect(),
})
}
}