MCPcopy Create free account
hub / github.com/apache/datafusion / select_columns

Method select_columns

datafusion/core/src/dataframe/mod.rs:330–353  ·  view source on GitHub ↗

Filter the DataFrame by column. Returns a new DataFrame only containing the specified columns. ``` # 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/data/example.csv", CsvReadOptions::new()) .await?; let df = df.select_co

(self, columns: &[&str])

Source from the content-addressed store, hash-verified

328 /// # }
329 /// ```
330 pub fn select_columns(self, columns: &[&str]) -> Result<DataFrame> {
331 let fields = columns
332 .iter()
333 .map(|name| {
334 let fields = self
335 .plan
336 .schema()
337 .qualified_fields_with_unqualified_name(name);
338 if fields.is_empty() {
339 Err(unqualified_field_not_found(name, self.plan.schema()))
340 } else {
341 Ok(fields)
342 }
343 })
344 .collect::<Result<Vec<_>, _>>()?
345 .into_iter()
346 .flatten()
347 .collect::<Vec<_>>();
348 let expr: Vec<Expr> = fields
349 .into_iter()
350 .map(|(qualifier, field)| Expr::Column(Column::from((qualifier, field))))
351 .collect();
352 self.select(expr)
353 }
354 /// Project arbitrary list of expression strings into a new `DataFrame`.
355 /// Method will parse string expressions into logical plan expressions.
356 ///

Callers 15

simple_plan_to_sql_demoFunction · 0.80
read_parquetFunction · 0.80
read_memoryFunction · 0.80
query_dataframeFunction · 0.80
query_make_dateFunction · 0.80
query_to_dateFunction · 0.80
query_to_timestampFunction · 0.80
search_accountsFunction · 0.80

Calls 11

flattenMethod · 0.80
collectMethod · 0.80
ColumnClass · 0.50
into_iterMethod · 0.45
mapMethod · 0.45
iterMethod · 0.45
schemaMethod · 0.45
is_emptyMethod · 0.45
selectMethod · 0.45