-
Notifications
You must be signed in to change notification settings - Fork 593
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
feat(iceberg): support eq delete merge on read for iceberg #18448
Merged
Merged
Changes from 8 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
ab71216
isave
xxhZs 73d22c1
save
xxhZs 46dc286
support
xxhZs 8e2397d
fix risedev
xxhZs 718a6f9
fix risedev
xxhZs edeab1e
fix mutil pk
xxhZs 606c26f
add eq delete schema check
xxhZs 9caa2fd
refa
xxhZs 4ee73ba
fix risedev
xxhZs 62644fe
fix comm
xxhZs 3a35be3
fix comm
xxhZs c68eecd
delete schema mv
xxhZs 7b76adc
fix comm
xxhZs 52adf4c
fix comm
xxhZs f3b6faf
Merge branch 'main' into xxh/iceberg_merge_on_read
xxhZs d38d5bb
add ci
xxhZs da835cf
fix cargo lock
xxhZs 0c29c40
add ci
xxhZs 24092e2
fix ci
xxhZs e39af11
fix ci
xxhZs 16f72bc
Merge branch 'main' into xxh/iceberg_merge_on_read
xxhZs 31c15a7
fix ci
xxhZs e0df8cc
fix ci
xxhZs a42665a
refactor
chenzl25 83c30a6
fix ci
xxhZs 1d78090
Merge branch 'main' into xxh/iceberg_merge_on_read
xxhZs 88a8b62
use dev
xxhZs 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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 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 |
---|---|---|
|
@@ -12,6 +12,8 @@ | |
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use core::ops::BitOr; | ||
use std::collections::HashMap; | ||
use std::mem; | ||
|
||
use futures_async_stream::try_stream; | ||
|
@@ -20,6 +22,7 @@ use iceberg::scan::FileScanTask; | |
use iceberg::spec::TableMetadata; | ||
use itertools::Itertools; | ||
use risingwave_common::array::arrow::IcebergArrowConvert; | ||
use risingwave_common::bitmap::Bitmap; | ||
use risingwave_common::catalog::{Field, Schema}; | ||
use risingwave_common::types::DataType; | ||
use risingwave_connector::sink::iceberg::IcebergConfig; | ||
|
@@ -39,6 +42,7 @@ pub struct IcebergScanExecutor { | |
snapshot_id: Option<i64>, | ||
table_meta: TableMetadata, | ||
file_scan_tasks: Vec<FileScanTask>, | ||
eq_delete_file_scan_tasks: Vec<FileScanTask>, | ||
batch_size: usize, | ||
schema: Schema, | ||
identity: String, | ||
|
@@ -64,6 +68,7 @@ impl IcebergScanExecutor { | |
snapshot_id: Option<i64>, | ||
table_meta: TableMetadata, | ||
file_scan_tasks: Vec<FileScanTask>, | ||
xxhZs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
eq_delete_file_scan_tasks: Vec<FileScanTask>, | ||
batch_size: usize, | ||
schema: Schema, | ||
identity: String, | ||
|
@@ -73,6 +78,7 @@ impl IcebergScanExecutor { | |
snapshot_id, | ||
table_meta, | ||
file_scan_tasks, | ||
eq_delete_file_scan_tasks, | ||
batch_size, | ||
schema, | ||
identity, | ||
|
@@ -86,33 +92,131 @@ impl IcebergScanExecutor { | |
.load_table_v2_with_metadata(self.table_meta) | ||
.await?; | ||
let data_types = self.schema.data_types(); | ||
let chunk_schema_name_to_id = self | ||
.schema | ||
.names() | ||
.iter() | ||
.enumerate() | ||
.map(|(k, v)| (v.clone(), k)) | ||
.collect::<HashMap<_, _>>(); | ||
|
||
let file_scan_tasks = mem::take(&mut self.file_scan_tasks); | ||
let mut eq_delete_file_scan_tasks_map: HashMap< | ||
xxhZs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
String, | ||
xxhZs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
HashMap<Option<risingwave_common::types::ScalarImpl>, i64>, | ||
xxhZs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
> = HashMap::default(); | ||
let eq_delete_file_scan_tasks = mem::take(&mut self.eq_delete_file_scan_tasks); | ||
|
||
for mut eq_delete_file_scan_task in eq_delete_file_scan_tasks { | ||
eq_delete_file_scan_task.project_field_ids = | ||
eq_delete_file_scan_task.equality_ids.clone(); | ||
xxhZs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let mut sequence_number = eq_delete_file_scan_task.sequence_number; | ||
let reader = table | ||
.reader_builder() | ||
.with_batch_size(self.batch_size) | ||
.build(); | ||
let delete_file_scan_stream = tokio_stream::once(Ok(eq_delete_file_scan_task)); | ||
|
||
let file_scan_stream = { | ||
#[try_stream] | ||
async move { | ||
for file_scan_task in file_scan_tasks { | ||
yield file_scan_task; | ||
let mut delete_record_batch_stream = reader | ||
.read(Box::pin(delete_file_scan_stream)) | ||
.map_err(BatchError::Iceberg)?; | ||
|
||
while let Some(record_batch) = delete_record_batch_stream.next().await { | ||
let record_batch = record_batch.map_err(BatchError::Iceberg)?; | ||
let delete_column_names = record_batch | ||
.schema() | ||
.fields() | ||
.iter() | ||
.map(|field| field.name()) | ||
.cloned() | ||
.collect_vec(); | ||
|
||
let chunk = IcebergArrowConvert.chunk_from_record_batch(&record_batch)?; | ||
for (array, columns_name) in chunk.columns().iter().zip_eq(delete_column_names) { | ||
xxhZs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let each_column_seq_num_map = eq_delete_file_scan_tasks_map | ||
.entry(columns_name) | ||
.or_default(); | ||
for datum in array.get_all_values() { | ||
let entry = each_column_seq_num_map | ||
.entry(datum) | ||
.or_insert(sequence_number); | ||
*entry = *entry.max(&mut sequence_number); | ||
} | ||
} | ||
} | ||
}; | ||
|
||
let reader = table | ||
.reader_builder() | ||
.with_batch_size(self.batch_size) | ||
.build(); | ||
|
||
let record_batch_stream = reader | ||
.read(Box::pin(file_scan_stream)) | ||
.map_err(BatchError::Iceberg)?; | ||
|
||
#[for_await] | ||
for record_batch in record_batch_stream { | ||
let record_batch = record_batch.map_err(BatchError::Iceberg)?; | ||
let chunk = IcebergArrowConvert.chunk_from_record_batch(&record_batch)?; | ||
debug_assert_eq!(chunk.data_types(), data_types); | ||
yield chunk; | ||
} | ||
|
||
let file_scan_tasks = mem::take(&mut self.file_scan_tasks); | ||
|
||
for file_scan_task in file_scan_tasks { | ||
let sequence_number = file_scan_task.sequence_number; | ||
let reader = table | ||
.reader_builder() | ||
.with_batch_size(self.batch_size) | ||
.build(); | ||
let file_scan_stream = tokio_stream::once(Ok(file_scan_task)); | ||
|
||
let mut record_batch_stream = reader | ||
.read(Box::pin(file_scan_stream)) | ||
.map_err(BatchError::Iceberg)?; | ||
|
||
while let Some(record_batch) = record_batch_stream.next().await { | ||
let record_batch = record_batch.map_err(BatchError::Iceberg)?; | ||
let column_names = record_batch | ||
.schema() | ||
.fields() | ||
.iter() | ||
.map(|field| field.name()) | ||
.cloned() | ||
.collect_vec(); | ||
let chunk = IcebergArrowConvert.chunk_from_record_batch(&record_batch)?; | ||
let visibilitys: Vec<_> = chunk | ||
.columns() | ||
.iter() | ||
.zip_eq(column_names.clone()) | ||
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. ditto |
||
.filter_map(|(array, column_map)| { | ||
xxhZs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if let Some(each_column_seq_num_map) = | ||
eq_delete_file_scan_tasks_map.get(&column_map) | ||
{ | ||
let visibility = | ||
Bitmap::from_iter(array.get_all_values().iter().map(|datum| { | ||
if let Some(s) = each_column_seq_num_map.get(datum) | ||
&& s > &sequence_number | ||
{ | ||
false | ||
} else { | ||
true | ||
} | ||
})); | ||
Some(visibility) | ||
} else { | ||
None | ||
} | ||
}) | ||
.collect(); | ||
let (data, va) = chunk.into_parts_v2(); | ||
let visibility = if visibilitys.is_empty() { | ||
va | ||
} else { | ||
visibilitys | ||
.iter() | ||
.skip(1) | ||
.fold(visibilitys[0].clone(), |acc, bitmap| acc.bitor(bitmap)) | ||
xxhZs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
let data = data | ||
.iter() | ||
.zip_eq(column_names) | ||
.filter_map(|(array, columns)| { | ||
chunk_schema_name_to_id | ||
.get(&columns) | ||
.map(|&id| (id, array.clone())) | ||
}) | ||
.sorted_by_key(|a| a.0) | ||
.map(|(k, v)| v) | ||
.collect_vec(); | ||
let chunk = DataChunk::new(data, visibility); | ||
debug_assert_eq!(chunk.data_types(), data_types); | ||
yield chunk; | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -171,6 +275,11 @@ impl BoxedExecutorBuilder for IcebergScanExecutorBuilder { | |
Some(split.snapshot_id), | ||
split.table_meta.deserialize(), | ||
split.files.into_iter().map(|x| x.deserialize()).collect(), | ||
split | ||
.eq_delete_files | ||
.into_iter() | ||
.map(|x| x.deserialize()) | ||
.collect(), | ||
source.context.get_config().developer.chunk_size, | ||
schema, | ||
source.plan_node().get_identity().clone(), | ||
|
This file contains 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 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 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 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 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.
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.
Just curious, do we have a plan to contribute back to upstream to expose delete files?