Skip to content

Commit 0341c85

Browse files
authored
refactor(cubesql): Fix clippy warnings in cubesql, part 1 (#9052)
* refactor(pg-srv): Fix redundant_slicing warning * refactor(cubesql): Fix redundant_slicing warning * refactor(pg-srv): Fix single_char_add_str warning * refactor(pg-srv): Fix single_match warning * refactor(pg-srv): Fix to_string_trait_impl warning * refactor(cubesql): Fix assign_op_pattern warning * refactor(cubesql): Fix bool_assert_comparison warning * refactor(cubesql): Fix bool_comparison warning * refactor(cubesql): Fix borrowed_box warning * refactor(cubesql): Fix cast_abs_to_unsigned warning * refactor(cubesql): Fix cmp_owned warning * refactor(cubesql): Fix expect_fun_call warning * refactor(cubesql): Fix explicit_auto_deref warning * refactor(cubesql): Fix extra_unused_lifetimes warning * refactor(cubesql): Fix filter_map_bool_then warning * refactor(cubesql): Fix filter_map_identity warning * refactor(cubesql): Simplify CloseCursor::All handling * refactor(cubesql): Fix for_kv_map warning * refactor(cubesql): Fix get_first warning * refactor(cubesql): Fix identity_op warning * refactor(cubesql): Enable manual_filter warning * refactor(cubesql): Fix manual_is_ascii_check warning * refactor(cubesql): Fix manual_map warning * refactor(cubesql): Fix manual_strip warning * refactor(cubesql): Fix to_string_in_format_args warning
1 parent bde6eea commit 0341c85

File tree

17 files changed

+89
-142
lines changed

17 files changed

+89
-142
lines changed

rust/cubesql/cubesql/Cargo.toml

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -90,40 +90,22 @@ harness = false
9090
# Feel free to remove any rule from here and fix all warnings with it
9191
# Or to write a comment why rule should stay disabled
9292
[lints.clippy]
93-
assign_op_pattern = "allow"
94-
bool_assert_comparison = "allow"
95-
bool_comparison = "allow"
96-
borrowed_box = "allow"
97-
cast_abs_to_unsigned = "allow"
9893
clone_on_copy = "allow"
99-
cmp_owned = "allow"
10094
collapsible_if = "allow"
10195
collapsible_match = "allow"
10296
collapsible_else_if = "allow"
10397
comparison_chain = "allow"
10498
derive_ord_xor_partial_ord = "allow"
105-
expect_fun_call = "allow"
106-
explicit_auto_deref = "allow"
107-
extra_unused_lifetimes = "allow"
10899
field_reassign_with_default = "allow"
109-
filter_map_bool_then = "allow"
110-
filter_map_identity = "allow"
111-
for_kv_map = "allow"
112-
get_first = "allow"
113-
identity_op = "allow"
114100
if_same_then_else = "allow"
115101
into_iter_on_ref = "allow"
116102
iter_cloned_collect = "allow"
117103
iter_next_slice = "allow"
118104
len_without_is_empty = "allow"
119105
len_zero = "allow"
120106
let_and_return = "allow"
121-
manual_filter = "allow"
122107
manual_flatten = "allow"
123-
manual_is_ascii_check = "allow"
124-
manual_map = "allow"
125108
manual_range_contains = "allow"
126-
manual_strip = "allow"
127109
map_clone = "allow"
128110
map_flatten = "allow"
129111
map_identity = "allow"
@@ -152,11 +134,9 @@ redundant_closure = "allow"
152134
redundant_field_names = "allow"
153135
redundant_pattern = "allow"
154136
redundant_pattern_matching = "allow"
155-
redundant_slicing = "allow"
156137
result_large_err = "allow"
157138
single_match = "allow"
158139
should_implement_trait = "allow"
159-
to_string_in_format_args = "allow"
160140
to_string_trait_impl = "allow"
161141
too_many_arguments = "allow"
162142
type_complexity = "allow"

rust/cubesql/cubesql/e2e/tests/postgres.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl PostgresIntegrationTestSuite {
8383
services.wait_processing_loops().await.unwrap();
8484
});
8585

86-
sleep(Duration::from_millis(1 * 1000)).await;
86+
sleep(Duration::from_secs(1)).await;
8787

8888
let client = PostgresIntegrationTestSuite::create_client(
8989
format!("host=127.0.0.1 port={} user=test password=test", port)
@@ -142,15 +142,15 @@ impl PostgresIntegrationTestSuite {
142142
column.type_().oid(),
143143
PgType::get_by_tid(
144144
PgTypeId::from_oid(column.type_().oid())
145-
.expect(&format!("Unknown oid {}", column.type_().oid()))
145+
.unwrap_or_else(|| panic!("Unknown oid {}", column.type_().oid()))
146146
)
147147
.typname,
148148
));
149149
}
150150

