Skip to content

Commit

Permalink
fix clippy
Browse files Browse the repository at this point in the history
Signed-off-by: Runji Wang <[email protected]>
  • Loading branch information
wangrunji0408 committed Oct 7, 2023
1 parent 5f3bb4d commit ce9dec4
Show file tree
Hide file tree
Showing 15 changed files with 38 additions and 36 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions src/common/src/array/stream_chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ impl Op {
}

pub fn from_protobuf(prost: &i32) -> ArrayResult<Op> {
let op = match PbOp::from_i32(*prost) {
Some(PbOp::Insert) => Op::Insert,
Some(PbOp::Delete) => Op::Delete,
Some(PbOp::UpdateInsert) => Op::UpdateInsert,
Some(PbOp::UpdateDelete) => Op::UpdateDelete,
Some(PbOp::Unspecified) => unreachable!(),
None => bail!("No such op type"),
let op = match PbOp::try_from(*prost) {
Ok(PbOp::Insert) => Op::Insert,
Ok(PbOp::Delete) => Op::Delete,
Ok(PbOp::UpdateInsert) => Op::UpdateInsert,
Ok(PbOp::UpdateDelete) => Op::UpdateDelete,
Ok(PbOp::Unspecified) => unreachable!(),
Err(_) => bail!("No such op type"),
};
Ok(op)
}
Expand Down
6 changes: 3 additions & 3 deletions src/connector/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ impl SpecificParserConfig {
Some(info.proto_message_name.clone())
},
key_record_name: info.key_message_name.clone(),
name_strategy: PbSchemaRegistryNameStrategy::from_i32(info.name_strategy)
name_strategy: PbSchemaRegistryNameStrategy::try_from(info.name_strategy)
.unwrap(),
use_schema_registry: info.use_schema_registry,
row_schema_location: info.row_schema_location.clone(),
Expand Down Expand Up @@ -887,7 +887,7 @@ impl SpecificParserConfig {
message_name: info.proto_message_name.clone(),
use_schema_registry: info.use_schema_registry,
row_schema_location: info.row_schema_location.clone(),
name_strategy: PbSchemaRegistryNameStrategy::from_i32(info.name_strategy)
name_strategy: PbSchemaRegistryNameStrategy::try_from(info.name_strategy)
.unwrap(),
key_message_name: info.key_message_name.clone(),
..Default::default()
Expand All @@ -912,7 +912,7 @@ impl SpecificParserConfig {
} else {
Some(info.proto_message_name.clone())
},
name_strategy: PbSchemaRegistryNameStrategy::from_i32(info.name_strategy)
name_strategy: PbSchemaRegistryNameStrategy::try_from(info.name_strategy)
.unwrap(),
key_record_name: info.key_message_name.clone(),
row_schema_location: info.row_schema_location.clone(),
Expand Down
2 changes: 1 addition & 1 deletion src/connector/src/sink/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl SinkParam {
.map(|i| *i as usize)
.collect(),
sink_type: SinkType::from_proto(
PbSinkType::from_i32(pb_param.sink_type).expect("should be able to convert"),
PbSinkType::try_from(pb_param.sink_type).expect("should be able to convert"),
),
format_desc,
db_name: pb_param.db_name,
Expand Down
22 changes: 11 additions & 11 deletions src/expr/core/src/window_function/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ impl WindowFuncKind {
use risingwave_pb::expr::window_function::{PbGeneralType, PbType};

let kind = match window_function_type {
PbType::General(typ) => match PbGeneralType::from_i32(*typ) {
Some(PbGeneralType::Unspecified) => bail!("Unspecified window function type"),
Some(PbGeneralType::RowNumber) => Self::RowNumber,
Some(PbGeneralType::Rank) => Self::Rank,
Some(PbGeneralType::DenseRank) => Self::DenseRank,
Some(PbGeneralType::Lag) => Self::Lag,
Some(PbGeneralType::Lead) => Self::Lead,
None => bail!("no such window function type"),
PbType::General(typ) => match PbGeneralType::try_from(*typ) {
Ok(PbGeneralType::Unspecified) => bail!("Unspecified window function type"),
Ok(PbGeneralType::RowNumber) => Self::RowNumber,
Ok(PbGeneralType::Rank) => Self::Rank,
Ok(PbGeneralType::DenseRank) => Self::DenseRank,
Ok(PbGeneralType::Lag) => Self::Lag,
Ok(PbGeneralType::Lead) => Self::Lead,
Err(_) => bail!("no such window function type"),
},
PbType::Aggregate(agg_type) => match PbAggType::from_i32(*agg_type) {
Some(agg_type) => Self::Aggregate(AggKind::from_protobuf(agg_type)?),
None => bail!("no such aggregate function type"),
PbType::Aggregate(agg_type) => match PbAggType::try_from(*agg_type) {
Ok(agg_type) => Self::Aggregate(AggKind::from_protobuf(agg_type)?),
Err(_) => bail!("no such aggregate function type"),
},
};
Ok(kind)
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/catalog/system_catalog/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ fn get_acl_items(
.unwrap()
.iter()
.for_each(|(action, option)| {
let str = match Action::from_i32(*action).unwrap() {
let str = match Action::try_from(*action).unwrap() {
Action::Select => "r",
Action::Insert => "a",
Action::Update => "w",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ impl SysCatalogReaderImpl {
for i in 0..32 {
let bit = 1 << i;
if mask & bit != 0 {
match FragmentTypeFlag::from_i32(bit as i32) {
None => continue,
Some(flag) => result.push(flag),
match FragmentTypeFlag::try_from(bit as i32) {
Err(_) => continue,
Ok(flag) => result.push(flag),
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/scheduler/distributed/stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ impl StageRunner {
match status_res_inner {
Ok(status) => {
use risingwave_pb::task_service::task_info_response::TaskStatus as TaskStatusPb;
match TaskStatusPb::from_i32(status.task_status).unwrap() {
match TaskStatusPb::try_from(status.task_status).unwrap() {
TaskStatusPb::Running => {
running_task_cnt += 1;
// The task running count should always less or equal than the
Expand Down
1 change: 1 addition & 0 deletions src/meta/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ tokio = { version = "0.2", package = "madsim-tokio", features = [
tokio-retry = "0.3"
tokio-stream = { version = "0.1", features = ["net"] }
tonic = { workspace = true }
tonic_0_9 = { package = "tonic", version = "0.9" }
tower = { version = "0.4", features = ["util", "load-shed"] }
tracing = "0.1"
url = "2"
Expand Down
4 changes: 2 additions & 2 deletions src/meta/src/dashboard/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ pub(super) mod handlers {
let mut result = srv
.cluster_manager
.list_worker_node(
WorkerType::from_i32(ty)
.ok_or_else(|| anyhow!("invalid worker type"))
WorkerType::try_from(ty)
.map_err(|_| anyhow!("invalid worker type"))
.map_err(err)?,
None,
)
Expand Down
2 changes: 1 addition & 1 deletion src/meta/src/hummock/manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2700,7 +2700,7 @@ impl HummockManager {
sorted_output_ssts,
table_stats_change
}) => {
if let Err(e) = hummock_manager.report_compact_task(task_id, TaskStatus::from_i32(task_status).unwrap(), sorted_output_ssts, Some(table_stats_change))
if let Err(e) = hummock_manager.report_compact_task(task_id, TaskStatus::try_from(task_status).unwrap(), sorted_output_ssts, Some(table_stats_change))
.await {
tracing::error!("report compact_tack fail {e:?}");
}
Expand Down
2 changes: 1 addition & 1 deletion src/meta/src/hummock/mock_hummock_meta_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ impl HummockMetaClient for MockHummockMetaClient {
if let Err(e) = hummock_manager_compact
.report_compact_task(
task_id,
TaskStatus::from_i32(task_status).unwrap(),
TaskStatus::try_from(task_status).unwrap(),
sorted_output_ssts,
Some(table_stats_change),
)
Expand Down
2 changes: 1 addition & 1 deletion src/meta/src/rpc/service/user_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl UserService for UserServiceImpl {
let update_fields = req
.update_fields
.iter()
.map(|i| UpdateField::from_i32(*i).unwrap())
.map(|i| UpdateField::try_from(*i).unwrap())
.collect_vec();
let user = req.get_user()?.clone();
let version = self
Expand Down
6 changes: 3 additions & 3 deletions src/meta/src/storage/etcd_retry_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ impl EtcdRetryClient {
fn should_retry(err: &Error) -> bool {
match err {
Error::GRpcStatus(status) => {
status.code() == tonic::Code::Unavailable
|| status.code() == tonic::Code::Unknown
|| (status.code() == tonic::Code::Unauthenticated
status.code() == tonic_0_9::Code::Unavailable
|| status.code() == tonic_0_9::Code::Unknown
|| (status.code() == tonic_0_9::Code::Unauthenticated
&& status.message().contains("invalid auth token"))
}
_ => false,
Expand Down
2 changes: 1 addition & 1 deletion src/meta/src/storage/wrapped_etcd_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl EtcdRefreshClient {
fn should_refresh(err: &etcd_client::Error) -> bool {
match err {
etcd_client::Error::GRpcStatus(status) => {
status.code() == tonic::Code::Unauthenticated
status.code() == tonic_0_9::Code::Unauthenticated
&& status.message().contains("invalid auth token")
}
_ => false,
Expand Down

0 comments on commit ce9dec4

Please sign in to comment.