Project a record batch according to this projector's expressions. # Errors This function returns an error if any expression evaluation fails or if the output schema of the resulting record batch does not match the pre-computed output schema of the projector.
(&self, batch: &RecordBatch)
| 812 | /// or if the output schema of the resulting record batch does not match |
| 813 | /// the pre-computed output schema of the projector. |
| 814 | pub fn project_batch(&self, batch: &RecordBatch) -> Result<RecordBatch> { |
| 815 | let arrays = evaluate_expressions_to_arrays_with_metrics( |
| 816 | self.projection.exprs.iter().map(|p| &p.expr), |
| 817 | batch, |
| 818 | self.expression_metrics.as_ref(), |
| 819 | )?; |
| 820 | |
| 821 | if arrays.is_empty() { |
| 822 | let options = |
| 823 | RecordBatchOptions::new().with_row_count(Some(batch.num_rows())); |
| 824 | RecordBatch::try_new_with_options( |
| 825 | Arc::clone(&self.output_schema), |
| 826 | arrays, |
| 827 | &options, |
| 828 | ) |
| 829 | .map_err(Into::into) |
| 830 | } else { |
| 831 | RecordBatch::try_new(Arc::clone(&self.output_schema), arrays) |
| 832 | .map_err(Into::into) |
| 833 | } |
| 834 | } |
| 835 | |
| 836 | pub fn output_schema(&self) -> &SchemaRef { |
| 837 | &self.output_schema |