jayzhan211 commented on code in PR #9595:
URL: https://github.com/apache/arrow-datafusion/pull/9595#discussion_r1528491140
##########
datafusion/common/src/dfschema.rs:
##########
@@ -118,80 +120,115 @@ impl DFSchema {
/// Creates an empty `DFSchema`
pub fn empty() -> Self {
Self {
- fields: vec![],
- metadata: HashMap::new(),
+ inner: Arc::new(Schema::new([])),
+ field_qualifiers: vec![],
functional_dependencies: FunctionalDependencies::empty(),
}
}
- #[deprecated(since = "7.0.0", note = "please use `new_with_metadata`
instead")]
- /// Create a new `DFSchema`
- pub fn new(fields: Vec<DFField>) -> Result<Self> {
- Self::new_with_metadata(fields, HashMap::new())
+ /// Create a new `DFSchema` from an Arrow schema
+ pub fn new_with_metadata(
+ fields: Vec<Field>,
+ metadata: HashMap<String, String>,
+ ) -> Self {
+ let field_count = fields.len();
+ let schema = Arc::new(Schema::new_with_metadata(fields, metadata));
+ Self {
+ inner: schema,
+ field_qualifiers: vec![None; field_count],
+ functional_dependencies: FunctionalDependencies::empty(),
+ }
}
- /// Create a new `DFSchema`
- pub fn new_with_metadata(
- fields: Vec<DFField>,
+ /// Create a `DFSchema` from an Arrow schema and a given qualifier
+ ///
+ /// To create a schema from an Arrow schema without a qualifier, use
+ /// `DFSchema::try_from`.
+ pub fn try_from_qualified_schema<'a>(
+ qualifier: impl Into<TableReference<'a>>,
+ schema: &Schema,
+ ) -> Result<Self> {
+ let qualifier = qualifier.into();
+ let owned_qualifier = qualifier.to_owned_reference();
+ let schema = DFSchema {
+ inner: schema.clone().into(),
+ field_qualifiers: vec![Some(owned_qualifier); schema.fields.len()],
+ functional_dependencies: FunctionalDependencies::empty(),
+ };
+ schema.check_names()?;
+ Ok(schema)
+ }
+
+ // TODO ADD TESTS FOR THIS NEW FUNCTION
+ /// Create a `DFSchema` from an Arrow schema where all the fields have a
given qualifier
+ pub fn from_field_specific_qualified_schema<'a>(
+ qualifiers: Vec<Option<impl Into<TableReference<'a>>>>,
+ schema: &SchemaRef,
+ ) -> Result<Self> {
+ let owned_qualifiers = qualifiers
+ .into_iter()
+ .map(|qualifier| qualifier.map(|q| q.into().to_owned_reference()))
+ .collect();
+ let dfschema = Self {
+ inner: schema.clone(),
+ field_qualifiers: owned_qualifiers,
+ functional_dependencies: FunctionalDependencies::empty(),
+ };
+ dfschema.check_names()?;
+ Ok(dfschema)
+ }
+
+ // TODO Add tests
+ /// Create a `DFSchema` from an Arrow schema where all the fields have a
given qualifier
+ pub fn from_qualified_fields(
Review Comment:
The name implies that we build DFSchema with qualified fields, but it may
not if the qualified name is None. I think it is more to me `new_with_meta`.
And the `new_with_metadata` above is like `from_unqualifed_fields`.
--
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]