Skip to content

Commit

Permalink
Arc<String> for TableReference
Browse files Browse the repository at this point in the history
  • Loading branch information
comphead committed Apr 2, 2024
1 parent 1e99002 commit 2086ca2
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 174 deletions.
8 changes: 4 additions & 4 deletions datafusion/common/src/dfschema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ impl DFSchema {
///
/// 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>>,
pub fn try_from_qualified_schema(
qualifier: impl Into<TableReference>,
schema: &Schema,
) -> Result<Self> {
let qualifier = qualifier.into();
Expand Down Expand Up @@ -815,8 +815,8 @@ impl DFField {
}

/// Create a qualified field from an existing Arrow field
pub fn from_qualified<'a>(
qualifier: impl Into<TableReference<'a>>,
pub fn from_qualified(
qualifier: impl Into<TableReference>,
field: impl Into<FieldRef>,
) -> Self {
Self {
Expand Down
35 changes: 14 additions & 21 deletions datafusion/common/src/schema_reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,49 +15,42 @@
// specific language governing permissions and limitations
// under the License.

use std::{marker::PhantomData, sync::Arc};
use std::sync::Arc;

#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum SchemaReference<'a> {
Bare { schema: Arc<str> },
Full { schema: Arc<str>, catalog: Arc<str> },
X { phantom: PhantomData<&'a bool> },
pub enum SchemaReference {
Bare {
schema: Arc<String>,
},
Full {
schema: Arc<String>,
catalog: Arc<String>,
},
}

impl SchemaReference<'_> {
impl SchemaReference {
/// Get only the schema name that this references.
pub fn schema_name(&self) -> &str {
match self {
SchemaReference::Bare { schema } => schema,
SchemaReference::Full { schema, catalog: _ } => schema,
_ => todo!(),
}
}
}

pub type OwnedSchemaReference = SchemaReference<'static>;
pub type OwnedSchemaReference = SchemaReference;

impl std::fmt::Display for SchemaReference<'_> {
impl std::fmt::Display for SchemaReference {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Bare { schema } => write!(f, "{schema}"),
Self::Full { schema, catalog } => write!(f, "{catalog}.{schema}"),
_ => todo!(),
}
}
}

impl<'a> From<&'a OwnedSchemaReference> for SchemaReference<'a> {
impl<'a> From<&'a OwnedSchemaReference> for SchemaReference {
fn from(value: &'a OwnedSchemaReference) -> Self {
match value {
SchemaReference::Bare { schema } => SchemaReference::Bare {
schema: schema.clone(),
},
SchemaReference::Full { schema, catalog } => SchemaReference::Full {
schema: schema.clone(),
catalog: catalog.clone(),
},
_ => todo!(),
}
value.clone()
}
}
Loading

0 comments on commit 2086ca2

Please sign in to comment.