alamb commented on code in PR #26934:
URL: https://github.com/apache/datafusion/pull/26934#discussion_r4671498047
##########
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
Review Comment:
the mention of "default SessionContext" is still confusing to me here as
this method is on `DataFrame` and returns ` DataFrame` -- all the talk about
SessionContext is pretty confusing I think
##########
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:
Now I am just confused. I think sending people to SessionContext out of the
DataFrame API is pretty weird.
It seems to me like most of the other apis like read_batch take a `&self`
which is where the session state comes from:
https://github.com/apache/datafusion/blob/e81ab3614c2dd51f194219c4ee01a2a69a529e35/datafusion/core/src/execution/context/mod.rs#L1861-L1873
How about we do the same here?
Aka make something like `DataFrame::from_arrays(&self, arrays: I) ->
reult<Self>`
--
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]