Project arbitrary expressions (like SQL SELECT expressions) into a new `DataFrame`. The output `DataFrame` has one column for each element in `expr_list`. # Example ``` # use datafusion::prelude::*; # use datafusion::error::Result; # use datafusion_common::assert_batches_sorted_eq; # #[tokio::main] # async fn main() -> Result<()> { let ctx = SessionContext::new(); let df = ctx .read_csv("tests/d
(
self,
expr_list: impl IntoIterator<Item = impl Into<SelectExpr>>,
)
| 409 | /// # } |
| 410 | /// ``` |
| 411 | pub fn select( |
| 412 | self, |
| 413 | expr_list: impl IntoIterator<Item = impl Into<SelectExpr>>, |
| 414 | ) -> Result<DataFrame> { |
| 415 | let expr_list: Vec<SelectExpr> = |
| 416 | expr_list.into_iter().map(|e| e.into()).collect::<Vec<_>>(); |
| 417 | |
| 418 | let expressions = expr_list.iter().filter_map(|e| match e { |
| 419 | SelectExpr::Expression(expr) => Some(expr), |
| 420 | _ => None, |
| 421 | }); |
| 422 | |
| 423 | let window_func_exprs = find_window_exprs(expressions); |
| 424 | let plan = if window_func_exprs.is_empty() { |
| 425 | self.plan |
| 426 | } else { |
| 427 | LogicalPlanBuilder::window_plan(self.plan, window_func_exprs)? |
| 428 | }; |
| 429 | |
| 430 | let project_plan = LogicalPlanBuilder::from(plan).project(expr_list)?.build()?; |
| 431 | |
| 432 | Ok(DataFrame { |
| 433 | session_state: self.session_state, |
| 434 | plan: project_plan, |
| 435 | projection_requires_validation: false, |
| 436 | }) |
| 437 | } |
| 438 | |
| 439 | /// Returns a new DataFrame containing all columns except the specified columns. |
| 440 | /// |