Skip to content

refactor(cubesql): Fix clippy warnings in cubesql, part 1 #9052

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
7ab3255
refactor(pg-srv): Fix redundant_slicing warning
mcheshkov Dec 13, 2024
e452c82
refactor(cubesql): Fix redundant_slicing warning
mcheshkov Dec 13, 2024
dbe85c4
refactor(pg-srv): Fix single_char_add_str warning
mcheshkov Dec 13, 2024
41df079
refactor(pg-srv): Fix single_match warning
mcheshkov Dec 13, 2024
627cbff
refactor(pg-srv): Fix to_string_trait_impl warning
mcheshkov Dec 13, 2024
c713865
refactor(cubesql): Fix assign_op_pattern warning
mcheshkov Dec 13, 2024
94d395c
refactor(cubesql): Fix bool_assert_comparison warning
mcheshkov Dec 13, 2024
34e7fe5
refactor(cubesql): Fix bool_comparison warning
mcheshkov Dec 13, 2024
ce69f17
refactor(cubesql): Fix borrowed_box warning
mcheshkov Dec 13, 2024
5396ff4
refactor(cubesql): Fix cast_abs_to_unsigned warning
mcheshkov Dec 13, 2024
3936b2f
refactor(cubesql): Fix cmp_owned warning
mcheshkov Dec 13, 2024
6895d5d
refactor(cubesql): Fix expect_fun_call warning
mcheshkov Dec 13, 2024
9cd8e5a
refactor(cubesql): Fix explicit_auto_deref warning
mcheshkov Dec 13, 2024
c7b3e6c
refactor(cubesql): Fix extra_unused_lifetimes warning
mcheshkov Dec 13, 2024
1d5825a
refactor(cubesql): Fix filter_map_bool_then warning
mcheshkov Dec 13, 2024
bb74a21
refactor(cubesql): Fix filter_map_identity warning
mcheshkov Dec 13, 2024
7fa2e1b
refactor(cubesql): Simplify CloseCursor::All handling
mcheshkov Dec 13, 2024
de1302b
refactor(cubesql): Fix for_kv_map warning
mcheshkov Dec 13, 2024
e552ab7
refactor(cubesql): Fix get_first warning
mcheshkov Dec 13, 2024
be475f5
refactor(cubesql): Fix identity_op warning
mcheshkov Dec 13, 2024
6d10dc8
refactor(cubesql): Enable manual_filter warning
mcheshkov Dec 13, 2024
377243c
refactor(cubesql): Fix manual_is_ascii_check warning
mcheshkov Dec 13, 2024
bf2e946
refactor(cubesql): Fix manual_map warning
mcheshkov Dec 13, 2024
05363de
refactor(cubesql): Fix manual_strip warning
mcheshkov Dec 13, 2024
674dab6
refactor(cubesql): Fix to_string_in_format_args warning
mcheshkov Dec 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions rust/cubesql/cubesql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,40 +90,22 @@ harness = false
# Feel free to remove any rule from here and fix all warnings with it
# Or to write a comment why rule should stay disabled
[lints.clippy]
assign_op_pattern = "allow"
bool_assert_comparison = "allow"
bool_comparison = "allow"
borrowed_box = "allow"
cast_abs_to_unsigned = "allow"
clone_on_copy = "allow"
cmp_owned = "allow"
collapsible_if = "allow"
collapsible_match = "allow"
collapsible_else_if = "allow"
comparison_chain = "allow"
derive_ord_xor_partial_ord = "allow"
expect_fun_call = "allow"
explicit_auto_deref = "allow"
extra_unused_lifetimes = "allow"
field_reassign_with_default = "allow"
filter_map_bool_then = "allow"
filter_map_identity = "allow"
for_kv_map = "allow"
get_first = "allow"
identity_op = "allow"
if_same_then_else = "allow"
into_iter_on_ref = "allow"
iter_cloned_collect = "allow"
iter_next_slice = "allow"
len_without_is_empty = "allow"
len_zero = "allow"
let_and_return = "allow"
manual_filter = "allow"
manual_flatten = "allow"
manual_is_ascii_check = "allow"
manual_map = "allow"
manual_range_contains = "allow"
manual_strip = "allow"
map_clone = "allow"
map_flatten = "allow"
map_identity = "allow"
Expand Down Expand Up @@ -152,11 +134,9 @@ redundant_closure = "allow"
redundant_field_names = "allow"
redundant_pattern = "allow"
redundant_pattern_matching = "allow"
redundant_slicing = "allow"
result_large_err = "allow"
single_match = "allow"
should_implement_trait = "allow"
to_string_in_format_args = "allow"
to_string_trait_impl = "allow"
too_many_arguments = "allow"
type_complexity = "allow"
Expand Down
8 changes: 4 additions & 4 deletions rust/cubesql/cubesql/e2e/tests/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl PostgresIntegrationTestSuite {
services.wait_processing_loops().await.unwrap();
});

