Skip to content

Commit 7dd0923

Browse files
committed
Complete upgrade to object_store 0.13.0
1 parent 721250f commit 7dd0923

File tree

23 files changed

+226
-243
lines changed

23 files changed

+226
-243
lines changed

datafusion-cli/src/object_storage/instrumented.rs

Lines changed: 56 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,14 @@ use datafusion::{
3535
error::DataFusionError,
3636
execution::object_store::{DefaultObjectStoreRegistry, ObjectStoreRegistry},
3737
};
38-
use futures::stream::{BoxStream, Stream};
38+
use futures::{
39+
StreamExt,
40+
stream::{BoxStream, Stream},
41+
};
3942
use object_store::{
40-
GetOptions, GetRange, GetResult, ListResult, MultipartUpload, ObjectMeta,
41-
ObjectStore, PutMultipartOptions, PutOptions, PutPayload, PutResult, Result,
42-
path::Path,
43+
CopyOptions, GetOptions, GetRange, GetResult, ListResult, MultipartUpload,
44+
ObjectMeta, ObjectStore, PutMultipartOptions, PutOptions, PutPayload, PutResult,
45+
Result, path::Path,
4346
};
4447
use parking_lot::{Mutex, RwLock};
4548
use url::Url;
@@ -228,42 +231,56 @@ impl InstrumentedObjectStore {
228231
options: GetOptions,
229232
) -> Result<GetResult> {
230233
let timestamp = Utc::now();
234+
let operation = if options.head {
235+
Operation::Head
236+
} else {
237+
Operation::Get
238+
};
231239
let range = options.range.clone();
232240

233241
let start = Instant::now();
234242
let ret = self.inner.get_opts(location, options).await?;
235243
let elapsed = start.elapsed();
236244

237245
self.requests.lock().push(RequestDetails {
238-
op: Operation::Get,
246+
op: operation,
239247
path: location.clone(),
240248
timestamp,
241249
duration: Some(elapsed),
242-
size: Some((ret.range.end - ret.range.start) as usize),
250+
size: (operation == Operation::Get)
251+
.then_some((ret.range.end - ret.range.start) as usize),
243252
range,
244253
extra_display: None,
245254
});
246255

247256
Ok(ret)
248257
}
249258

250-
async fn instrumented_delete(&self, location: &Path) -> Result<()> {
259+
fn instrumented_delete_stream(
260+
&self,
261+
locations: BoxStream<'static, Result<Path>>,
262+
) -> BoxStream<'static, Result<Path>> {
251263
let timestamp = Utc::now();
252264
let start = Instant::now();
253-
self.inner.delete(location).await?;
254-
let elapsed = start.elapsed();
255-
256-
self.requests.lock().push(RequestDetails {
257-
op: Operation::Delete,
258-
path: location.clone(),
259-
timestamp,
260-
duration: Some(elapsed),
261-
size: None,
262-
range: None,
263-
extra_display: None,
264-
});
265-
266-
Ok(())
265+
let requests = Arc::clone(&self.requests);
266+
267+
self.inner
268+
.delete_stream(locations)
269+
.inspect(move |result| {
270+
if let Ok(path) = result {
271+
let elapsed = start.elapsed();
272+
requests.lock().push(RequestDetails {
273+
op: Operation::Delete,
274+
path: path.clone(),
275+
timestamp,
276+
duration: Some(elapsed),
277+
size: None,
278+
range: None,
279+
extra_display: None,
280+
});
281+
}
282+
})
283+
.boxed()
267284
}
268285

