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: Implement batch processing for stateless processors #2319

Merged
merged 1 commit into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions dozer-sql/src/projection/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl ProjectionProcessor {
Ok(Operation::Delete { old: output_record })
}

fn insert(&mut self, record: &Record) -> Result<Operation, PipelineError> {
fn insert(&mut self, record: &Record) -> Result<Record, PipelineError> {
let mut results = vec![];

for expr in &mut self.expressions {
Expand All @@ -57,7 +57,7 @@ impl ProjectionProcessor {

let mut output_record = Record::new(results);
output_record.set_lifetime(record.lifetime.to_owned());
Ok(Operation::Insert { new: output_record })
Ok(output_record)
}

fn update(&mut self, old: &Record, new: &Record) -> Result<Operation, PipelineError> {
Expand Down Expand Up @@ -90,18 +90,16 @@ impl Processor for ProjectionProcessor {
) -> Result<(), BoxedError> {
let output_op = match op {
Operation::Delete { ref old } => self.delete(old)?,
Operation::Insert { ref new } => self.insert(new)?,
Operation::Insert { ref new } => Operation::Insert {
new: self.insert(new)?,
},
Operation::Update { ref old, ref new } => self.update(old, new)?,
Operation::BatchInsert { new } => {
for record in new {
self.process(
_from_port,
_record_store,
Operation::Insert { new: record },
fw,
)?;
}
return Ok(());
let records = new
.iter()
.map(|record| self.insert(record))
.collect::<Result<Vec<_>, _>>()?;
Operation::BatchInsert { new: records }
}
};
fw.send(output_op, DEFAULT_PORT_HANDLE);
Expand Down
33 changes: 19 additions & 14 deletions dozer-sql/src/selection/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use dozer_core::DEFAULT_PORT_HANDLE;
use dozer_recordstore::ProcessorRecordStore;
use dozer_sql_expression::execution::Expression;
use dozer_types::errors::internal::BoxedError;
use dozer_types::types::{Field, Operation, Schema};
use dozer_types::types::{Field, Operation, Record, Schema};

use crate::errors::PipelineError;

Expand All @@ -33,6 +33,10 @@ impl SelectionProcessor {
expression,
})
}

fn filter(&mut self, record: &Record) -> Result<bool, PipelineError> {
Ok(self.expression.evaluate(record, &self.input_schema)? == Field::Boolean(true))
}
}

impl Processor for SelectionProcessor {
Expand All @@ -49,20 +53,18 @@ impl Processor for SelectionProcessor {
) -> Result<(), BoxedError> {
match op {
Operation::Delete { ref old } => {
if self.expression.evaluate(old, &self.input_schema)? == Field::Boolean(true) {
if self.filter(old)? {
fw.send(op, DEFAULT_PORT_HANDLE);
}
}
Operation::Insert { ref new } => {
if self.expression.evaluate(new, &self.input_schema)? == Field::Boolean(true) {
if self.filter(new)? {
fw.send(op, DEFAULT_PORT_HANDLE);
}
}
Operation::Update { old, new } => {
let old_fulfilled =
self.expression.evaluate(&old, &self.input_schema)? == Field::Boolean(true);
let new_fulfilled =
self.expression.evaluate(&new, &self.input_schema)? == Field::Boolean(true);
let old_fulfilled = self.filter(&old)?;
let new_fulfilled = self.filter(&new)?;
match (old_fulfilled, new_fulfilled) {
(true, true) => {
// both records fulfills the WHERE condition, forward the operation
Expand All @@ -82,13 +84,16 @@ impl Processor for SelectionProcessor {
}
}
Operation::BatchInsert { new } => {
for record in new {
self.process(
_from_port,
_record_store,
Operation::Insert { new: record },
fw,
)?;
let records = new
.into_iter()
.filter_map(|record| {
self.filter(&record)
.map(|fulfilled| if fulfilled { Some(record) } else { None })
.transpose()
})
.collect::<Result<Vec<_>, _>>()?;
if !records.is_empty() {
fw.send(Operation::BatchInsert { new: records }, DEFAULT_PORT_HANDLE);
}
}
}
Expand Down
13 changes: 7 additions & 6 deletions dozer-sql/src/table_operator/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,15 @@ impl Processor for TableOperatorProcessor {
}
}
Operation::BatchInsert { new } => {
let mut records = vec![];
for record in new {
self.process(
_from_port,
record_store,
Operation::Insert { new: record },
fw,
)?;
records.extend(
self.operator
.execute(record_store, &record, &self.input_schema)
.map_err(PipelineError::TableOperatorError)?,
);
}
fw.send(Operation::BatchInsert { new: records }, DEFAULT_PORT_HANDLE);
}
}
Ok(())
Expand Down
13 changes: 7 additions & 6 deletions dozer-sql/src/window/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,15 @@ impl Processor for WindowProcessor {
)?;
}
Operation::BatchInsert { new } => {
let mut records = vec![];
for record in new {
self.process(
_from_port,
record_store,
Operation::Insert { new: record },
fw,
)?;
records.extend(
self.window
.execute(record_store, record)
.map_err(PipelineError::WindowError)?,
);
}
fw.send(Operation::BatchInsert { new: records }, DEFAULT_PORT_HANDLE);
}
}
Ok(())
Expand Down
Loading