Skip to content

Commit e8f0d08

Browse files
committed
cargo fmt
1 parent 4b41400 commit e8f0d08

File tree

4 files changed

+67
-14
lines changed

4 files changed

+67
-14
lines changed

datafusion/core/src/datasource/listing/url.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,21 @@ impl ListingTableUrl {
9292
/// Get object store for specified input_url
9393
/// if input_url is actually not a url, we assume it is a local file path
9494
/// if we have a local path, create it if not exists so ListingTableUrl::parse works
95-
pub fn parse_create_local_if_not_exists(s: impl AsRef<str>, is_directory: bool) -> Result<Self>{
95+
pub fn parse_create_local_if_not_exists(
96+
s: impl AsRef<str>,
97+
is_directory: bool,
98+
) -> Result<Self> {
9699
let s = s.as_ref();
97100
let is_valid_url = Url::parse(s).is_ok();
98101

99102
match is_valid_url {
100103
true => ListingTableUrl::parse(s),
101104
false => {
102105
let path = std::path::PathBuf::from(s);
103-
if !path.exists(){
104-
if is_directory{
106+
if !path.exists() {
107+
if is_directory {
105108
fs::create_dir_all(path)?;
106-
} else{
109+
} else {
107110
fs::File::create(path)?;
108111
}
109112
}

datafusion/core/src/datasource/listing_table_factory.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,27 +145,36 @@ impl TableProviderFactory for ListingTableFactory {
145145
},
146146
}?;
147147

148-
let create_local_path_mode = cmd.options.get("create_local_path")
148+
let create_local_path_mode = cmd
149+
.options
150+
.get("create_local_path")
149151
.map(|s| s.as_str())
150152
.unwrap_or("false");
151-
let single_file = cmd.options.get("single_file")
153+
let single_file = cmd
154+
.options
155+
.get("single_file")
152156
.map(|s| s.as_str())
153157
.unwrap_or("false");
154158

155-
let single_file = match single_file{
159+
let single_file = match single_file {
156160
"true" => Ok(true),
157161
"false" => Ok(false),
158-
_ => Err(DataFusionError::Plan("Invalid option single_file, must be 'true' or 'false'".into()))
162+
_ => Err(DataFusionError::Plan(
163+
"Invalid option single_file, must be 'true' or 'false'".into(),
164+
)),
159165
}?;
160166

161-
let table_path = match create_local_path_mode{
162-
"true" => ListingTableUrl::parse_create_local_if_not_exists(&cmd.location, !single_file),
167+
let table_path = match create_local_path_mode {
168+
"true" => ListingTableUrl::parse_create_local_if_not_exists(
169+
&cmd.location,
170+
!single_file,
171+
),
163172
"false" => ListingTableUrl::parse(&cmd.location),
164-
_ => Err(DataFusionError::Plan("Invalid option create_local_path, must be 'true' or 'false'".into()))
173+
_ => Err(DataFusionError::Plan(
174+
"Invalid option create_local_path, must be 'true' or 'false'".into(),
175+
)),
165176
}?;
166177

167-
168-
169178
let options = ListingOptions::new(file_format)
170179
.with_collect_stat(state.config().collect_statistics())
171180
.with_file_extension(file_extension)

datafusion/expr/src/logical_plan/plan.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,7 @@ impl LogicalPlan {
11041104
.map(|(k, v)| format!("{k} {v}"))
11051105
.collect::<Vec<String>>()
11061106
.join(", ");
1107-
1107+
11081108
write!(f, "CopyTo: format={file_format} output_url={output_url} per_thread_output={per_thread_output} options: ({op_str})")
11091109
}
11101110
LogicalPlan::Ddl(ddl) => {

datafusion/sqllogictest/test_files/insert_to_external.slt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,47 @@ LOCATION '../../testing/data/csv/aggregate_test_100.csv'
4545
statement ok
4646
set datafusion.execution.target_partitions = 8;
4747

48+
statement ok
49+
CREATE EXTERNAL TABLE
50+
single_file_test(a bigint, b bigint)
51+
STORED AS csv
52+
LOCATION 'test_files/scratch/single_csv_table.csv'
53+
OPTIONS(
54+
create_local_path 'true',
55+
single_file 'true',
56+
);
57+
58+
query II
59+
INSERT INTO single_file_test values (1, 2), (3, 4);
60+
----
61+
2
62+
63+
query II
64+
select * from single_file_test;
65+
----
66+
1 2
67+
3 4
68+
69+
statement ok
70+
CREATE EXTERNAL TABLE
71+
directory_test(a bigint, b bigint)
72+
STORED AS parquet
73+
LOCATION 'test_files/scratch/external_parquet_table_q0'
74+
OPTIONS(
75+
create_local_path 'true',
76+
);
77+
78+
query II
79+
INSERT INTO directory_test values (1, 2), (3, 4);
80+
----
81+
2
82+
83+
query II
84+
select * from directory_test;
85+
----
86+
1 2
87+
3 4
88+
4889
statement ok
4990
CREATE EXTERNAL TABLE
5091
table_without_values(field1 BIGINT NULL, field2 BIGINT NULL)

0 commit comments

Comments
 (0)