Skip to content

Commit 1f26716

Browse files
authored
Update 4 crates to rust 2024 edition (#19357)
## Which issue does this PR close? This addresses part of #15804 but does not close it. ## Rationale for this change Now that we are on MSRV 1.88 we can use rust edition 2024, which brings let chains and other nice features. It also improves `unsafe` checking. In order to introduce these changes in slower way instead of one massive PR that is too difficult to manage we are updating a few crates at a time. ## What changes are included in this PR? Updates these crates to 2024. - datafusion-cli - datafusion-proto - datafusion-substrait - datafusion-wasmtest ## Are these changes tested? Existing unit tests. There are no functional code changes. ## Are there any user-facing changes? None. ## Note It is recommended to review with the ignore whitespace setting: https://github.com/apache/datafusion/pull/19357/files?w=1
1 parent efd793b commit 1f26716

Some content is hidden

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

81 files changed

+651
-549
lines changed

datafusion-cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ name = "datafusion-cli"
2020
description = "Command Line Client for DataFusion query engine."
2121
readme = "README.md"
2222
version = { workspace = true }
23-
edition = { workspace = true }
23+
edition = "2024"
2424
homepage = { workspace = true }
2525
repository = { workspace = true }
2626
license = { workspace = true }

datafusion-cli/examples/cli-session-context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use std::sync::Arc;
2323
use datafusion::{
2424
dataframe::DataFrame,
2525
error::DataFusionError,
26-
execution::{context::SessionState, TaskContext},
26+
execution::{TaskContext, context::SessionState},
2727
logical_expr::{LogicalPlan, LogicalPlanBuilder},
2828
prelude::SessionContext,
2929
};

datafusion-cli/src/catalog.rs

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
use std::any::Any;
1919
use std::sync::{Arc, Weak};
2020

21-
use crate::object_storage::{get_object_store, AwsOptions, GcpOptions};
21+
use crate::object_storage::{AwsOptions, GcpOptions, get_object_store};
2222

2323
use datafusion::catalog::{CatalogProvider, CatalogProviderList, SchemaProvider};
2424

2525
use datafusion::common::plan_datafusion_err;
26-
use datafusion::datasource::listing::ListingTableUrl;
2726
use datafusion::datasource::TableProvider;
27+
use datafusion::datasource::listing::ListingTableUrl;
2828
use datafusion::error::Result;
2929
use datafusion::execution::context::SessionState;
3030
use datafusion::execution::session_state::SessionStateBuilder;
@@ -152,10 +152,10 @@ impl SchemaProvider for DynamicObjectStoreSchemaProvider {
152152

153153
async fn table(&self, name: &str) -> Result<Option<Arc<dyn TableProvider>>> {
154154
let inner_table = self.inner.table(name).await;
155-
if inner_table.is_ok() {
156-
if let Some(inner_table) = inner_table? {
157-
return Ok(Some(inner_table));
158-
}
155+
if inner_table.is_ok()
156+
&& let Some(inner_table) = inner_table?
157+
{
158+
return Ok(Some(inner_table));
159159
}
160160

161161
// if the inner schema provider didn't have a table by
@@ -219,12 +219,12 @@ impl SchemaProvider for DynamicObjectStoreSchemaProvider {
219219
}
220220

221221
pub fn substitute_tilde(cur: String) -> String {
222-
if let Some(usr_dir_path) = home_dir() {
223-
if let Some(usr_dir) = usr_dir_path.to_str() {
224-
if cur.starts_with('~') && !usr_dir.is_empty() {
225-
return cur.replacen('~', usr_dir, 1);
226-
}
227-
}
222+
if let Some(usr_dir_path) = home_dir()
223+
&& let Some(usr_dir) = usr_dir_path.to_str()
224+
&& cur.starts_with('~')
225+
&& !usr_dir.is_empty()
226+
{
227+
return cur.replacen('~', usr_dir, 1);
228228
}
229229
cur
230230
}
@@ -359,10 +359,12 @@ mod tests {
359359
} else {
360360
"/home/user"
361361
};
362-
env::set_var(
363-
if cfg!(windows) { "USERPROFILE" } else { "HOME" },
364-
test_home_path,
365-
);
362+
unsafe {
363+
env::set_var(
364+
if cfg!(windows) { "USERPROFILE" } else { "HOME" },
365+
test_home_path,
366+
);
367+
}
366368
let input = "~/Code/datafusion/benchmarks/data/tpch_sf1/part/part-0.parquet";
367369
let expected = PathBuf::from(test_home_path)
368370
.join("Code")
@@ -376,12 +378,16 @@ mod tests {
376378
.to_string();
377379
let actual = substitute_tilde(input.to_string());
378380
assert_eq!(actual, expected);
379-
match original_home {
380-
Some(home_path) => env::set_var(
381-
if cfg!(windows) { "USERPROFILE" } else { "HOME" },
382-
home_path.to_str().unwrap(),
383-
),
384-
None => env::remove_var(if cfg!(windows) { "USERPROFILE" } else { "HOME" }),
381+
unsafe {
382+
match original_home {
383+
Some(home_path) => env::set_var(
384+
if cfg!(windows) { "USERPROFILE" } else { "HOME" },
385+
home_path.to_str().unwrap(),
386+
),
387+
None => {
388+
env::remove_var(if cfg!(windows) { "USERPROFILE" } else { "HOME" })
389+
}
390+
}
385391
}
386392
}
387393
}

datafusion-cli/src/cli_context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use std::sync::Arc;
2020
use datafusion::{
2121
dataframe::DataFrame,
2222
error::DataFusionError,
23-
execution::{context::SessionState, TaskContext},
23+
execution::{TaskContext, context::SessionState},
2424
logical_expr::LogicalPlan,
2525
prelude::SessionContext,
2626
};

datafusion-cli/src/command.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
2020
use crate::cli_context::CliSessionContext;
2121
use crate::exec::{exec_and_print, exec_from_lines};
22-
use crate::functions::{display_all_functions, Function};
22+
use crate::functions::{Function, display_all_functions};
2323
use crate::print_format::PrintFormat;
2424
use crate::print_options::PrintOptions;
2525
use clap::ValueEnum;

datafusion-cli/src/exec.rs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,19 @@ use datafusion::execution::memory_pool::MemoryConsumer;
3535
use datafusion::logical_expr::{DdlStatement, LogicalPlan};
3636
use datafusion::physical_plan::execution_plan::EmissionType;
3737
use datafusion::physical_plan::spill::get_record_batch_memory_size;
38-
use datafusion::physical_plan::{execute_stream, ExecutionPlanProperties};
38+
use datafusion::physical_plan::{ExecutionPlanProperties, execute_stream};
3939
use datafusion::sql::parser::{DFParser, Statement};
4040
use datafusion::sql::sqlparser;
4141
use datafusion::sql::sqlparser::dialect::dialect_from_str;
4242
use futures::StreamExt;
4343
use log::warn;
4444
use object_store::Error::Generic;
45-
use rustyline::error::ReadlineError;
4645
use rustyline::Editor;
46+
use rustyline::error::ReadlineError;
4747
use std::collections::HashMap;
4848
use std::fs::File;
49-
use std::io::prelude::*;
5049
use std::io::BufReader;
50+
use std::io::prelude::*;
5151
use tokio::signal;
5252

5353
/// run and execute SQL statements and commands, against a context with the given print options
@@ -168,7 +168,10 @@ pub async fn exec_from_repl(
168168
}
169169
}
170170
} else {
171-
eprintln!("'\\{}' is not a valid command, you can use '\\?' to see all commands", &line[1..]);
171+
eprintln!(
172+
"'\\{}' is not a valid command, you can use '\\?' to see all commands",
173+
&line[1..]
174+
);
172175
}
173176
}
174177
Ok(line) => {
@@ -334,7 +337,9 @@ impl StatementExecutor {
334337
if matches!(err.as_ref(), Generic { store, source: _ } if "S3".eq_ignore_ascii_case(store))
335338
&& self.statement_for_retry.is_some() =>
336339
{
337-
warn!("S3 region is incorrect, auto-detecting the correct region (this may be slow). Consider updating your region configuration.");
340+
warn!(
341+
"S3 region is incorrect, auto-detecting the correct region (this may be slow). Consider updating your region configuration."
342+
);
338343
let plan =
339344
create_plan(ctx, self.statement_for_retry.take().unwrap(), true)
340345
.await?;
@@ -699,8 +704,7 @@ mod tests {
699704
#[tokio::test]
700705
async fn create_object_store_table_gcs() -> Result<()> {
701706
let service_account_path = "fake_service_account_path";
702-
let service_account_key =
703-
"{\"private_key\": \"fake_private_key.pem\",\"client_email\":\"fake_client_email\", \"private_key_id\":\"id\"}";
707+
let service_account_key = "{\"private_key\": \"fake_private_key.pem\",\"client_email\":\"fake_client_email\", \"private_key_id\":\"id\"}";
704708
let application_credentials_path = "fake_application_credentials_path";
705709
let location = "gcs://bucket/path/file.parquet";
706710

@@ -713,7 +717,9 @@ mod tests {
713717
assert!(err.to_string().contains("os error 2"));
714718

715719
// for service_account_key
716-
let sql = format!("CREATE EXTERNAL TABLE test STORED AS PARQUET OPTIONS('gcp.service_account_key' '{service_account_key}') LOCATION '{location}'");
720+
let sql = format!(
721+
"CREATE EXTERNAL TABLE test STORED AS PARQUET OPTIONS('gcp.service_account_key' '{service_account_key}') LOCATION '{location}'"
722+
);
717723
let err = create_external_table_test(location, &sql)
718724
.await
719725
.unwrap_err()
@@ -748,8 +754,9 @@ mod tests {
748754
let location = "path/to/file.cvs";
749755

750756
// Test with format options
751-
let sql =
752-
format!("CREATE EXTERNAL TABLE test STORED AS CSV LOCATION '{location}' OPTIONS('format.has_header' 'true')");
757+
let sql = format!(
758+
"CREATE EXTERNAL TABLE test STORED AS CSV LOCATION '{location}' OPTIONS('format.has_header' 'true')"
759+
);
753760
create_external_table_test(location, &sql).await.unwrap();
754761

755762
Ok(())

datafusion-cli/src/functions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ use arrow::datatypes::{DataType, Field, Schema, SchemaRef, TimeUnit};
2727
use arrow::record_batch::RecordBatch;
2828
use arrow::util::pretty::pretty_format_batches;
2929
use datafusion::catalog::{Session, TableFunctionImpl};
30-
use datafusion::common::{plan_err, Column};
31-
use datafusion::datasource::memory::MemorySourceConfig;
30+
use datafusion::common::{Column, plan_err};
3231
use datafusion::datasource::TableProvider;
32+
use datafusion::datasource::memory::MemorySourceConfig;
3333
use datafusion::error::Result;
3434
use datafusion::execution::cache::cache_manager::CacheManager;
3535
use datafusion::logical_expr::Expr;

datafusion-cli/src/helper.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl CliHelper {
6767
return Ok(ValidationResult::Invalid(Some(format!(
6868
" 🤔 Invalid dialect: {}",
6969
self.dialect
70-
))))
70+
))));
7171
}
7272
};
7373
let lines = split_from_semicolon(sql);
@@ -121,10 +121,10 @@ impl Hinter for CliHelper {
121121
fn is_open_quote_for_location(line: &str, pos: usize) -> bool {
122122
let mut sql = line[..pos].to_string();
123123
sql.push('\'');
124-
if let Ok(stmts) = DFParser::parse_sql(&sql) {
125-
if let Some(Statement::CreateExternalTable(_)) = stmts.back() {
126-
return true;
127-
}
124+
if let Ok(stmts) = DFParser::parse_sql(&sql)
125+
&& let Some(Statement::CreateExternalTable(_)) = stmts.back()
126+
{
127+
return true;
128128
}
129129
false
130130
}

datafusion-cli/src/highlighter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use std::{
2323
};
2424

2525
use datafusion::sql::sqlparser::{
26-
dialect::{dialect_from_str, Dialect, GenericDialect},
26+
dialect::{Dialect, GenericDialect, dialect_from_str},
2727
keywords::Keyword,
2828
tokenizer::{Token, Tokenizer},
2929
};
@@ -94,8 +94,8 @@ impl Color {
9494

9595
#[cfg(test)]
9696
mod tests {
97-
use super::config::Dialect;
9897
use super::SyntaxHighlighter;
98+
use super::config::Dialect;
9999
use rustyline::highlight::Highlighter;
100100

101101
#[test]

datafusion-cli/src/main.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,10 @@ use datafusion_cli::object_storage::instrumented::{
3838
InstrumentedObjectStoreMode, InstrumentedObjectStoreRegistry,
3939
};
4040
use datafusion_cli::{
41-
exec,
41+
DATAFUSION_CLI_VERSION, exec,
4242
pool_type::PoolType,
4343
print_format::PrintFormat,
4444
print_options::{MaxRows, PrintOptions},
45-
DATAFUSION_CLI_VERSION,
4645
};
4746

4847
use clap::Parser;
@@ -504,8 +503,7 @@ mod tests {
504503
ctx.register_udtf("parquet_metadata", Arc::new(ParquetMetadataFunc {}));
505504

506505
// input with single quote
507-
let sql =
508-
"SELECT * FROM parquet_metadata('../datafusion/core/tests/data/fixed_size_list_array.parquet')";
506+
let sql = "SELECT * FROM parquet_metadata('../datafusion/core/tests/data/fixed_size_list_array.parquet')";
509507
let df = ctx.sql(sql).await?;
510508
let rbs = df.collect().await?;
511509

@@ -518,8 +516,7 @@ mod tests {
518516
"#);
519517

520518
// input with double quote
521-
let sql =
522-
"SELECT * FROM parquet_metadata(\"../datafusion/core/tests/data/fixed_size_list_array.parquet\")";
519+
let sql = "SELECT * FROM parquet_metadata(\"../datafusion/core/tests/data/fixed_size_list_array.parquet\")";
523520
let df = ctx.sql(sql).await?;
524521
let rbs = df.collect().await?;
525522
assert_snapshot!(batches_to_string(&rbs), @r#"
@@ -539,8 +536,7 @@ mod tests {
539536
ctx.register_udtf("parquet_metadata", Arc::new(ParquetMetadataFunc {}));
540537

541538
// input with string columns
542-
let sql =
543-
"SELECT * FROM parquet_metadata('../parquet-testing/data/data_index_bloom_encoding_stats.parquet')";
539+
let sql = "SELECT * FROM parquet_metadata('../parquet-testing/data/data_index_bloom_encoding_stats.parquet')";
544540
let df = ctx.sql(sql).await?;
545541
let rbs = df.collect().await?;
546542

0 commit comments

Comments
 (0)