Skip to content

Apache DataFusion SQL Query Engine

style: simplify some strings for readability (#15999)

Hamir Mahalc74faee425ff
diff --git a/datafusion-cli/src/catalog.rs b/datafusion-cli/src/catalog.rs
index ceb72dbc54..3298b7deae 100644
--- a/datafusion-cli/src/catalog.rs
+++ b/datafusion-cli/src/catalog.rs
@@ -337,8 +337,7 @@ mod tests {
#[cfg(not(target_os = "windows"))]
#[test]
fn test_substitute_tilde() {
- use std::env;
- use std::path::MAIN_SEPARATOR;
+ use std::{env, path::PathBuf};
let original_home = home_dir();
let test_home_path = if cfg!(windows) {
"C:\\Users\\user"
@@ -350,17 +349,16 @@ mod tests {
test_home_path,
);
let input = "~/Code/datafusion/benchmarks/data/tpch_sf1/part/part-0.parquet";
- let expected = format!(
- "{}{}Code{}datafusion{}benchmarks{}data{}tpch_sf1{}part{}part-0.parquet",
- test_home_path,
- MAIN_SEPARATOR,
- MAIN_SEPARATOR,
- MAIN_SEPARATOR,
- MAIN_SEPARATOR,
- MAIN_SEPARATOR,
- MAIN_SEPARATOR,
- MAIN_SEPARATOR
- );
+ let expected = PathBuf::from(test_home_path)
+ .join("Code")
+ .join("datafusion")
+ .join("benchmarks")
+ .join("data")
+ .join("tpch_sf1")
+ .join("part")
+ .join("part-0.parquet")
+ .to_string_lossy()
+ .to_string();
let actual = substitute_tilde(input.to_string());
assert_eq!(actual, expected);
match original_home {
diff --git a/datafusion-cli/src/command.rs b/datafusion-cli/src/command.rs
index bc2bb0ee02..77bc8d3d20 100644
--- a/datafusion-cli/src/command.rs
+++ b/datafusion-cli/src/command.rs
@@ -78,15 +78,14 @@ impl Command {
exec_and_print(ctx, print_options, "SHOW TABLES".into()).await
}
Self::DescribeTableStmt(name) => {
- exec_and_print(ctx, print_options, format!("SHOW COLUMNS FROM {}", name))
+ exec_and_print(ctx, print_options, format!("SHOW COLUMNS FROM {name}"))
.await
}
Self::Include(filename) => {
if let Some(filename) = filename {
let file = File::open(filename).map_err(|e| {
DataFusionError::Execution(format!(
- "Error opening {:?} {}",
- filename, e
+ "Error opening {filename:?} {e}"
))
})?;
exec_from_lines(ctx, &mut BufReader::new(file), print_options)
@@ -116,7 +115,7 @@ impl Command {
Self::SearchFunctions(function) => {
if let Ok(func) = function.parse::<Function>() {
let details = func.function_details()?;
- println!("{}", details);
+ println!("{details}");
Ok(())
} else {
exec_err!("{function} is not a supported function")
diff --git a/datafusion-cli/src/exec.rs b/datafusion-cli/src/exec.rs
index fa4cd9c5fd..3c2a6e68bb 100644
--- a/datafusion-cli/src/exec.rs
+++ b/datafusion-cli/src/exec.rs
@@ -200,7 +200,7 @@ pub async fn exec_from_repl(
break;
}
Err(err) => {
- eprintln!("Unknown error happened {:?}", err);
+ eprintln!("Unknown error happened {err:?}");
break;
}
}
@@ -530,7 +530,7 @@ mod tests {
)
})?;
for location in locations {
- let sql = format!("copy (values (1,2)) to '{}' STORED AS PARQUET;", location);
+ let sql = format!("copy (values (1,2)) to '{location}' STORED AS PARQUET;");
let statements = DFParser::parse_sql_with_dialect(&sql, dialect.as_ref())?;
for statement in statements {
//Should not fail
diff --git a/datafusion-cli/src/functions.rs b/datafusion-cli/src/functions.rs
index 13d2d5fd35..911bbf34b0 100644
--- a/datafusion-cli/src/functions.rs
+++ b/datafusion-cli/src/functions.rs
@@ -205,7 +205,7 @@ pub fn display_all_functions() -> Result<()> {
let array = StringArray::from(
ALL_FUNCTIONS
.iter()
- .map(|f| format!("{}", f))
+ .map(|f| format!("{f}"))
.collect::<Vec<String>>(),
);
let schema = Schema::new(vec![Field::new("Function", DataType::Utf8, false)]);
diff --git a/datafusion-cli/src/main.rs b/datafusion-cli/src/main.rs
index 2971a6191b..16ddf2a6a5 100644
--- a/datafusion-cli/src/main.rs
+++ b/datafusion-cli/src/main.rs
@@ -154,7 +154,7 @@ async fn main_inner() -> Result<()> {
let args = Args::parse();
if !args.quiet {
- println!("DataFusion CLI v{}", DATAFUSION_CLI_VERSION);
+ println!("DataFusion CLI v{DATAFUSION_CLI_VERSION}");
}
if let Some(ref path) = args.data_path {
@@ -280,7 +280,7 @@ fn parse_valid_file(dir: &str) -> Result<String, String> {
if Path::new(dir).is_file() {
Ok(dir.to_string())
} else {
- Err(format!("Invalid file '{}'", dir))
+ Err(format!("Invalid file '{dir}'"))
}
}
@@ -288,14 +288,14 @@ fn parse_valid_data_dir(dir: &str) -> Result<String, String> {
if Path::new(dir).is_dir() {
Ok(dir.to_string())
} else {
- Err(format!("Invalid data directory '{}'", dir))
+ Err(format!("Invalid data directory '{dir}'"))
}
}
fn parse_batch_size(size: &str) -> Result<usize, String> {
match size.parse::<usize>() {
Ok(size) if size > 0 => Ok(size),
- _ => Err(format!("Invalid batch size '{}'", size)),
+ _ => Err(format!("Invalid batch size '{size}'")),
}
}
@@ -352,20 +352,20 @@ fn parse_size_string(size: &str, label: &str) -> Result<usize, String> {
let num_str = caps.get(1).unwrap().as_str();
let num = num_str
.parse::<usize>()
- .map_err(|_| format!("Invalid numeric value in {} '{}'", label, size))?;
+ .map_err(|_| format!("Invalid numeric value in {label} '{size}'"))?;
let suffix = caps.get(2).map(|m| m.as_str()).unwrap_or("b");
let unit = BYTE_SUFFIXES
.get(suffix)
- .ok_or_else(|| format!("Invalid {} '{}'", label, size))?;
+ .ok_or_else(|| format!("Invalid {label} '{size}'"))?;
let total_bytes = usize::try_from(unit.multiplier())
.ok()
.and_then(|multiplier| num.checked_mul(multiplier))
- .ok_or_else(|| format!("{} '{}' is too large", label, size))?;
+ .ok_or_else(|| format!("{label} '{size}' is too large"))?;
Ok(total_bytes)
} else {
- Err(format!("Invalid {} '{}'", label, size))
+ Err(format!("Invalid {label} '{size}'"))
}
}
diff --git a/datafusion-cli/src/pool_type.rs b/datafusion-cli/src/pool_type.rs
index 269790b61f..a2164cc3c7 100644
--- a/datafusion-cli/src/pool_type.rs
+++ b/datafusion-cli/src/pool_type.rs
@@ -33,7 +33,7 @@ impl FromStr for PoolType {
match s {
"Greedy" | "greedy" => Ok(PoolType::Greedy),
"Fair" | "fair" => Ok(PoolType::Fair),
- _ => Err(format!("Invalid memory pool type '{}'", s)),
+ _ => Err(format!("Invalid memory pool type '{s}'")),
}
}
}
diff --git a/datafusion-cli/src/print_format.rs b/datafusion-cli/src/print_format.rs
index 1d4889c4ba..1d6a8396ae 100644
--- a/datafusion-cli/src/print_format.rs
+++ b/datafusion-cli/src/print_format.rs
@@ -137,16 +137,16 @@ fn format_batches_with_maxrows<W: std::io::Write>(
let formatted =
pretty_format_batches_with_options(&filtered_batches, &options)?;
if over_limit {
- let mut formatted_str = format!("{}", formatted);
+ let mut formatted_str = format!("{formatted}");
formatted_str = keep_only_maxrows(&formatted_str, maxrows);
- writeln!(writer, "{}", formatted_str)?;
+ writeln!(writer, "{formatted_str}")?;
} else {
- writeln!(writer, "{}", formatted)?;
+ writeln!(writer, "{formatted}")?;
}
}
MaxRows::Unlimited => {
let formatted = pretty_format_batches_with_options(batches, &options)?;
- writeln!(writer, "{}", formatted)?;
+ writeln!(writer, "{formatted}")?;
}
}
@@ -206,7 +206,7 @@ impl PrintFormat {
let empty_batch = RecordBatch::new_empty(schema);
let formatted =
pretty_format_batches_with_options(&[empty_batch], &format_options)?;
- writeln!(writer, "{}", formatted)?;
+ writeln!(writer, "{formatted}")?;
}
_ => {}
}
diff --git a/datafusion-cli/src/print_options.rs b/datafusion-cli/src/print_options.rs
index 6ca75bd226..56d787b0fe 100644
--- a/datafusion-cli/src/print_options.rs
+++ b/datafusion-cli/src/print_options.rs
@@ -52,7 +52,7 @@ impl FromStr for MaxRows {
} else {
match maxrows.parse::<usize>() {
Ok(nrows) => Ok(Self::Limited(nrows)),
- _ => Err(format!("Invalid maxrows {}. Valid inputs are natural numbers or \'none\', \'inf\', or \'infinite\' for no limit.", maxrows)),
+ _ => Err(format!("Invalid maxrows {maxrows}. Valid inputs are natural numbers or \'none\', \'inf\', or \'infinite\' for no limit.")),
}
}
}
diff --git a/datafusion-cli/tests/cli_integration.rs b/datafusion-cli/tests/cli_integration.rs
index 69344f4e5e..bdab38026f 100644
--- a/datafusion-cli/tests/cli_integration.rs
+++ b/datafusion-cli/tests/cli_integration.rs
@@ -161,15 +161,14 @@ async fn test_aws_options() {
STORED AS CSV
LOCATION 's3://data/cars.csv'
OPTIONS(
- 'aws.access_key_id' '{}',
- 'aws.secret_access_key' '{}',
- 'aws.endpoint' '{}',
+ 'aws.access_key_id' '{access_key_id}',
+ 'aws.secret_access_key' '{secret_access_key}',
+ 'aws.endpoint' '{endpoint_url}',
'aws.allow_http' 'true'
);
SELECT * FROM CARS limit 1;
-"#,
- access_key_id, secret_access_key, endpoint_url
+"#
);
assert_cmd_snapshot!(cli().env_clear().pass_stdin(input));
diff --git a/datafusion/ffi/src/plan_properties.rs b/datafusion/ffi/src/plan_properties.rs
index 479696e388..5c878fa4be 100644
--- a/datafusion/ffi/src/plan_properties.rs
+++ b/datafusion/ffi/src/plan_properties.rs
@@ -321,7 +321,7 @@ mod tests {
let foreign_props: PlanProperties = local_props_ptr.try_into()?;
- assert!(format!("{foreign_props:?}") == format!("{original_props:?}"));
+ assert_eq!(format!("{foreign_props:?}"), format!("{original_props:?}"));
Ok(())
}
diff --git a/datafusion/proto/src/logical_plan/file_formats.rs b/datafusion/proto/src/logical_plan/file_formats.rs
index 5c33277dc9..d3f6511ec9 100644
--- a/datafusion/proto/src/logical_plan/file_formats.rs
+++ b/datafusion/proto/src/logical_plan/file_formats.rs
@@ -205,10 +205,7 @@ impl LogicalExtensionCodec for CsvLogicalExtensionCodec {
_ctx: &SessionContext,
) -> datafusion_common::Result<Arc<dyn FileFormatFactory>> {
let proto = CsvOptionsProto::decode(buf).map_err(|e| {
- DataFusionError::Execution(format!(
- "Failed to decode CsvOptionsProto: {:?}",
- e
- ))
+ DataFusionError::Execution(format!("Failed to decode CsvOptionsProto: {e:?}"))
})?;
let options: CsvOptions = (&proto).into();
Ok(Arc::new(CsvFormatFactory {
@@ -233,7 +230,7 @@ impl LogicalExtensionCodec for CsvLogicalExtensionCodec {
});
proto.encode(buf).map_err(|e| {
- DataFusionError::Execution(format!("Failed to encode CsvOptions: {:?}", e))
+ DataFusionError::Execution(format!("Failed to encode CsvOptions: {e:?}"))
})?;
Ok(())
@@ -316,8 +313,7 @@ impl LogicalExtensionCodec for JsonLogicalExtensionCodec {
) -> datafusion_common::Result<Arc<dyn FileFormatFactory>> {
let proto = JsonOptionsProto::decode(buf).map_err(|e| {
DataFusionError::Execution(format!(
- "Failed to decode JsonOptionsProto: {:?}",
- e
+ "Failed to decode JsonOptionsProto: {e:?}"
))
})?;
let options: JsonOptions = (&proto).into();
@@ -346,7 +342,7 @@ impl LogicalExtensionCodec for JsonLogicalExtensionCodec {
});
proto.encode(buf).map_err(|e| {
- DataFusionError::Execution(format!("Failed to encode JsonOptions: {:?}", e))
+ DataFusionError::Execution(format!("Failed to encode JsonOptions: {e:?}"))
})?;
Ok(())
@@ -632,8 +628,7 @@ impl LogicalExtensionCodec for ParquetLogicalExtensionCodec {
) -> datafusion_common::Result<Arc<dyn FileFormatFactory>> {
let proto = TableParquetOptionsProto::decode(buf).map_err(|e| {
DataFusionError::Execution(format!(
- "Failed to decode TableParquetOptionsProto: {:?}",
- e
+ "Failed to decode TableParquetOptionsProto: {e:?}"
))
})?;
let options: TableParquetOptions = (&proto).into();
@@ -663,8 +658,7 @@ impl LogicalExtensionCodec for ParquetLogicalExtensionCodec {
proto.encode(buf).map_err(|e| {
DataFusionError::Execution(format!(
- "Failed to encode TableParquetOptionsProto: {:?}",
- e
+ "Failed to encode TableParquetOptionsProto: {e:?}"
))
})?;
diff --git a/datafusion/proto/src/logical_plan/mod.rs b/datafusion/proto/src/logical_plan/mod.rs
index a39e6dac37..d934b24dc3 100644
--- a/datafusion/proto/src/logical_plan/mod.rs
+++ b/datafusion/proto/src/logical_plan/mod.rs
@@ -465,7 +465,7 @@ impl AsLogicalPlan for LogicalPlanNode {
));
};
let arrow_type = DataType::try_from(arrow_type).map_err(|e| {
- proto_error(format!("Received an unknown ArrowType: {}", e))
+ proto_error(format!("Received an unknown ArrowType: {e}"))
})?;
Ok((col.name.clone(), arrow_type))
})
@@ -1127,8 +1127,7 @@ impl AsLogicalPlan for LogicalPlanNode {
let arrow_type = protobuf::ArrowType::try_from(arrow_type)
.map_err(|e| {
proto_error(format!(
- "Received an unknown ArrowType: {}",
- e
+ "Received an unknown ArrowType: {e}"
))
})?;
Ok(protobuf::PartitionColumn {
diff --git a/datafusion/proto/tests/cases/roundtrip_logical_plan.rs b/datafusion/proto/tests/cases/roundtrip_logical_plan.rs
index eee1bc23c9..ac3b14aeaf 100644
--- a/datafusion/proto/tests/cases/roundtrip_logical_plan.rs
+++ b/datafusion/proto/tests/cases/roundtrip_logical_plan.rs
@@ -126,7 +126,7 @@ fn roundtrip_expr_test_with_codec(
codec: &dyn LogicalExtensionCodec,
) {
let proto: protobuf::LogicalExprNode = serialize_expr(&initial_struct, codec)
- .unwrap_or_else(|e| panic!("Error serializing expression: {:?}", e));
+ .unwrap_or_else(|e| panic!("Error serializing expression: {e:?}"));
let round_trip: Expr = from_proto::parse_expr(&proto, &ctx, codec).unwrap();
assert_eq!(format!("{:?}", &initial_struct), format!("{round_trip:?}"));