Skip to content

Commit

Permalink
minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
chenkovsky committed Feb 2, 2025
1 parent 20581ad commit 7126d97
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 42 deletions.
2 changes: 1 addition & 1 deletion datafusion-examples/examples/metadata_columns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use datafusion::physical_plan::{
use datafusion::prelude::*;

use datafusion::catalog::Session;
use datafusion_common::FieldId;
use datafusion::common::FieldId;
use itertools::Itertools;
use tokio::time::timeout;

Expand Down
33 changes: 0 additions & 33 deletions datafusion/core/src/dataframe/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -994,39 +994,6 @@ impl DataFrame {
})
}

/// Rename this DataFrame with a new name.
///
/// # 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/data/example.csv", CsvReadOptions::new()).await?;
/// // Rename the DataFrame to "my_table"
/// let df = df.alias("my_table")?;
/// let expected = vec![
/// "+---+---+---+",
/// "| a | b | c |",
/// "+---+---+---+",
/// "| 1 | 2 | 3 |",
/// "+---+---+---+",
/// ];
/// assert_batches_sorted_eq!(expected, &df.collect().await?);
/// # Ok(())
/// # }
/// ```
pub fn alias(self, alias: &str) -> Result<DataFrame> {
let plan = LogicalPlanBuilder::from(self.plan).alias(alias)?.build()?;
Ok(DataFrame {
session_state: self.session_state,
plan,
})
}

/// Join this `DataFrame` with another `DataFrame` using explicitly specified
/// columns and an optional filter expression.
///
Expand Down
16 changes: 8 additions & 8 deletions datafusion/optimizer/src/optimize_projections/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,10 +597,10 @@ fn rewrite_expr(expr: Expr, input: &Projection) -> Result<Transformed<Expr>> {
let input_expr = match FieldId::from(idx) {
FieldId::Metadata(_) => {
let (relation, field) = input.schema.qualified_field(idx);
Expr::Column(Column {
relation: relation.cloned(),
name: field.name().clone(),
})
Expr::Column(Column::new(
relation.cloned(),
field.name().clone(),
))
}
FieldId::Normal(idx) => input.expr[idx].clone().unalias_nested().data,
};
Expand Down Expand Up @@ -781,10 +781,10 @@ fn rewrite_projection_given_requirements(
.map(|&idx| match FieldId::from(idx) {
FieldId::Metadata(_) => {
let (relation, field) = schema.qualified_field(idx);
Expr::Column(Column {
relation: relation.cloned(),
name: field.name().clone(),
})
Expr::Column(Column::new(
relation.cloned(),
field.name().clone(),
))
}
FieldId::Normal(idx) => expr[idx].clone(),
})
Expand Down

0 comments on commit 7126d97

Please sign in to comment.