Skip to content

Commit ea061e9

Browse files
chore: fix cargo clippy issues (#733)
Co-authored-by: Jiangzhou He <[email protected]>
1 parent eaf73dd commit ea061e9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+223
-248
lines changed

src/base/duration.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ fn parse_components(
1818

1919
// Parse digits and optional decimal point
2020
while let Some(&c) = iter.peek() {
21-
if c.is_digit(10) || (c == '.' && !has_decimal) {
21+
if c.is_ascii_digit() || (c == '.' && !has_decimal) {
2222
if c == '.' {
2323
has_decimal = true;
2424
}
@@ -53,8 +53,8 @@ fn parse_components(
5353

5454
/// Parses an ISO 8601 duration string into a `chrono::Duration`.
5555
fn parse_iso8601_duration(s: &str, original_input: &str) -> Result<Duration> {
56-
let (is_negative, s_after_sign) = if s.starts_with('-') {
57-
(true, &s[1..])
56+
let (is_negative, s_after_sign) = if let Some(stripped) = s.strip_prefix('-') {
57+
(true, stripped)
5858
} else {
5959
(false, s)
6060
};
@@ -193,28 +193,21 @@ mod tests {
193193

194194
fn check_ok(res: Result<Duration>, expected: Duration, input_str: &str) {
195195
match res {
196-
Ok(duration) => assert_eq!(duration, expected, "Input: '{}'", input_str),
197-
Err(e) => panic!(
198-
"Input: '{}', expected Ok({:?}), but got Err: {}",
199-
input_str, expected, e
200-
),
196+
Ok(duration) => assert_eq!(duration, expected, "Input: '{input_str}'"),
197+
Err(e) => panic!("Input: '{input_str}', expected Ok({expected:?}), but got Err: {e}"),
201198
}
202199
}
203200

204201
fn check_err_contains(res: Result<Duration>, expected_substring: &str, input_str: &str) {
205202
match res {
206203
Ok(d) => panic!(
207-
"Input: '{}', expected error containing '{}', but got Ok({:?})",
208-
input_str, expected_substring, d
204+
"Input: '{input_str}', expected error containing '{expected_substring}', but got Ok({d:?})"
209205
),
210206
Err(e) => {
211207
let err_msg = e.to_string();
212208
assert!(
213209
err_msg.contains(expected_substring),
214-
"Input: '{}', error message '{}' does not contain expected substring '{}'",
215-
input_str,
216-
err_msg,
217-
expected_substring
210+
"Input: '{input_str}', error message '{err_msg}' does not contain expected substring '{expected_substring}'"
218211
);
219212
}
220213
}

src/base/schema.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl std::fmt::Display for BasicValueType {
8686
BasicValueType::Vector(s) => {
8787
write!(f, "Vector[{}", s.element_type)?;
8888
if let Some(dimension) = s.dimension {
89-
write!(f, ", {}", dimension)?;
89+
write!(f, ", {dimension}")?;
9090
}
9191
write!(f, "]")
9292
}
@@ -97,7 +97,7 @@ impl std::fmt::Display for BasicValueType {
9797
// Add type delimiter
9898
write!(f, " | ")?;
9999
}
100-
write!(f, "{}", typ)?;
100+
write!(f, "{typ}")?;
101101
}
102102
write!(f, "]")
103103
}
@@ -129,13 +129,14 @@ impl std::fmt::Display for StructSchema {
129129
if i > 0 {
130130
write!(f, ", ")?;
131131
}
132-
write!(f, "{}", field)?;
132+
write!(f, "{field}")?;
133133
}
134134
write!(f, ")")
135135
}
136136
}
137137

138138
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
139+
#[allow(clippy::enum_variant_names)]
139140
pub enum TableKind {
140141
/// An table with unordered rows, without key.
141142
UTable,
@@ -307,9 +308,9 @@ impl std::fmt::Display for EnrichedValueType {
307308
impl std::fmt::Display for ValueType {
308309
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
309310
match self {
310-
ValueType::Basic(b) => write!(f, "{}", b),
311-
ValueType::Struct(s) => write!(f, "{}", s),
312-
ValueType::Table(c) => write!(f, "{}", c),
311+
ValueType::Basic(b) => write!(f, "{b}"),
312+
ValueType::Struct(s) => write!(f, "{s}"),
313+
ValueType::Table(c) => write!(f, "{c}"),
313314
}
314315
}
315316
}
@@ -371,7 +372,7 @@ impl std::fmt::Display for CollectorSchema {
371372
if i > 0 {
372373
write!(f, ", ")?;
373374
}
374-
write!(f, "{}", field)?;
375+
write!(f, "{field}")?;
375376
}
376377
write!(f, ")")
377378
}

src/base/spec.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub struct OpArgName(pub Option<String>);
6767
impl fmt::Display for OpArgName {
6868
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
6969
if let Some(arg_name) = &self.0 {
70-
write!(f, "${}", arg_name)
70+
write!(f, "${arg_name}")
7171
} else {
7272
write!(f, "?")
7373
}
@@ -113,7 +113,7 @@ impl fmt::Display for FieldMapping {
113113
if scope.is_empty() {
114114
"".to_string()
115115
} else {
116-
format!("{}.", scope)
116+
format!("{scope}.")
117117
},
118118
self.field_path
119119
)
@@ -129,7 +129,7 @@ pub struct ConstantMapping {
129129
impl fmt::Display for ConstantMapping {
130130
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
131131
let value = serde_json::to_string(&self.value).unwrap_or("#serde_error".to_string());
132-
write!(f, "{}", value)
132+
write!(f, "{value}")
133133
}
134134
}
135135

@@ -152,7 +152,7 @@ impl fmt::Display for StructMapping {
152152
.map(|field| field.name.clone())
153153
.collect::<Vec<_>>()
154154
.join(",");
155-
write!(f, "{}", fields)
155+
write!(f, "{fields}")
156156
}
157157
}
158158

@@ -280,9 +280,9 @@ impl fmt::Display for SourceRefreshOptions {
280280
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
281281
let refresh = self
282282
.refresh_interval
283-
.map(|d| format!("{:?}", d))
283+
.map(|d| format!("{d:?}"))
284284
.unwrap_or("none".to_string());
285-
write!(f, "{}", refresh)
285+
write!(f, "{refresh}")
286286
}
287287
}
288288

@@ -327,8 +327,8 @@ impl SpecFormatter for TransformOpSpec {
327327
.join(",");
328328
let op_str = self.op.format(mode);
329329
match mode {
330-
OutputMode::Concise => format!("op={}, inputs={}", op_str, inputs),
331-
OutputMode::Verbose => format!("op={}, inputs=[{}]", op_str, inputs),
330+
OutputMode::Concise => format!("op={op_str}, inputs={inputs}"),
331+
OutputMode::Verbose => format!("op={op_str}, inputs=[{inputs}]"),
332332
}
333333
}
334334
}
@@ -453,7 +453,7 @@ impl fmt::Display for IndexOptions {
453453
.map(|v| v.to_string())
454454
.collect::<Vec<_>>()
455455
.join(",");
456-
write!(f, "keys={}, indexes={}", primary_keys, vector_indexes)
456+
write!(f, "keys={primary_keys}, indexes={vector_indexes}")
457457
}
458458
}
459459

@@ -494,7 +494,7 @@ impl SpecFormatter for ReactiveOpSpec {
494494
match self {
495495
ReactiveOpSpec::Transform(t) => format!("Transform: {}", t.format(mode)),
496496
ReactiveOpSpec::ForEach(fe) => match mode {
497-
OutputMode::Concise => format!("{}", fe.get_label()),
497+
OutputMode::Concise => fe.get_label().to_string(),
498498
OutputMode::Verbose => format!("ForEach: {}", fe.format(mode)),
499499
},
500500
ReactiveOpSpec::Collect(c) => format!("Collect: {}", c.format(mode)),

src/base/value.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,11 @@ impl std::fmt::Display for KeyValue {
164164
match self {
165165
KeyValue::Bytes(v) => write!(f, "{}", BASE64_STANDARD.encode(v)),
166166
KeyValue::Str(v) => write!(f, "\"{}\"", v.escape_default()),
167-
KeyValue::Bool(v) => write!(f, "{}", v),
168-
KeyValue::Int64(v) => write!(f, "{}", v),
167+
KeyValue::Bool(v) => write!(f, "{v}"),
168+
KeyValue::Int64(v) => write!(f, "{v}"),
169169
KeyValue::Range(v) => write!(f, "[{}, {})", v.start, v.end),
170-
KeyValue::Uuid(v) => write!(f, "{}", v),
171-
KeyValue::Date(v) => write!(f, "{}", v),
170+
KeyValue::Uuid(v) => write!(f, "{v}"),
171+
KeyValue::Date(v) => write!(f, "{v}"),
172172
KeyValue::Struct(v) => {
173173
write!(
174174
f,
@@ -191,7 +191,7 @@ impl KeyValue {
191191
let field_values: FieldValues = FieldValues::from_json(value, fields_schema)?;
192192
Value::Struct(field_values)
193193
};
194-
Ok(value.as_key()?)
194+
value.as_key()
195195
}
196196

197197
pub fn from_values<'a>(values: impl ExactSizeIterator<Item = &'a Value>) -> Result<Self> {
@@ -226,10 +226,10 @@ impl KeyValue {
226226
.next()
227227
.ok_or_else(|| api_error!("Key parts less than expected"))?;
228228
match basic_type {
229-
BasicValueType::Bytes { .. } => {
229+
BasicValueType::Bytes => {
230230
KeyValue::Bytes(Bytes::from(BASE64_STANDARD.decode(v)?))
231231
}
232-
BasicValueType::Str { .. } => KeyValue::Str(Arc::from(v)),
232+
BasicValueType::Str => KeyValue::Str(Arc::from(v)),
233233
BasicValueType::Bool => KeyValue::Bool(v.parse()?),
234234
BasicValueType::Int64 => KeyValue::Int64(v.parse()?),
235235
BasicValueType::Range => {
@@ -1030,12 +1030,10 @@ impl serde::Serialize for BasicValue {
10301030
impl BasicValue {
10311031
pub fn from_json(value: serde_json::Value, schema: &BasicValueType) -> Result<Self> {
10321032
let result = match (value, schema) {
1033-
(serde_json::Value::String(v), BasicValueType::Bytes { .. }) => {
1033+
(serde_json::Value::String(v), BasicValueType::Bytes) => {
10341034
BasicValue::Bytes(Bytes::from(BASE64_STANDARD.decode(v)?))
10351035
}
1036-
(serde_json::Value::String(v), BasicValueType::Str { .. }) => {
1037-
BasicValue::Str(Arc::from(v))
1038-
}
1036+
(serde_json::Value::String(v), BasicValueType::Str) => BasicValue::Str(Arc::from(v)),
10391037
(serde_json::Value::Bool(v), BasicValueType::Bool) => BasicValue::Bool(v),
10401038
(serde_json::Value::Number(v), BasicValueType::Int64) => BasicValue::Int64(
10411039
v.as_i64()

src/builder/analyzer.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -695,9 +695,9 @@ impl AnalyzerContext {
695695
.get_concur_control_options();
696696
let global_concurrency_controller = self.lib_ctx.global_concurrency_controller.clone();
697697
let result_fut = async move {
698-
trace!("Start building executor for source op `{}`", op_name);
698+
trace!("Start building executor for source op `{op_name}`");
699699
let executor = executor.await?;
700-
trace!("Finished building executor for source op `{}`", op_name);
700+
trace!("Finished building executor for source op `{op_name}`");
701701
Ok(AnalyzedImportOp {
702702
executor,
703703
output,
@@ -840,14 +840,15 @@ impl AnalyzerContext {
840840
Ok(result_fut)
841841
}
842842

843+
#[allow(clippy::too_many_arguments)]
843844
async fn analyze_export_op_group(
844845
&self,
845846
target_kind: &str,
846847
op_scope: &Arc<OpScope>,
847848
flow_inst: &FlowInstanceSpec,
848849
export_op_group: &AnalyzedExportTargetOpGroup,
849850
declarations: Vec<serde_json::Value>,
850-
targets_analyzed_ss: &mut Vec<Option<exec_ctx::AnalyzedTargetSetupState>>,
851+
targets_analyzed_ss: &mut [Option<exec_ctx::AnalyzedTargetSetupState>],
851852
declarations_analyzed_ss: &mut Vec<exec_ctx::AnalyzedTargetSetupState>,
852853
) -> Result<Vec<impl Future<Output = Result<AnalyzedExportOp>> + Send + use<>>> {
853854
let mut collection_specs = Vec::<interface::ExportDataCollectionSpec>::new();
@@ -875,7 +876,7 @@ impl AnalyzerContext {
875876

876877
let key_fields_schema = pk_fields_idx
877878
.iter()
878-
.map(|idx| collector_schema.fields[*idx as usize].clone())
879+
.map(|idx| collector_schema.fields[*idx].clone())
879880
.collect::<Vec<_>>();
880881
let primary_key_type = if pk_fields_idx.len() == 1 {
881882
key_fields_schema[0].value_type.typ.clone()

src/builder/exec_ctx.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ pub fn build_flow_setup_execution_context(
239239
.ok_or_else(invariance_violation)?;
240240
build_import_op_exec_ctx(
241241
&import_op.name,
242-
&output_type,
242+
output_type,
243243
source_states_by_name.get(&import_op.name.as_str()),
244244
&mut setup_state.metadata,
245245
)

src/builder/flow_builder.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl std::fmt::Display for OpScopeRef {
4646
#[pymethods]
4747
impl OpScopeRef {
4848
pub fn __str__(&self) -> String {
49-
format!("{}", self)
49+
format!("{self}")
5050
}
5151

5252
pub fn __repr__(&self) -> String {
@@ -105,7 +105,7 @@ impl DataSlice {
105105
}
106106

107107
pub fn __str__(&self) -> String {
108-
format!("{}", self)
108+
format!("{self}")
109109
}
110110

111111
pub fn __repr__(&self) -> String {
@@ -142,7 +142,7 @@ impl DataSlice {
142142
.iter()
143143
.find(|f| f.name == field_name)
144144
.map(|f| f.spec.clone())
145-
.ok_or_else(|| PyException::new_err(format!("field {} not found", field_name)))?,
145+
.ok_or_else(|| PyException::new_err(format!("field {field_name} not found")))?,
146146

147147
spec::ValueMapping::Constant { .. } => {
148148
return Err(PyException::new_err(
@@ -191,7 +191,7 @@ pub struct DataCollector {
191191
#[pymethods]
192192
impl DataCollector {
193193
fn __str__(&self) -> String {
194-
format!("{}", self)
194+
format!("{self}")
195195
}
196196

197197
fn __repr__(&self) -> String {
@@ -271,6 +271,7 @@ impl FlowBuilder {
271271
}
272272

273273
#[pyo3(signature = (kind, op_spec, target_scope, name, refresh_options=None, execution_options=None))]
274+
#[allow(clippy::too_many_arguments)]
274275
pub fn add_source(
275276
&mut self,
276277
py: Python<'_>,
@@ -327,7 +328,7 @@ impl FlowBuilder {
327328
let schema = value_type.into_inner();
328329
let value = py::value_from_py_object(&schema.typ, &value)?;
329330
let slice = DataSlice {
330-
scope: self.root_op_scope.clone().into(),
331+
scope: self.root_op_scope.clone(),
331332
value: Arc::new(spec::ValueMapping::Constant(spec::ConstantMapping {
332333
schema: schema.clone(),
333334
value: serde_json::to_value(value).into_py_result()?,
@@ -571,7 +572,7 @@ impl FlowBuilder {
571572
let (_, field_schema) = scope_builder
572573
.data
573574
.find_field(field_name)
574-
.ok_or_else(|| PyException::new_err(format!("field {} not found", field_name)))?;
575+
.ok_or_else(|| PyException::new_err(format!("field {field_name} not found")))?;
575576
schema::EnrichedValueType::from_alternative(&field_schema.value_type)
576577
.into_py_result()?
577578
};
@@ -671,7 +672,7 @@ impl FlowBuilder {
671672
}
672673

673674
pub fn __str__(&self) -> String {
674-
format!("{}", self)
675+
format!("{self}")
675676
}
676677

677678
pub fn __repr__(&self) -> String {
@@ -713,7 +714,7 @@ impl std::fmt::Display for FlowBuilder {
713714
)?;
714715
}
715716
if let Some(output) = &self.direct_output_value {
716-
write!(f, "Direct output: {}\n\n", output)?;
717+
write!(f, "Direct output: {output}\n\n")?;
717718
}
718719
Ok(())
719720
}

src/execution/db_tracking.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ pub async fn read_source_tracking_info_for_precommit(
136136
Ok(precommit_tracking_info)
137137
}
138138

139+
#[allow(clippy::too_many_arguments)]
139140
pub async fn precommit_source_tracking_info(
140141
source_id: i32,
141142
source_key_json: &serde_json::Value,
@@ -191,6 +192,7 @@ pub async fn read_source_tracking_info_for_commit(
191192
Ok(commit_tracking_info)
192193
}
193194

195+
#[allow(clippy::too_many_arguments)]
194196
pub async fn commit_source_tracking_info(
195197
source_id: i32,
196198
source_key_json: &serde_json::Value,

src/execution/db_tracking_setup.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ impl TrackingTableSetupStatus {
181181
}
182182
} else {
183183
for lagacy_name in self.legacy_table_names.iter() {
184-
let query = format!("DROP TABLE IF EXISTS {}", lagacy_name);
184+
let query = format!("DROP TABLE IF EXISTS {lagacy_name}");
185185
sqlx::query(&query).execute(pool).await?;
186186
}
187187
return Ok(());

src/execution/dumper.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ impl<'a> Dumper<'a> {
207207
let num_keys = keys.len();
208208
keys.into_iter().enumerate().map(move |(i, key)| {
209209
let extra_id = if num_keys > 1 {
210-
Cow::Owned(format!(".{}", i))
210+
Cow::Owned(format!(".{i}"))
211211
} else {
212212
Cow::Borrowed("")
213213
};

0 commit comments

Comments
 (0)