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

fix(udf): fix wrong number of rows #9003

Merged
merged 1 commit into from
Apr 5, 2023
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
16 changes: 11 additions & 5 deletions src/expr/src/expr/expr_udf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,21 @@ impl Expression for UdfExpression {
columns.push(array.as_ref().into());
}
let opts =
arrow_array::RecordBatchOptions::default().with_row_count(Some(input.cardinality()));
arrow_array::RecordBatchOptions::default().with_row_count(Some(input.capacity()));
let input =
arrow_array::RecordBatch::try_new_with_options(self.arg_schema.clone(), columns, &opts)
.expect("failed to build record batch");
let output = self.client.call(&self.identifier, input).await?;
let arrow_array = output
.columns()
.get(0)
.ok_or(risingwave_udf::Error::NoColumn)?;
if output.num_rows() != vis.len() {
bail!(
"UDF returned {} rows, but expected {}",
output.num_rows(),
vis.len(),
);
}
let Some(arrow_array) = output.columns().get(0) else {
bail!("UDF returned no columns");
Copy link
Member

@fuyufjh fuyufjh Apr 5, 2023

Choose a reason for hiding this comment

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

When an expression returns an Error, we will put an array of NULLs there, right?

If so, it may sounds a little bit violent. For example, is it possible to fallback to a row-by-row mode? so that at least we can fill these normal values, dropping the "bad" ones.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess so. In this case it will fallback in an upper-level function:

pub async fn eval_infallible(&self, input: &DataChunk, on_err: impl Fn(ExprError)) -> ArrayRef {

Although it's not efficient to evaluate row-by-row in UDF.

};
let mut array = ArrayImpl::from(arrow_array);
array.set_bitmap(array.null_bitmap() & vis);
Ok(Arc::new(array))
Expand Down
2 changes: 0 additions & 2 deletions src/udf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,6 @@ pub enum Error {
},
#[error("UDF service returned no data")]
NoReturned,
#[error("UDF service returned a batch with no column")]
NoColumn,
}

/// Check if two list of data types match, ignoring field names.
Expand Down