sleep(Duration::from_millis(1 * 1000)).await;
sleep(Duration::from_secs(1)).await;

let client = PostgresIntegrationTestSuite::create_client(
format!("host=127.0.0.1 port={} user=test password=test", port)
Expand Down Expand Up @@ -142,15 +142,15 @@ impl PostgresIntegrationTestSuite {
column.type_().oid(),
PgType::get_by_tid(
PgTypeId::from_oid(column.type_().oid())
.expect(&format!("Unknown oid {}", column.type_().oid()))
.unwrap_or_else(|| panic!("Unknown oid {}", column.type_().oid()))
)
.typname,
));
}

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

let columns = rows.get(0).unwrap().columns();
let columns = rows.first().unwrap().columns();
assert_eq!(
columns
.into_iter()
Expand Down
6 changes: 1 addition & 5 deletions rust/cubesql/cubesql/src/compile/engine/df/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -751,11 +751,7 @@ impl CubeScanOneShotStream {
}

fn poll_next(&mut self) -> Option<ArrowResult<RecordBatch>> {
if let Some(batch) = self.data.take() {
Some(Ok(batch))
} else {
None
}
self.data.take().map(Ok)
}
}

Expand Down
26 changes: 10 additions & 16 deletions rust/cubesql/cubesql/src/compile/engine/udf/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1418,7 +1418,7 @@
}
debug_assert!(0 <= month);
year += month / 12;
month = month % 12;
month %= 12;

