Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 23 additions & 24 deletions datafusion/common/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ use std::sync::Arc;
/// /// Field 3 doc
/// field3: Option<usize>, default = None
/// }
///}
/// }
/// ```
///
/// Will generate
Expand Down Expand Up @@ -1326,36 +1326,35 @@ impl ConfigOptions {
/// # Example
/// ```
/// use datafusion_common::{
/// config::ConfigExtension, extensions_options,
/// config::ConfigOptions,
/// config::ConfigExtension, config::ConfigOptions, extensions_options,
/// };
/// // Define a new configuration struct using the `extensions_options` macro
/// extensions_options! {
/// /// My own config options.
/// pub struct MyConfig {
/// /// Should "foo" be replaced by "bar"?
/// pub foo_to_bar: bool, default = true
/// // Define a new configuration struct using the `extensions_options` macro
/// extensions_options! {
/// /// My own config options.
/// pub struct MyConfig {
/// /// Should "foo" be replaced by "bar"?
/// pub foo_to_bar: bool, default = true
///
/// /// How many "baz" should be created?
/// pub baz_count: usize, default = 1337
/// }
/// }
/// /// How many "baz" should be created?
/// pub baz_count: usize, default = 1337
/// }
/// }
///
/// impl ConfigExtension for MyConfig {
/// impl ConfigExtension for MyConfig {
/// const PREFIX: &'static str = "my_config";
/// }
/// }
///
/// // set up config struct and register extension
/// let mut config = ConfigOptions::default();
/// config.extensions.insert(MyConfig::default());
/// // set up config struct and register extension
/// let mut config = ConfigOptions::default();
/// config.extensions.insert(MyConfig::default());
///
/// // overwrite config default
/// config.set("my_config.baz_count", "42").unwrap();
/// // overwrite config default
/// config.set("my_config.baz_count", "42").unwrap();
///
/// // check config state
/// let my_config = config.extensions.get::<MyConfig>().unwrap();
/// assert!(my_config.foo_to_bar,);
/// assert_eq!(my_config.baz_count, 42,);
/// // check config state
/// let my_config = config.extensions.get::<MyConfig>().unwrap();
/// assert!(my_config.foo_to_bar,);
/// assert_eq!(my_config.baz_count, 42,);
/// ```
///
/// # Note:
Expand Down
2 changes: 0 additions & 2 deletions datafusion/common/src/datatype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ pub trait FieldExt {
/// assert_eq!(list_field.data_type(), &DataType::List(Arc::new(
/// Field::new("item", DataType::Int32, true)
/// )));
///
fn into_list(self) -> Self;

/// Return a new Field representing this Field as the item type of a
Expand All @@ -107,7 +106,6 @@ pub trait FieldExt {
/// Field::new("item", DataType::Int32, true)),
/// 3
/// ));
///
fn into_fixed_size_list(self, list_size: i32) -> Self;

/// Update the field to have the default list field name ("item")
Expand Down
40 changes: 21 additions & 19 deletions datafusion/common/src/dfschema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,10 @@ pub type DFSchemaRef = Arc<DFSchema>;
/// an Arrow schema.
///
/// ```rust
/// use datafusion_common::{DFSchema, Column};
/// use arrow::datatypes::{DataType, Field, Schema};
/// use datafusion_common::{Column, DFSchema};
///
/// let arrow_schema = Schema::new(vec![
/// Field::new("c1", DataType::Int32, false),
/// ]);
/// let arrow_schema = Schema::new(vec![Field::new("c1", DataType::Int32, false)]);
///
/// let df_schema = DFSchema::try_from_qualified_schema("t1", &arrow_schema).unwrap();
/// let column = Column::from_qualified_name("t1.c1");
Expand All @@ -77,12 +75,10 @@ pub type DFSchemaRef = Arc<DFSchema>;
/// Create an unqualified schema using TryFrom:
///
/// ```rust
/// use datafusion_common::{DFSchema, Column};
/// use arrow::datatypes::{DataType, Field, Schema};
/// use datafusion_common::{Column, DFSchema};
///
/// let arrow_schema = Schema::new(vec![
/// Field::new("c1", DataType::Int32, false),
/// ]);
/// let arrow_schema = Schema::new(vec![Field::new("c1", DataType::Int32, false)]);
///
/// let df_schema = DFSchema::try_from(arrow_schema).unwrap();
/// let column = Column::new_unqualified("c1");
Expand All @@ -94,13 +90,15 @@ pub type DFSchemaRef = Arc<DFSchema>;
/// Use the `Into` trait to convert `DFSchema` into an Arrow schema:
///
/// ```rust
/// use arrow::datatypes::{Field, Schema};
/// use datafusion_common::DFSchema;
/// use arrow::datatypes::{Schema, Field};
/// use std::collections::HashMap;
///
/// let df_schema = DFSchema::from_unqualified_fields(vec![
/// Field::new("c1", arrow::datatypes::DataType::Int32, false),
/// ].into(),HashMap::new()).unwrap();
/// let df_schema = DFSchema::from_unqualified_fields(
/// vec![Field::new("c1", arrow::datatypes::DataType::Int32, false)].into(),
/// HashMap::new(),
/// )
/// .unwrap();
/// let schema: &Schema = df_schema.as_arrow();
/// assert_eq!(schema.fields().len(), 1);
/// ```
Expand Down Expand Up @@ -884,22 +882,26 @@ impl DFSchema {
/// # Example
///
/// ```
/// use datafusion_common::DFSchema;
/// use arrow::datatypes::{DataType, Field, Schema};
/// use datafusion_common::DFSchema;
/// use std::collections::HashMap;
///
/// let schema = DFSchema::from_unqualified_fields(
/// vec![
/// Field::new("id", DataType::Int32, false),
/// Field::new("name", DataType::Utf8, true),
/// ].into(),
/// HashMap::new()
/// ).unwrap();
/// ]
/// .into(),
/// HashMap::new(),
/// )
/// .unwrap();
///
/// assert_eq!(schema.tree_string().to_string(),
/// r#"root
/// assert_eq!(
/// schema.tree_string().to_string(),
/// r#"root
/// |-- id: int32 (nullable = false)
/// |-- name: utf8 (nullable = true)"#);
/// |-- name: utf8 (nullable = true)"#
/// );
/// ```
pub fn tree_string(&self) -> impl Display + '_ {
let mut result = String::from("root\n");
Expand Down
7 changes: 5 additions & 2 deletions datafusion/common/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ use crate::Span;
/// ```rust
/// # use datafusion_common::{Location, Span, Diagnostic};
/// let span = Some(Span {
/// start: Location{ line: 2, column: 1 },
/// end: Location{ line: 4, column: 15 }
/// start: Location { line: 2, column: 1 },
/// end: Location {
/// line: 4,
/// column: 15,
/// },
/// });
/// let diagnostic = Diagnostic::new_error("Something went wrong", span)
/// .with_help("Have you tried turning it on and off again?", None);
Expand Down
17 changes: 13 additions & 4 deletions datafusion/common/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,10 @@ impl DataFusionError {
/// let mut builder = DataFusionError::builder();
/// builder.add_error(DataFusionError::Internal("foo".to_owned()));
/// // ok_or returns the value if no errors have been added
/// assert_contains!(builder.error_or(42).unwrap_err().to_string(), "Internal error: foo");
/// assert_contains!(
/// builder.error_or(42).unwrap_err().to_string(),
/// "Internal error: foo"
/// );
/// ```
#[derive(Debug, Default)]
pub struct DataFusionErrorBuilder(Vec<DataFusionError>);
Expand All @@ -702,7 +705,10 @@ impl DataFusionErrorBuilder {
/// # use datafusion_common::{assert_contains, DataFusionError};
/// let mut builder = DataFusionError::builder();
/// builder.add_error(DataFusionError::Internal("foo".to_owned()));
/// assert_contains!(builder.error_or(42).unwrap_err().to_string(), "Internal error: foo");
/// assert_contains!(
/// builder.error_or(42).unwrap_err().to_string(),
/// "Internal error: foo"
/// );
/// ```
pub fn add_error(&mut self, error: DataFusionError) {
self.0.push(error);
Expand All @@ -714,8 +720,11 @@ impl DataFusionErrorBuilder {
/// ```
/// # use datafusion_common::{assert_contains, DataFusionError};
/// let builder = DataFusionError::builder()
/// .with_error(DataFusionError::Internal("foo".to_owned()));
/// assert_contains!(builder.error_or(42).unwrap_err().to_string(), "Internal error: foo");
/// .with_error(DataFusionError::Internal("foo".to_owned()));
/// assert_contains!(
/// builder.error_or(42).unwrap_err().to_string(),
/// "Internal error: foo"
/// );
/// ```
pub fn with_error(mut self, error: DataFusionError) -> Self {
self.0.push(error);
Expand Down
1 change: 0 additions & 1 deletion datafusion/common/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ pub fn format_type_and_metadata(
/// // Add any metadata from `FieldMetadata` to `Field`
/// let updated_field = metadata.add_to_field(field);
/// ```
///
#[derive(Clone, PartialEq, Eq, PartialOrd, Hash, Debug)]
pub struct FieldMetadata {
/// The inner metadata of a literal expression, which is a map of string
Expand Down
9 changes: 6 additions & 3 deletions datafusion/common/src/nested_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,19 @@ fn cast_struct_column(
/// temporal values are formatted when cast to strings.
///
/// ```
/// use std::sync::Arc;
/// use arrow::array::{Int64Array, ArrayRef};
/// use arrow::array::{ArrayRef, Int64Array};
/// use arrow::compute::CastOptions;
/// use arrow::datatypes::{DataType, Field};
/// use datafusion_common::nested_struct::cast_column;
/// use std::sync::Arc;
///
/// let source: ArrayRef = Arc::new(Int64Array::from(vec![1, i64::MAX]));
/// let target = Field::new("ints", DataType::Int32, true);
/// // Permit lossy conversions by producing NULL on overflow instead of erroring
/// let options = CastOptions { safe: true, ..Default::default() };
/// let options = CastOptions {
/// safe: true,
/// ..Default::default()
/// };
/// let result = cast_column(&source, &target, &options).unwrap();
/// assert!(result.is_null(1));
/// ```
Expand Down
Loading