Repository navigation
Fix/18211 versioned scans #27934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
HairstonE
wants to merge
3
commits into
apache:main
Choose a base branch
from
HairstonE:fix/18211-versioned-scans
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+526
−29
Open
Fix/18211 versioned scans #27934
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,3 +11,4 @@ mod compression; | |
| // Include tests in csv module | ||
| mod csv; | ||
| mod object_store_access; | ||
| mod object_version_pinning; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
209 changes: 209 additions & 0 deletions
209
datafusion/core/tests/datasource/object_version_pinning.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,209 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // SPDX-FileCopyrightText: See the NOTICE file distributed with this work for additional information regarding copyright ownership | ||
| // SPDX-FileContributor: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements | ||
|
|
||
| use super::object_store_access::{RequestCountingObjectStore, RequestDetails}; | ||
| use arrow::array::{ArrayRef, Int32Array, RecordBatch}; | ||
| use arrow::datatypes::{DataType, Field, Schema, SchemaRef}; | ||
| use datafusion::physical_plan::{ExecutionPlan, collect}; | ||
| use datafusion::prelude::SessionContext; | ||
| use datafusion_catalog_listing::{ListingOptions, ListingTable, ListingTableConfig}; | ||
| use datafusion_common::Result; | ||
| use datafusion_datasource::file_format::FileFormat; | ||
| use datafusion_datasource::{ListingTableUrl, ObjectVersionType}; | ||
| use datafusion_datasource_csv::CsvFormat; | ||
| use datafusion_datasource_json::JsonFormat; | ||
| use datafusion_datasource_parquet::file_format::ParquetFormat; | ||
| use object_store::path::Path; | ||
| use object_store::{ObjectStore, ObjectStoreExt}; | ||
| use parquet::arrow::ArrowWriter; | ||
| use std::sync::Arc; | ||
| use url::Url; | ||
|
|
||
| #[derive(Clone, Copy, Debug)] | ||
| enum Kind { | ||
| Parquet, | ||
| Csv, | ||
| Json, | ||
| } | ||
|
|
||
| impl Kind { | ||
| fn all() -> [Kind; 3] { | ||
| [Kind::Parquet, Kind::Csv, Kind::Json] | ||
| } | ||
|
|
||
| fn format(self) -> Arc<dyn FileFormat> { | ||
| match self { | ||
| Kind::Parquet => Arc::new(ParquetFormat::default()), | ||
| Kind::Csv => Arc::new(CsvFormat::default().with_has_header(true)), | ||
| Kind::Json => Arc::new(JsonFormat::default()), | ||
| } | ||
| } | ||
|
|
||
| fn path(self) -> &'static str { | ||
| match self { | ||
| Kind::Parquet => "t/data.parquet", | ||
| Kind::Csv => "t/data.csv", | ||
| Kind::Json => "t/data.json", | ||
| } | ||
| } | ||
|
|
||
| fn bytes(self, values: &[i32]) -> Vec<u8> { | ||
| match self { | ||
| Kind::Parquet => { | ||
| let array: ArrayRef = Arc::new(Int32Array::from(values.to_vec())); | ||
| let batch = RecordBatch::try_new(schema(), vec![array]).unwrap(); | ||
| let mut out = vec![]; | ||
| let mut writer = ArrowWriter::try_new(&mut out, schema(), None).unwrap(); | ||
| writer.write(&batch).unwrap(); | ||
| writer.close().unwrap(); | ||
| out | ||
| } | ||
| Kind::Csv => lines(values, "v\n", |v| v.to_string()), | ||
| Kind::Json => lines(values, "", |v| format!("{{\"v\":{v}}}")), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fn lines(values: &[i32], header: &str, line: fn(&i32) -> String) -> Vec<u8> { | ||
| let mut out = header.to_string(); | ||
| for v in values { | ||
| out.push_str(&line(v)); | ||
| out.push('\n'); | ||
| } | ||
| out.into_bytes() | ||
| } | ||
|
|
||
| fn schema() -> SchemaRef { | ||
| Arc::new(Schema::new(vec![Field::new("v", DataType::Int32, false)])) | ||
| } | ||
|
|
||
| struct Fixture { | ||
| ctx: SessionContext, | ||
| store: Arc<RequestCountingObjectStore>, | ||
| kind: Kind, | ||
| } | ||
|
|
||
| impl Fixture { | ||
| async fn new(kind: Kind, pin: Option<ObjectVersionType>) -> Self { | ||
| let store = Arc::new(RequestCountingObjectStore::new()); | ||
| store | ||
| .put(&Path::from(kind.path()), kind.bytes(&[1, 2, 3]).into()) | ||
| .await | ||
| .unwrap(); | ||
| let ctx = SessionContext::new(); | ||
| ctx.runtime_env().register_object_store( | ||
| &Url::parse("mem://").unwrap(), | ||
| Arc::clone(&store) as Arc<dyn ObjectStore>, | ||
| ); | ||
| let options = ListingOptions::new(kind.format()) | ||
| .with_file_extension(kind.path().rsplit('.').next().unwrap()) | ||
| .with_object_version_type(pin); | ||
| let config = | ||
| ListingTableConfig::new(ListingTableUrl::parse("mem:///t/").unwrap()) | ||
| .with_listing_options(options) | ||
| .with_schema(schema()); | ||
| ctx.register_table("t", Arc::new(ListingTable::try_new(config).unwrap())) | ||
| .unwrap(); | ||
| Self { ctx, store, kind } | ||
| } | ||
|
|
||
| async fn plan(&self) -> Arc<dyn ExecutionPlan> { | ||
| let df = self.ctx.sql("SELECT v FROM t").await.unwrap(); | ||
| let plan = df.create_physical_plan().await.unwrap(); | ||
| self.store.clear_requests(); | ||
| plan | ||
| } | ||
|
|
||
| async fn run(&self, plan: Arc<dyn ExecutionPlan>) -> Result<Vec<RecordBatch>> { | ||
| collect(plan, self.ctx.task_ctx()).await | ||
| } | ||
|
|
||
| async fn current_etag(&self) -> String { | ||
| let meta = self | ||
| .store | ||
| .head(&Path::from(self.kind.path())) | ||
| .await | ||
| .unwrap(); | ||
| meta.e_tag.unwrap() | ||
| } | ||
|
|
||
| fn recorded_reads(&self) -> Vec<RequestDetails> { | ||
| self.store | ||
| .recorded_requests() | ||
| .into_iter() | ||
| .filter(|r| { | ||
| matches!( | ||
| r, | ||
| RequestDetails::GetOpts { .. } | RequestDetails::GetRanges { .. } | ||
| ) | ||
| }) | ||
| .collect() | ||
| } | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn execution_reads_carry_the_pin_only_when_pinned() { | ||
| for kind in Kind::all() { | ||
| for pin in [Some(ObjectVersionType::ETag), None] { | ||
| let fx = Fixture::new(kind, pin).await; | ||
| let etag = fx.current_etag().await; | ||
| let plan = fx.plan().await; | ||
|
|
||
| let batches = fx.run(plan).await.unwrap(); | ||
| assert_eq!(batches.iter().map(|b| b.num_rows()).sum::<usize>(), 3); | ||
|
|
||
| let want = pin.map(|_| etag.clone()); | ||
| let reads = fx.recorded_reads(); | ||
| assert!(!reads.is_empty(), "{kind:?}: no reads recorded"); | ||
| for read in reads { | ||
| match read { | ||
| RequestDetails::GetOpts { get_options, .. } => { | ||
| assert_eq!(get_options.if_match, want, "{kind:?} pin={pin:?}"); | ||
| } | ||
| // A raw `get_ranges` bypasses `get_opts`, so it can never carry a pin | ||
| other => assert!(pin.is_none(), "{kind:?}: unpinned {other:?}"), | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn overwrite_between_plan_and_execute_fails_only_when_pinned() { | ||
| for kind in Kind::all() { | ||
| for pin in [Some(ObjectVersionType::ETag), None] { | ||
| let fx = Fixture::new(kind, pin).await; | ||
| let plan = fx.plan().await; | ||
|
|
||
| // Same size, different content, new etag | ||
| fx.store | ||
| .put(&Path::from(kind.path()), kind.bytes(&[7, 8, 9]).into()) | ||
| .await | ||
| .unwrap(); | ||
|
|
||
| let run = fx.run(plan).await; | ||
| if pin.is_none() { | ||
| // Documents the bug this feature guards against | ||
| assert!(run.is_ok(), "{kind:?}"); | ||
| continue; | ||
| } | ||
| let err = run.unwrap_err().to_string(); | ||
| assert!( | ||
| err.contains("Precondition") || err.contains("does not match"), | ||
| "{kind:?}: unexpected error: {err}" | ||
| ); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn version_pinning_without_version_errors_at_open() { | ||
| // InMemory reports no `version`, so Version pinning must fail cleanly | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. InMemory reports no version ids, so there is no end-to-end Version test. Version shares the ETag path except which field it copies. |
||
| for kind in Kind::all() { | ||
| let fx = Fixture::new(kind, Some(ObjectVersionType::Version)).await; | ||
| let plan = fx.plan().await; | ||
| let err = fx.run(plan).await.unwrap_err().to_string(); | ||
| assert!(err.contains("Cannot pin"), "{kind:?}: {err}"); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AVRO, Arrow, and custom ParquetFileReaderFactory implementations are not pinned.