match change_ym(t, year, 1 + month as u32) {
Some(t) => return Ok(t),
Expand All @@ -1442,13 +1442,13 @@
let result = if month > 0 && is_add || month < 0 && !is_add {
t.checked_add_months(Months::new(month as u32))
} else {
t.checked_sub_months(Months::new(month.abs() as u32))
t.checked_sub_months(Months::new(month.unsigned_abs()))
};

let result = if day > 0 && is_add || day < 0 && !is_add {
result.and_then(|t| t.checked_add_days(Days::new(day as u64)))
} else {
result.and_then(|t| t.checked_sub_days(Days::new(day.abs() as u64)))
result.and_then(|t| t.checked_sub_days(Days::new(day.unsigned_abs() as u64)))
};

let result = result.and_then(|t| {
Expand All @@ -1472,7 +1472,7 @@
let result = if days > 0 && is_add || days < 0 && !is_add {
t.checked_add_days(Days::new(days as u64))
} else {
t.checked_sub_days(Days::new(days.abs() as u64))
t.checked_sub_days(Days::new(days.unsigned_abs() as u64))
};

let result = result.and_then(|t| {
Expand Down Expand Up @@ -1501,9 +1501,9 @@
return 31;
}
NaiveDate::from_ymd_opt(y, m + 1, 1)
.expect(&format!("Invalid year month: {}-{}", y, m))
.unwrap_or_else(|| panic!("Invalid year month: {}-{}", y, m))
.pred_opt()
.expect(&format!("Invalid year month: {}-{}", y, m))
.unwrap_or_else(|| panic!("Invalid year month: {}-{}", y, m))
.day()
}

Expand Down Expand Up @@ -1564,10 +1564,7 @@

let res = NaiveDateTime::parse_from_str(timestamp, &format).map_err(|e| {
DataFusionError::Execution(format!(
"Error evaluating str_to_date('{}', '{}'): {}",
timestamp,
format,
e.to_string()
"Error evaluating str_to_date('{timestamp}', '{format}'): {e}"

Check warning on line 1567 in rust/cubesql/cubesql/src/compile/engine/udf/common.rs

View check run for this annotation

Codecov / codecov/patch

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

Added line #L1567 was not covered by tests
))
})?;

Expand Down Expand Up @@ -1671,7 +1668,7 @@
let secs = duration.num_seconds();
let nanosecs = duration.num_nanoseconds().unwrap_or(0) - secs * 1_000_000_000;
let timestamp = NaiveDateTime::from_timestamp_opt(secs, nanosecs as u32)
.expect(format!("Invalid secs {} nanosecs {}", secs, nanosecs).as_str());
.unwrap_or_else(|| panic!("Invalid secs {} nanosecs {}", secs, nanosecs));

// chrono's strftime is missing quarter format, as such a workaround is required
let quarter = &format!("{}", timestamp.date().month0() / 3 + 1);
Expand Down Expand Up @@ -2237,10 +2234,7 @@
let oids_arr = downcast_primitive_arg!(args[0], "oid", OidType);
let result = oids_arr
.iter()
.map(|oid| match oid {
Some(_oid) => Some("PRIMARY KEY (oid)".to_string()),
_ => None,
})
.map(|oid| oid.map(|_oid| "PRIMARY KEY (oid)".to_string()))
.collect::<StringArray>();

Ok(Arc::new(result))
Expand Down Expand Up @@ -3583,7 +3577,7 @@
let join_str = join_strs.value(i);
let strings = downcast_string_arg!(array, "str", i32);
let joined_string =
itertools::Itertools::intersperse(strings.iter().filter_map(|s| s), join_str)
itertools::Itertools::intersperse(strings.iter().flatten(), join_str)

Check warning on line 3580 in rust/cubesql/cubesql/src/compile/engine/udf/common.rs

View check run for this annotation

Codecov / codecov/patch

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

Added line #L3580 was not covered by tests
.collect::<String>();
builder.append_value(joined_string)?;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl VariablesProvider {

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

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

if ignore_first {
identifier[1..].concat()
Expand Down Expand Up @@ -85,9 +85,7 @@ impl VarProvider for VariablesProvider {

match (&first_word_vec[0], &first_word_vec[1]) {
('@', '@') => {
if identifier.len() > 1
&& identifier[0].to_ascii_lowercase() == "@@session".to_owned()
{
if identifier.len() > 1 && identifier[0].to_ascii_lowercase() == "@@session" {
return self.get_session_value(identifier, VarType::System);
}

Expand Down
38 changes: 15 additions & 23 deletions rust/cubesql/cubesql/src/compile/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ impl Dialect for MySqlDialectWithBackTicks {
// See https://dev.mysql.com/doc/refman/8.0/en/identifiers.html.
// We don't yet support identifiers beginning with numbers, as that
// makes it hard to distinguish numeric literals.
('a'..='z').contains(&ch)
|| ('A'..='Z').contains(&ch)
ch.is_ascii_lowercase()
|| ch.is_ascii_uppercase()
|| ch == '_'
|| ch == '$'
|| ch == '@'
|| ('\u{0080}'..='\u{ffff}').contains(&ch)
}

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

Expand Down Expand Up @@ -293,11 +293,9 @@ mod tests {
);
match result {
Ok(_) => panic!("This test should throw an error"),
Err(err) => assert_eq!(
true,
err.to_string()
.contains("Invalid query, no statements was specified")
),
Err(err) => assert!(err
.to_string()
.contains("Invalid query, no statements was specified")),
}
}

Expand All @@ -310,11 +308,9 @@ mod tests {
);
match result {
Ok(_) => panic!("This test should throw an error"),
Err(err) => assert_eq!(
true,
err.to_string()
.contains("Multiple statements was specified in one query")
),
Err(err) => assert!(err
.to_string()
.contains("Multiple statements was specified in one query")),
}
}

Expand Down Expand Up @@ -349,11 +345,9 @@ mod tests {
);
match result {
Ok(_) => panic!("This test should throw an error"),
Err(err) => assert_eq!(
true,
err.to_string()
.contains("Invalid query, no statements was specified")
),
Err(err) => assert!(err
.to_string()
.contains("Invalid query, no statements was specified")),
}
}

Expand All @@ -366,11 +360,9 @@ mod tests {
);
match result {
Ok(_) => panic!("This test should throw an error"),
Err(err) => assert_eq!(
true,
err.to_string()
.contains("Multiple statements was specified in one query")
),
Err(err) => assert!(err
.to_string()
.contains("Multiple statements was specified in one query")),
}
}

Expand Down
2 changes: 1 addition & 1 deletion rust/cubesql/cubesql/src/compile/rewrite/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ impl LogicalPlanAnalysis {
.unwrap();
let expr = original_expr(params[2])?;
map.push((
Some(format!("{}.{}", cube, field_name.to_string())),
Some(format!("{cube}.{field_name}")),
Member::VirtualField {
name: field_name.to_string(),
cube: cube.to_string(),
Expand Down
10 changes: 6 additions & 4 deletions rust/cubesql/cubesql/src/compile/rewrite/rewriter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,10 +550,12 @@ impl egg::RewriteScheduler<LogicalPlanLanguage, LogicalPlanAnalysis> for Increme
if iteration != self.current_iter {
self.current_iter = iteration;
self.current_eclasses.clear();
self.current_eclasses
.extend(egraph.classes().filter_map(|class| {
(class.data.iteration_timestamp >= iteration).then(|| class.id)
}));
self.current_eclasses.extend(
egraph
.classes()
.filter(|class| (class.data.iteration_timestamp >= iteration))
.map(|class| class.id),
);
};
assert_eq!(iteration, self.current_iter);
rewrite.searcher.search_eclasses_with_limit(
Expand Down
7 changes: 4 additions & 3 deletions rust/cubesql/cubesql/src/compile/rewrite/rules/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2780,12 +2780,13 @@ impl FilterRules {
value.to_string()
}
} else if op == "endsWith" || op == "notEndsWith" {
if value.starts_with("%") {
let without_wildcard = value[1..].to_string();
if let Some(without_wildcard) =
value.strip_prefix("%")
{
if without_wildcard.contains("%") {
continue;
}
without_wildcard
without_wildcard.to_string()
} else {
value.to_string()
}
Expand Down
9 changes: 4 additions & 5 deletions rust/cubesql/cubesql/src/compile/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@
DatabaseProtocol::PostgreSQL,
) if object_type == &ast::ObjectType::Table => self.drop_table_to_plan(names).await,
_ => Err(CompilationError::unsupported(format!(
"Unsupported query type: {}",
stmt.to_string()
"Unsupported query type: {stmt}"
))),
};

Expand Down Expand Up @@ -348,7 +347,7 @@
}
DatabaseProtocol::MySQL => {
for key_value in key_values.iter() {
if key_value.key.value.to_lowercase() == "autocommit".to_string() {
if key_value.key.value.to_lowercase() == "autocommit" {

Check warning on line 350 in rust/cubesql/cubesql/src/compile/router.rs

View check run for this annotation

Codecov / codecov/patch

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

Added line #L350 was not covered by tests
flags |= StatusFlags::AUTOCOMMIT;

break;
Expand Down Expand Up @@ -513,7 +512,7 @@
async fn select_into_to_plan(
&self,
into: &ast::SelectInto,
query: &Box<ast::Query>,
query: &ast::Query,
qtrace: &mut Option<Qtrace>,
span_id: Option<Arc<SpanId>>,
) -> Result<QueryPlan, CompilationError> {
Expand All @@ -531,7 +530,7 @@
"query is unexpectedly not SELECT".to_string(),
));
}
let new_stmt = ast::Statement::Query(new_query);
let new_stmt = ast::Statement::Query(Box::new(new_query));
self.create_table_to_plan(&into.name, &new_stmt, qtrace, span_id)
.await
}
Expand Down
2 changes: 1 addition & 1 deletion rust/cubesql/cubesql/src/sql/postgres/extended.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ impl Portal {

batch
} else {
*left = *left - batch.num_rows();
*left -= batch.num_rows();
batch
}
};
Expand Down
Loading
Loading