151151
// We dont need data when with_rows = false, but it's useful for testing that data type is correct
152152
match PgTypeId::from_oid(column.type_().oid())
153-
.expect(&format!("Unknown type oid: {}", column.type_().oid()))
153+
.unwrap_or_else(|| panic!("Unknown type oid: {}", column.type_().oid()))
154154
{
155155
PgTypeId::INT8 => {
156156
let value: Option<i64> = row.get(idx);
@@ -1269,7 +1269,7 @@ impl AsyncTestSuite for PostgresIntegrationTestSuite {
12691269
|rows| {
12701270
assert_eq!(rows.len(), 1);
12711271

1272-
let columns = rows.get(0).unwrap().columns();
1272+
let columns = rows.first().unwrap().columns();
12731273
assert_eq!(
12741274
columns
12751275
.into_iter()

rust/cubesql/cubesql/src/compile/engine/df/scan.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -751,11 +751,7 @@ impl CubeScanOneShotStream {
751751
}
752752

753753
fn poll_next(&mut self) -> Option<ArrowResult<RecordBatch>> {
754-
if let Some(batch) = self.data.take() {
755-
Some(Ok(batch))
756-
} else {
757-
None
758-
}
754+
self.data.take().map(Ok)
759755
}
760756
}
761757

rust/cubesql/cubesql/src/compile/engine/udf/common.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,7 +1418,7 @@ fn date_addsub_year_month(t: NaiveDateTime, i: i32, is_add: bool) -> Result<Naiv
14181418
}
14191419
debug_assert!(0 <= month);
14201420
year += month / 12;
1421-
month = month % 12;
1421+
month %= 12;
14221422

14231423
match change_ym(t, year, 1 + month as u32) {
14241424
Some(t) => return Ok(t),
@@ -1442,13 +1442,13 @@ fn date_addsub_month_day_nano(
14421442
let result = if month > 0 && is_add || month < 0 && !is_add {
14431443
t.checked_add_months(Months::new(month as u32))
14441444
} else {
1445-
t.checked_sub_months(Months::new(month.abs() as u32))
1445+
t.checked_sub_months(Months::new(month.unsigned_abs()))
14461446
};
14471447

14481448
let result = if day > 0 && is_add || day < 0 && !is_add {
14491449
result.and_then(|t| t.checked_add_days(Days::new(day as u64)))
14501450
} else {
1451-
result.and_then(|t| t.checked_sub_days(Days::new(day.abs() as u64)))
1451+
result.and_then(|t| t.checked_sub_days(Days::new(day.unsigned_abs() as u64)))
14521452
};
14531453

14541454
let result = result.and_then(|t| {
@@ -1472,7 +1472,7 @@ fn date_addsub_day_time(
14721472
let result = if days > 0 && is_add || days < 0 && !is_add {
14731473
t.checked_add_days(Days::new(days as u64))
14741474
} else {
1475-
t.checked_sub_days(Days::new(days.abs() as u64))
1475+
t.checked_sub_days(Days::new(days.unsigned_abs() as u64))
14761476
};
14771477

14781478
let result = result.and_then(|t| {
@@ -1501,9 +1501,9 @@ fn last_day_of_month(y: i32, m: u32) -> u32 {
15011501
return 31;
15021502
}
15031503
NaiveDate::from_ymd_opt(y, m + 1, 1)
1504-
.expect(&format!("Invalid year month: {}-{}", y, m))
1504+
.unwrap_or_else(|| panic!("Invalid year month: {}-{}", y, m))
15051505
.pred_opt()
1506-
.expect(&format!("Invalid year month: {}-{}", y, m))
1506+
.unwrap_or_else(|| panic!("Invalid year month: {}-{}", y, m))
15071507
.day()
15081508
}
15091509

@@ -1564,10 +1564,7 @@ pub fn create_str_to_date_udf() -> ScalarUDF {
15641564

15651565
let res = NaiveDateTime::parse_from_str(timestamp, &format).map_err(|e| {
15661566
DataFusionError::Execution(format!(
1567-
"Error evaluating str_to_date('{}', '{}'): {}",
1568-
timestamp,
1569-
format,
1570-
e.to_string()
1567+
"Error evaluating str_to_date('{timestamp}', '{format}'): {e}"
15711568
))
15721569
})?;
15731570

@@ -1671,7 +1668,7 @@ pub fn create_to_char_udf() -> ScalarUDF {
16711668
let secs = duration.num_seconds();
16721669
let nanosecs = duration.num_nanoseconds().unwrap_or(0) - secs * 1_000_000_000;
16731670
let timestamp = NaiveDateTime::from_timestamp_opt(secs, nanosecs as u32)
1674-
.expect(format!("Invalid secs {} nanosecs {}", secs, nanosecs).as_str());
1671+
.unwrap_or_else(|| panic!("Invalid secs {} nanosecs {}", secs, nanosecs));
16751672

16761673
// chrono's strftime is missing quarter format, as such a workaround is required
16771674
let quarter = &format!("{}", timestamp.date().month0() / 3 + 1);
@@ -2237,10 +2234,7 @@ pub fn create_pg_get_constraintdef_udf() -> ScalarUDF {
22372234
let oids_arr = downcast_primitive_arg!(args[0], "oid", OidType);
22382235
let result = oids_arr
22392236
.iter()
2240-
.map(|oid| match oid {
2241-
Some(_oid) => Some("PRIMARY KEY (oid)".to_string()),
2242-
_ => None,
2243-
})
2237+
.map(|oid| oid.map(|_oid| "PRIMARY KEY (oid)".to_string()))
22442238
.collect::<StringArray>();
22452239

22462240
Ok(Arc::new(result))
@@ -3583,7 +3577,7 @@ pub fn create_array_to_string_udf() -> ScalarUDF {
35833577
let join_str = join_strs.value(i);
35843578
let strings = downcast_string_arg!(array, "str", i32);
35853579
let joined_string =
3586-
itertools::Itertools::intersperse(strings.iter().filter_map(|s| s), join_str)
3580+
itertools::Itertools::intersperse(strings.iter().flatten(), join_str)
35873581
.collect::<String>();
35883582
builder.append_value(joined_string)?;
35893583
}

rust/cubesql/cubesql/src/compile/engine/variable_provider.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl VariablesProvider {
2525

2626
fn get_session_value(&self, identifier: Vec<String>, var_type: VarType) -> Result<ScalarValue> {
2727
let key = if identifier.len() > 1 {
28-
let ignore_first = identifier[0].to_ascii_lowercase() == "@@session".to_owned();
28+
let ignore_first = identifier[0].to_ascii_lowercase() == "@@session";
2929
if ignore_first {
3030
identifier[1..].concat()
3131
} else {
@@ -48,7 +48,7 @@ impl VariablesProvider {
4848

4949
fn get_global_value(&self, identifier: Vec<String>) -> Result<ScalarValue> {
5050
let key = if identifier.len() > 1 {
51-
let ignore_first = identifier[0].to_ascii_lowercase() == "@@global".to_owned();
51+
let ignore_first = identifier[0].to_ascii_lowercase() == "@@global";
5252

5353
if ignore_first {
5454
identifier[1..].concat()
@@ -85,9 +85,7 @@ impl VarProvider for VariablesProvider {
8585

8686
match (&first_word_vec[0], &first_word_vec[1]) {
8787
('@', '@') => {
88-
if identifier.len() > 1
89-
&& identifier[0].to_ascii_lowercase() == "@@session".to_owned()
90-
{
88+
if identifier.len() > 1 && identifier[0].to_ascii_lowercase() == "@@session" {
9189
return self.get_session_value(identifier, VarType::System);
9290
}
9391

rust/cubesql/cubesql/src/compile/parser.rs

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ impl Dialect for MySqlDialectWithBackTicks {
2323
// See https://dev.mysql.com/doc/refman/8.0/en/identifiers.html.
2424
// We don't yet support identifiers beginning with numbers, as that
2525
// makes it hard to distinguish numeric literals.
26-
('a'..='z').contains(&ch)
27-
|| ('A'..='Z').contains(&ch)
26+
ch.is_ascii_lowercase()
27+
|| ch.is_ascii_uppercase()
2828
|| ch == '_'
2929
|| ch == '$'
3030
|| ch == '@'
3131
|| ('\u{0080}'..='\u{ffff}').contains(&ch)
3232
}
3333

3434
fn is_identifier_part(&self, ch: char) -> bool {
35-
self.is_identifier_start(ch) || ('0'..='9').contains(&ch)
35+
self.is_identifier_start(ch) || ch.is_ascii_digit()
3636
}
3737
}
3838

@@ -293,11 +293,9 @@ mod tests {
293293
);
294294
match result {
295295
Ok(_) => panic!("This test should throw an error"),
296-
Err(err) => assert_eq!(
297-
true,
298-
err.to_string()
299-
.contains("Invalid query, no statements was specified")
300-
),
296+
Err(err) => assert!(err
297+
.to_string()
298+
.contains("Invalid query, no statements was specified")),
301299
}
302300
}
303301

@@ -310,11 +308,9 @@ mod tests {
310308
);
311309
match result {
312310
Ok(_) => panic!("This test should throw an error"),
313-
Err(err) => assert_eq!(
314-
true,
315-
err.to_string()
316-
.contains("Multiple statements was specified in one query")
317-
),
311+
Err(err) => assert!(err
312+
.to_string()
313+
.contains("Multiple statements was specified in one query")),
318314
}
319315
}
320316

@@ -349,11 +345,9 @@ mod tests {
349345
);
350346
match result {
351347
Ok(_) => panic!("This test should throw an error"),
352-
Err(err) => assert_eq!(
353-
true,
354-
err.to_string()
355-
.contains("Invalid query, no statements was specified")
356-
),
348+
Err(err) => assert!(err
349+
.to_string()
350+
.contains("Invalid query, no statements was specified")),
357351
}
358352
}
359353

@@ -366,11 +360,9 @@ mod tests {
366360
);
367361
match result {
368362
Ok(_) => panic!("This test should throw an error"),
369-
Err(err) => assert_eq!(
370-
true,
371-
err.to_string()
372-
.contains("Multiple statements was specified in one query")
373-
),
363+
Err(err) => assert!(err
364+
.to_string()
365+
.contains("Multiple statements was specified in one query")),
374366
}
375367
}
376368

rust/cubesql/cubesql/src/compile/rewrite/analysis.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ impl LogicalPlanAnalysis {
551551
.unwrap();
552552
let expr = original_expr(params[2])?;
553553
map.push((
554-
Some(format!("{}.{}", cube, field_name.to_string())),
554+
Some(format!("{cube}.{field_name}")),
555555
Member::VirtualField {
556556
name: field_name.to_string(),
557557
cube: cube.to_string(),

rust/cubesql/cubesql/src/compile/rewrite/rewriter.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -550,10 +550,12 @@ impl egg::RewriteScheduler<LogicalPlanLanguage, LogicalPlanAnalysis> for Increme
550550
if iteration != self.current_iter {
551551
self.current_iter = iteration;
552552
self.current_eclasses.clear();
553-
self.current_eclasses
554-
.extend(egraph.classes().filter_map(|class| {
555-
(class.data.iteration_timestamp >= iteration).then(|| class.id)
556-
}));
553+
self.current_eclasses.extend(
554+
egraph
555+
.classes()
556+
.filter(|class| (class.data.iteration_timestamp >= iteration))
557+
.map(|class| class.id),
558+
);
557559
};
558560
assert_eq!(iteration, self.current_iter);
559561
rewrite.searcher.search_eclasses_with_limit(

rust/cubesql/cubesql/src/compile/rewrite/rules/filters.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2780,12 +2780,13 @@ impl FilterRules {
27802780
value.to_string()
27812781
}
27822782
} else if op == "endsWith" || op == "notEndsWith" {
2783-
if value.starts_with("%") {
2784-
let without_wildcard = value[1..].to_string();
2783+
if let Some(without_wildcard) =
2784+
value.strip_prefix("%")
2785+
{
27852786
if without_wildcard.contains("%") {
27862787
continue;
27872788
}
2788-
without_wildcard
2789+
without_wildcard.to_string()
27892790
} else {
27902791
value.to_string()
27912792
}

rust/cubesql/cubesql/src/compile/router.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,7 @@ impl QueryRouter {
168168
DatabaseProtocol::PostgreSQL,
169169
) if object_type == &ast::ObjectType::Table => self.drop_table_to_plan(names).await,
170170
_ => Err(CompilationError::unsupported(format!(
171-
"Unsupported query type: {}",
172-
stmt.to_string()
171+
"Unsupported query type: {stmt}"
173172
))),
174173
};
175174

@@ -348,7 +347,7 @@ impl QueryRouter {
348347
}
349348
DatabaseProtocol::MySQL => {
350349
for key_value in key_values.iter() {
351-
if key_value.key.value.to_lowercase() == "autocommit".to_string() {
350+
if key_value.key.value.to_lowercase() == "autocommit" {
352351
flags |= StatusFlags::AUTOCOMMIT;
353352

354353
break;
@@ -513,7 +512,7 @@ impl QueryRouter {
513512
async fn select_into_to_plan(
514513
&self,
515514
into: &ast::SelectInto,
516-
query: &Box<ast::Query>,
515+
query: &ast::Query,
517516
qtrace: &mut Option<Qtrace>,
518517
span_id: Option<Arc<SpanId>>,
519518
) -> Result<QueryPlan, CompilationError> {
@@ -531,7 +530,7 @@ impl QueryRouter {
531530
"query is unexpectedly not SELECT".to_string(),
532531
));
533532
}
534-
let new_stmt = ast::Statement::Query(new_query);
533+
let new_stmt = ast::Statement::Query(Box::new(new_query));
535534
self.create_table_to_plan(&into.name, &new_stmt, qtrace, span_id)
536535
.await
537536
}

0 commit comments

Comments
 (0)