269286
fn instrumented_list(
@@ -320,33 +337,15 @@ impl InstrumentedObjectStore {
320337
Ok(ret)
321338
}
322339

323-
async fn instrumented_copy(&self, from: &Path, to: &Path) -> Result<()> {
324-
let timestamp = Utc::now();
325-
let start = Instant::now();
326-
self.inner.copy(from, to).await?;
327-
let elapsed = start.elapsed();
328-
329-
self.requests.lock().push(RequestDetails {
330-
op: Operation::Copy,
331-
path: from.clone(),
332-
timestamp,
333-
duration: Some(elapsed),
334-
size: None,
335-
range: None,
336-
extra_display: Some(format!("copy_to: {to}")),
337-
});
338-
339-
Ok(())
340-
}
341-
342-
async fn instrumented_copy_if_not_exists(
340+
async fn instrumented_copy_opts(
343341
&self,
344342
from: &Path,
345343
to: &Path,
344+
options: CopyOptions,
346345
) -> Result<()> {
347346
let timestamp = Utc::now();
348347
let start = Instant::now();
349-
self.inner.copy_if_not_exists(from, to).await?;
348+
self.inner.copy_opts(from, to, options).await?;
350349
let elapsed = start.elapsed();
351350

352351
self.requests.lock().push(RequestDetails {
@@ -361,25 +360,6 @@ impl InstrumentedObjectStore {
361360

362361
Ok(())
363362
}
364-
365-
async fn instrumented_head(&self, location: &Path) -> Result<ObjectMeta> {
366-
let timestamp = Utc::now();
367-
let start = Instant::now();
368-
let ret = self.inner.head(location).await?;
369-
let elapsed = start.elapsed();
370-
371-
self.requests.lock().push(RequestDetails {
372-
op: Operation::Head,
373-
path: location.clone(),
374-
timestamp,
375-
duration: Some(elapsed),
376-
size: None,
377-
range: None,
378-
extra_display: None,
379-
});
380-
381-
Ok(ret)
382-
}
383363
}
384364

385365
impl fmt::Display for InstrumentedObjectStore {
@@ -429,14 +409,6 @@ impl ObjectStore for InstrumentedObjectStore {
429409
self.inner.get_opts(location, options).await
430410
}
431411

432-
async fn delete(&self, location: &Path) -> Result<()> {
433-
if self.enabled() {
434-
return self.instrumented_delete(location).await;
435-
}
436-
437-
self.inner.delete(location).await
438-
}
439-
440412
fn list(&self, prefix: Option<&Path>) -> BoxStream<'static, Result<ObjectMeta>> {
441413
if self.enabled() {
442414
return self.instrumented_list(prefix);
@@ -453,28 +425,28 @@ impl ObjectStore for InstrumentedObjectStore {
453425
self.inner.list_with_delimiter(prefix).await
454426
}
455427

456-
async fn copy(&self, from: &Path, to: &Path) -> Result<()> {
457-
if self.enabled() {
458-
return self.instrumented_copy(from, to).await;
459-
}
460-
461-
self.inner.copy(from, to).await
462-
}
463-
464-
async fn copy_if_not_exists(&self, from: &Path, to: &Path) -> Result<()> {
428+
fn delete_stream(
429+
&self,
430+
locations: BoxStream<'static, Result<Path>>,
431+
) -> BoxStream<'static, Result<Path>> {
465432
if self.enabled() {
466-
return self.instrumented_copy_if_not_exists(from, to).await;
433+
return self.instrumented_delete_stream(locations);
467434
}
468435

469-
self.inner.copy_if_not_exists(from, to).await
436+
self.inner.delete_stream(locations)
470437
}
471438

472-
async fn head(&self, location: &Path) -> Result<ObjectMeta> {
439+
async fn copy_opts(
440+
&self,
441+
from: &Path,
442+
to: &Path,
443+
options: CopyOptions,
444+
) -> Result<()> {
473445
if self.enabled() {
474-
return self.instrumented_head(location).await;
446+
return self.instrumented_copy_opts(from, to, options).await;
475447
}
476448

477-
self.inner.head(location).await
449+
self.inner.copy_opts(from, to, options).await
478450
}
479451
}
480452

@@ -824,6 +796,7 @@ impl ObjectStoreRegistry for InstrumentedObjectStoreRegistry {
824796
#[cfg(test)]
825797
mod tests {
826798
use futures::StreamExt;
799+
use object_store::ObjectStoreExt;
827800
use object_store::WriteMultipart;
828801

829802
use super::*;

datafusion-examples/examples/custom_data_source/csv_json_opener.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ use datafusion::{
3636

3737
use datafusion::datasource::physical_plan::FileScanConfigBuilder;
3838
use futures::StreamExt;
39-
use object_store::{ObjectStore, local::LocalFileSystem, memory::InMemory};
39+
use object_store::ObjectStoreExt;
40+
use object_store::{local::LocalFileSystem, memory::InMemory};
4041

4142
/// This example demonstrates using the low level [`FileStream`] / [`FileOpener`] APIs to directly
4243
/// read data from (CSV/JSON) into Arrow RecordBatches.

datafusion-examples/examples/custom_data_source/custom_file_casts.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ use datafusion::prelude::SessionConfig;
3838
use datafusion_physical_expr_adapter::{
3939
DefaultPhysicalExprAdapterFactory, PhysicalExprAdapter, PhysicalExprAdapterFactory,
4040
};
41+
use object_store::ObjectStoreExt;
4142
use object_store::memory::InMemory;
4243
use object_store::path::Path;
4344
use object_store::{ObjectStore, PutPayload};

datafusion-examples/examples/custom_data_source/default_column_values.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ use datafusion_physical_expr_adapter::{
4646
replace_columns_with_literals,
4747
};
4848
use futures::StreamExt;
49+
use object_store::ObjectStoreExt;
4950
use object_store::memory::InMemory;
5051
use object_store::path::Path;
5152
use object_store::{ObjectStore, PutPayload};

datafusion-examples/examples/data_io/json_shredding.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ use datafusion::scalar::ScalarValue;
4545
use datafusion_physical_expr_adapter::{
4646
DefaultPhysicalExprAdapterFactory, PhysicalExprAdapter, PhysicalExprAdapterFactory,
4747
};
48+
use object_store::ObjectStoreExt;
49+
use object_store::PutPayload;
4850
use object_store::memory::InMemory;
4951
use object_store::path::Path;
50-
use object_store::{ObjectStore, PutPayload};
5152

5253
// Example showing how to implement custom filter rewriting for JSON shredding.
5354
//

datafusion-examples/examples/data_io/parquet_advanced_index.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ impl ParquetFileReaderFactory for CachedParquetFileReaderFactory {
567567
.object_meta
568568
.location
569569
.parts()
570-
.last()
570+
.next_back()
571571
.expect("No path in location")
572572
.as_ref()
573573
.to_string();

datafusion/core/benches/push_down_filter.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use datafusion_physical_optimizer::PhysicalOptimizerRule;
2626
use datafusion_physical_optimizer::filter_pushdown::FilterPushdown;
2727
use datafusion_physical_plan::ExecutionPlan;
2828
use object_store::ObjectStore;
29+
use object_store::ObjectStoreExt;
2930
use object_store::memory::InMemory;
3031
use object_store::path::Path;
3132
use parquet::arrow::ArrowWriter;

datafusion/core/benches/sql_query_with_io.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use datafusion::{
3030
};
3131
use datafusion_execution::runtime_env::RuntimeEnv;
3232
use itertools::Itertools;
33+
use object_store::ObjectStoreExt;
3334
use object_store::{
3435
ObjectStore,
3536
memory::InMemory,

datafusion/core/src/datasource/file_format/csv.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,14 @@ mod tests {
6060
use futures::StreamExt;
6161
use futures::stream::BoxStream;
6262
use insta::assert_snapshot;
63+
use object_store::ObjectStoreExt;
6364
use object_store::chunked::ChunkedStore;
6465
use object_store::local::LocalFileSystem;
6566
use object_store::path::Path;
6667
use object_store::{
67-
Attributes, GetOptions, GetResult, GetResultPayload, ListResult, MultipartUpload,
68-
ObjectMeta, ObjectStore, PutMultipartOptions, PutOptions, PutPayload, PutResult,
68+
Attributes, CopyOptions, GetOptions, GetResult, GetResultPayload, ListResult,
69+
MultipartUpload, ObjectMeta, ObjectStore, PutMultipartOptions, PutOptions,
70+
PutPayload, PutResult,
6971
};
7072
use regex::Regex;
7173
use rstest::*;
@@ -159,10 +161,19 @@ mod tests {
159161

160162
fn delete_stream(
161163
&self,
162-
locations: BoxStream<'static, object_store::Result<Path>>,
164+
_locations: BoxStream<'static, object_store::Result<Path>>,
163165
) -> BoxStream<'static, object_store::Result<Path>> {
164166
unimplemented!()
165167
}
168+
169+
async fn copy_opts(
170+
&self,
171+
_from: &Path,
172+
_to: &Path,
173+
_options: CopyOptions,
174+
) -> object_store::Result<()> {
175+
unimplemented!()
176+
}
166177
}
167178

168179
impl VariableStream {

0 commit comments

Comments
 (0)