Skip to content
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: sort record batch of write request #1585

Merged
merged 5 commits into from
Nov 4, 2024

Conversation

baojinri
Copy link
Contributor

@baojinri baojinri commented Nov 3, 2024

Rationale

Support sorted record batch of write request by primary key.

Detailed Changes

  • use datafusion to sort record batch

Test Plan

  • CI
  • Unit tests

@github-actions github-actions bot added the feature New feature or request label Nov 3, 2024
.context("execute sort physical plan")?;

let mut batches = Vec::new();
while let Some(batch) = stream.next().await {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The batch return from next() may not equals input, there are no guarantees for that.

@@ -69,6 +79,7 @@ pub struct CloudObjectStorage {
path: String,
store: ObjectStoreRef,
arrow_schema: SchemaRef,
primary_key_indexs: Vec<usize>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we use num_primary_key: usize, it's more easier to use, and have no heap memory allocation.
0..num_primary_keys columns are primary key.

let batch_plan =
MemoryExec::try_new(&[vec![batch]], schema, None).context("build batch plan")?;
let physical_plan = SortExec::new(physical_sort_exprs, Arc::new(batch_plan));
let mut stream = physical_plan
Copy link
Contributor

@jiacai2050 jiacai2050 Nov 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use collect to fetch results.

Your solution only works for single partition plan.

Copy link
Contributor

@jiacai2050 jiacai2050 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jiacai2050 jiacai2050 merged commit 115b002 into apache:main Nov 4, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants