From 162dbfe5ad1b6815691b33fc9cc096e37773d767 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Sat, 28 Jun 2025 08:39:02 -0700 Subject: [PATCH] fix clippy errors --- columnq-cli/src/main.rs | 2 +- columnq/src/columnq.rs | 3 +-- columnq/src/io/fs.rs | 4 ++-- columnq/src/io/http.rs | 2 +- columnq/src/io/mod.rs | 2 +- columnq/src/table/database.rs | 2 +- columnq/src/table/excel.rs | 8 ++++---- columnq/src/table/json.rs | 2 +- columnq/src/table/mod.rs | 7 +++---- roapi-ui/src/app.rs | 6 +++--- roapi/src/config.rs | 10 +++++----- roapi/src/main.rs | 3 +-- roapi/src/server/flight_sql.rs | 5 ++--- roapi/src/server/postgres.rs | 4 ++-- roapi/src/startup.rs | 2 +- roapi/tests/api_test.rs | 2 +- roapi/tests/config_test.rs | 2 +- roapi/tests/partitioned_table_test.rs | 6 ++---- 18 files changed, 33 insertions(+), 39 deletions(-) diff --git a/columnq-cli/src/main.rs b/columnq-cli/src/main.rs index 42f17f1..34d587f 100644 --- a/columnq-cli/src/main.rs +++ b/columnq-cli/src/main.rs @@ -48,7 +48,7 @@ async fn console_loop(cq: &ColumnQ) -> anyhow::Result<()> { let mut readline = Editor::<()>::new(); if let Err(e) = readline.load_history(&rl_history) { - debug!("no query history loaded: {:?}", e); + debug!("no query history loaded: {e:?}"); } loop { diff --git a/columnq/src/columnq.rs b/columnq/src/columnq.rs index 555542c..76d877a 100644 --- a/columnq/src/columnq.rs +++ b/columnq/src/columnq.rs @@ -215,8 +215,7 @@ impl ColumnQ { let object_store: DatafusionResult> = match url.host() { None => Err(DataFusionError::Execution(format!( - "Missing bucket name: {}", - url + "Missing bucket name: {url}" ))), Some(host) => { match blob_type { diff --git a/columnq/src/io/fs.rs b/columnq/src/io/fs.rs index 2a186d8..cd6c542 100644 --- a/columnq/src/io/fs.rs +++ b/columnq/src/io/fs.rs @@ -52,7 +52,7 @@ where // TODO: load partitions in parallel let partitions = path_iter .map(|fpath| { - debug!("loading file from path: {}", fpath); + debug!("loading file from path: {fpath}"); let reader = fs::File::open(fpath).context(FileOpenSnafu { fpath })?; partition_reader(reader).context(TableSnafu) @@ -83,6 +83,6 @@ where let files = build_file_list(&fs_path, &file_ext).context(FileListSnafu { fs_path, file_ext })?; - debug!("loading file partitions: {:?}", files); + debug!("loading file partitions: {files:?}"); partitions_from_iterator(files.iter().map(|s| s.as_str()), partition_reader) } diff --git a/columnq/src/io/http.rs b/columnq/src/io/http.rs index 37cebe7..02e997d 100644 --- a/columnq/src/io/http.rs +++ b/columnq/src/io/http.rs @@ -74,7 +74,7 @@ where Err(Error::Status { status: resp.status(), uri: uri.to_string(), - resp: format!("{:?}", resp), + resp: format!("{resp:?}"), })?; } let reader = std::io::Cursor::new(resp.bytes().await.context(ReadBytesSnafu { uri })?); diff --git a/columnq/src/io/mod.rs b/columnq/src/io/mod.rs index c481293..11bcd1a 100644 --- a/columnq/src/io/mod.rs +++ b/columnq/src/io/mod.rs @@ -51,7 +51,7 @@ impl TryFrom>> for BlobStoreType { Some(uriparse::Scheme::HTTP) | Some(uriparse::Scheme::HTTPS) => Ok(BlobStoreType::Http), Some(uriparse::Scheme::Unregistered(s)) => BlobStoreType::try_from(s.as_str()), _ => Err(Error::InvalidUriScheme { - scheme: format!("{:?}", scheme), + scheme: format!("{scheme:?}"), }), } } diff --git a/columnq/src/table/database.rs b/columnq/src/table/database.rs index ea36f1a..68ee45a 100644 --- a/columnq/src/table/database.rs +++ b/columnq/src/table/database.rs @@ -49,7 +49,7 @@ mod imp { } .unwrap_or(t.name.clone()); - let queries = CXQuery::naked(format!("SELECT * FROM {}", table_name)); + let queries = CXQuery::naked(format!("SELECT * FROM {table_name}")); let source = SourceConn::try_from(t.get_uri_str()) .context(SourceSnafu) .map_err(Box::new) diff --git a/columnq/src/table/excel.rs b/columnq/src/table/excel.rs index 31a8d88..5b1719d 100644 --- a/columnq/src/table/excel.rs +++ b/columnq/src/table/excel.rs @@ -184,8 +184,8 @@ fn infer_schema_from_config(table_schema: &TableSchema) -> Result if unsupported_data_types.is_empty() { Ok(table_schema.into()) } else { - Err(Error::IncorrectSchema{msg: format!("Configured schema for excel file contains unsupported data types in columns {}. Supported datatype: \ - Boolean, Int64, Float64, Date32, Date64, !Timestamp [Second, null], !Duration [Second], Null, Utf8", unsupported_data_types)}) + Err(Error::IncorrectSchema{msg: format!("Configured schema for excel file contains unsupported data types in columns {unsupported_data_types}. Supported datatype: \ + Boolean, Int64, Float64, Date32, Date64, !Timestamp [Second, null], !Duration [Second], Null, Utf8")}) } } @@ -193,7 +193,7 @@ fn empty_or_panic(v: &ExcelDataType, field_name: &String) -> Option { if v.is_empty() { None } else { - panic!("Incorrect value {:?} in column {}", v, field_name) + panic!("Incorrect value {v:?} in column {field_name}") } } @@ -338,7 +338,7 @@ fn excel_range_to_record_batch( }) .collect::>(), ) as ArrayRef, - unsupported => panic!("Unsupported data type for excel table {:?}", unsupported), + unsupported => panic!("Unsupported data type for excel table {unsupported:?}"), } }) .collect::>(); diff --git a/columnq/src/table/json.rs b/columnq/src/table/json.rs index cefd6d4..57b059a 100644 --- a/columnq/src/table/json.rs +++ b/columnq/src/table/json.rs @@ -259,7 +259,7 @@ mod tests { let tmp_dir = tempfile::TempDir::new().unwrap(); let tmp_file_path = tmp_dir.path().join("nested.json"); let mut f = std::fs::File::create(tmp_file_path.clone()).unwrap(); - writeln!(f, "{}", json_content).unwrap(); + writeln!(f, "{json_content}").unwrap(); let ctx = SessionContext::new(); let t = to_mem_table( diff --git a/columnq/src/table/mod.rs b/columnq/src/table/mod.rs index 38dab27..92e3a44 100644 --- a/columnq/src/table/mod.rs +++ b/columnq/src/table/mod.rs @@ -643,7 +643,7 @@ impl TableSource { } } - pub fn parsed_uri(&self) -> Result { + pub fn parsed_uri(&self) -> Result, Error> { match &self.io_source { TableIoSource::Uri(uri) => { URIReference::try_from(uri.as_str()).map_err(|_| Error::InvalidUri { @@ -1096,9 +1096,8 @@ schema: let t: TableSource = serde_yaml::from_str(&format!( r#" name: "uk_cities" -uri: "sqlite://../test_data/sqlite/sample.{}" -"#, - ext +uri: "sqlite://../test_data/sqlite/sample.{ext}" +"# )) .unwrap(); let ctx = datafusion::prelude::SessionContext::new(); diff --git a/roapi-ui/src/app.rs b/roapi-ui/src/app.rs index ad10e38..a3c7586 100644 --- a/roapi-ui/src/app.rs +++ b/roapi-ui/src/app.rs @@ -140,7 +140,7 @@ impl ROAPIUI { } Err(e) => { self.show_error = true; - self.error = Some(format!("Failed to parse query result: {}", e)); + self.error = Some(format!("Failed to parse query result: {e}")); } }, _ => { @@ -161,7 +161,7 @@ impl ROAPIUI { }, Err(e) => { self.show_error = true; - self.error = Some(format!("Failed to send request: {}", e)); + self.error = Some(format!("Failed to send request: {e}")); } } } @@ -183,7 +183,7 @@ impl ROAPIUI { } }, Err(e) => { - self.schema_fetching_message = Some(format!("Failed to fetch schema: {}", e)); + self.schema_fetching_message = Some(format!("Failed to fetch schema: {e}")); } } } diff --git a/roapi/src/config.rs b/roapi/src/config.rs index a863876..62b2498 100644 --- a/roapi/src/config.rs +++ b/roapi/src/config.rs @@ -210,15 +210,15 @@ pub fn get_configuration(cmd: clap::Command) -> Result { } if let Some(addr) = matches.get_one::("addr-http") { - config.addr.http = Some(addr.to_owned()); + config.addr.http = Some(addr.clone()); } if let Some(addr) = matches.get_one::("addr-postgres") { - config.addr.postgres = Some(addr.to_owned()); + config.addr.postgres = Some(addr.clone()); } if let Some(addr) = matches.get_one::("addr-flight-sql") { - config.addr.flight_sql = Some(addr.to_owned()); + config.addr.flight_sql = Some(addr.clone()); } if matches.get_one::("disable-read-only") == Some(&true) { @@ -229,7 +229,7 @@ pub fn get_configuration(cmd: clap::Command) -> Result { if !config.disable_read_only { whatever!("Table reload not supported in read-only mode. Try specify the --disable-read-only option."); } - config.reload_interval = Some(Duration::from_secs(reload_interval.to_owned())); + config.reload_interval = Some(Duration::from_secs(*reload_interval)); } if let Some(response_format) = matches.get_one::("response-format") { @@ -249,7 +249,7 @@ impl Config { let mut opt = ConfigOptions::default(); for (k, v) in df_cfg { whatever!( - opt.set(format!("datafusion.{}", k).as_str(), v), + opt.set(format!("datafusion.{k}").as_str(), v), "failed to set datafusion config: {k}={v}" ); } diff --git a/roapi/src/main.rs b/roapi/src/main.rs index a41e7fd..2cb0725 100644 --- a/roapi/src/main.rs +++ b/roapi/src/main.rs @@ -22,7 +22,6 @@ async fn main() { } .await; if let Err(e) = re { - cmd.error(clap::error::ErrorKind::Io, format!("{}", e)) - .exit(); + cmd.error(clap::error::ErrorKind::Io, format!("{e}")).exit(); } } diff --git a/roapi/src/server/flight_sql.rs b/roapi/src/server/flight_sql.rs index 702a20a..78e1c7a 100644 --- a/roapi/src/server/flight_sql.rs +++ b/roapi/src/server/flight_sql.rs @@ -285,8 +285,7 @@ impl FlightSqlService for RoapiFlightSqlService { if !message.is::() { Err(Status::unimplemented(format!( - "do_get_fallback: The defined request is invalid: {:?}", - message + "do_get_fallback: The defined request is invalid: {message:?}" )))? } @@ -984,7 +983,7 @@ impl RoapiFlightSqlServer { // when only basic auth is specified, handshake will return encoded basic auth // value as token to keep it constant (None, Some(BasicAuth { username, password })) => { - let token = BASE64_STANDARD_NO_PAD.encode(format!("{}:{}", username, password)); + let token = BASE64_STANDARD_NO_PAD.encode(format!("{username}:{password}")); Some(token) } (None, None) => None, diff --git a/roapi/src/server/postgres.rs b/roapi/src/server/postgres.rs index 4c915a1..28e42b6 100644 --- a/roapi/src/server/postgres.rs +++ b/roapi/src/server/postgres.rs @@ -113,7 +113,7 @@ impl RoapiQueryHandler { } async fn execute_query(&self, query: &str) -> PgWireResult> { - info!("executing query: {}", query); + info!("executing query: {query}"); // Handle some special PostgreSQL queries if query.trim().to_lowercase().starts_with("show") { @@ -549,7 +549,7 @@ impl RunnableServer for PostgresServer { let factory = Arc::new(RoapiHandlerFactory { handler }); if let Err(e) = process_socket(socket, None, factory).await { - log::error!("Error processing postgres connection: {}", e); + log::error!("Error processing postgres connection: {e}"); } }); } diff --git a/roapi/src/startup.rs b/roapi/src/startup.rs index 00ec21c..92dbfd8 100644 --- a/roapi/src/startup.rs +++ b/roapi/src/startup.rs @@ -75,7 +75,7 @@ impl Application { let _handle = tokio::task::spawn(async move { loop { if let Err(e) = ctx_ext.refresh_tables().await { - error!("Failed to refresh table: {:?}", e); + error!("Failed to refresh table: {e:?}"); } time::sleep(Duration::from_millis(1000)).await; } diff --git a/roapi/tests/api_test.rs b/roapi/tests/api_test.rs index 091a5dc..4fbabdc 100644 --- a/roapi/tests/api_test.rs +++ b/roapi/tests/api_test.rs @@ -267,7 +267,7 @@ async fn test_http2() { .unwrap() .stdout; - let two = vec!['\'', '2', '\n', '\''] + let two = ['\'', '2', '\n', '\''] .iter() .map(|c| *c as u8) .collect::>(); diff --git a/roapi/tests/config_test.rs b/roapi/tests/config_test.rs index ae18fac..f15ad91 100644 --- a/roapi/tests/config_test.rs +++ b/roapi/tests/config_test.rs @@ -12,7 +12,7 @@ fn test_load_yaml_datafusion_config() { let df_cfg = cfg.get_datafusion_config().unwrap(); assert_eq!(df_cfg.options().sql_parser.dialect, "Hive"); - assert_eq!(df_cfg.options().explain.physical_plan_only, true); + assert!(df_cfg.options().explain.physical_plan_only); assert_eq!(df_cfg.options().optimizer.max_passes, 10); assert_eq!(df_cfg.options().execution.batch_size, 100); assert_eq!(df_cfg.options().catalog.format, Some("parquet".to_string())); diff --git a/roapi/tests/partitioned_table_test.rs b/roapi/tests/partitioned_table_test.rs index 728f02f..2ccda79 100644 --- a/roapi/tests/partitioned_table_test.rs +++ b/roapi/tests/partitioned_table_test.rs @@ -5,7 +5,7 @@ use columnq::table::{TableColumn, TableLoadOption, TableOptionCsv, TableSource}; fn partitioned_csv_table() -> TableSource { let table_path = helpers::test_data_path("partitioned_csv"); - let table = TableSource::new("partitioned_csv".to_string(), table_path) + TableSource::new("partitioned_csv".to_string(), table_path) .with_option(TableLoadOption::csv( TableOptionCsv::default().with_use_memory_table(false), )) @@ -20,9 +20,7 @@ fn partitioned_csv_table() -> TableSource { data_type: DataType::UInt16, nullable: false, }, - ]); - - table + ]) } #[tokio::test]