cj-zhukov commented on code in PR #26934:
URL: https://github.com/apache/datafusion/pull/26934#discussion_r4677714100
##########
datafusion/core/src/dataframe/mod.rs:
##########
@@ -2853,54 +2853,51 @@ impl DataFrame {
.collect()
}
- /// Create a DataFrame from named Arrow arrays.
+ /// Create a `DataFrame` from named Arrow arrays in a new, default
+ /// [`SessionContext`]. Field nullability is derived from the arrays, see
+ /// [`SessionContext::read_columns`].
///
- /// # Example
+ /// # Deprecated
+ ///
+ /// Use [`SessionContext::read_columns`] instead. This method creates its
+ /// own `SessionContext`, so the returned `DataFrame` does not see the
+ /// functions, tables, configuration or runtime of any session the caller
+ /// already has. Calling `read_columns` on an existing context binds the
+ /// `DataFrame` to that session:
///
/// ```
/// use std::sync::Arc;
- /// use arrow::array::{ArrayRef, Int32Array, StringArray};
- /// use datafusion::prelude::DataFrame;
+ /// use arrow::array::{ArrayRef, Int32Array};
+ /// use datafusion::prelude::*;
/// # use datafusion::error::Result;
- /// # use datafusion_common::assert_batches_sorted_eq;
- /// # #[tokio::main]
- /// # async fn main() -> Result<()> {
+ /// # fn main() -> Result<()> {
/// let id: ArrayRef = Arc::new(Int32Array::from(vec![1, 2, 3]));
- /// let name: ArrayRef = Arc::new(StringArray::from(vec!["foo", "bar",
"baz"]));
- /// let df = DataFrame::from_columns([("id", id), ("name", name)])?;
- /// let expected = vec![
- /// "+----+------+",
- /// "| id | name |",
- /// "+----+------+",
- /// "| 1 | foo |",
- /// "| 2 | bar |",
- /// "| 3 | baz |",
- /// "+----+------+",
- /// ];
- /// # assert_batches_sorted_eq!(expected, &df.collect().await?);
+ /// let ctx = SessionContext::new();
+ /// // before: DataFrame::from_columns([("id", id)])?
+ /// let df = ctx.read_columns([("id", id)])?;
/// # Ok(())
/// # }
/// ```
+ ///
+ /// To build a `DataFrame` from literal values without a context, see the
+ /// [`dataframe!`] macro.
+ ///
+ /// [`dataframe!`]: macro@crate::dataframe
+ #[deprecated(since = "56.0.0", note = "use `SessionContext::read_columns`
instead")]
pub fn from_columns<'a, I>(columns: I) -> Result<Self>
Review Comment:
Thanks @alamb, I hadn't considered this shape when I started the PR, and I
appreciate you taking the time to think it through. Taking the session from
`&self` keeps the goal of the PR - UDFs, tables and config from the caller's
session stay available - since `self.session_state` is the same state
`read_batch` uses. I'll rework the PR that way.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]