Skip to main content

datafusion_common/
schema_reference.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: See the NOTICE file distributed with this work for additional information regarding copyright ownership
3// SPDX-FileContributor: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements
4
5use std::sync::Arc;
6
7#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
8pub enum SchemaReference {
9    Bare { schema: Arc<str> },
10    Full { schema: Arc<str>, catalog: Arc<str> },
11}
12
13impl SchemaReference {
14    /// Get only the schema name that this references.
15    pub fn schema_name(&self) -> &str {
16        match self {
17            SchemaReference::Bare { schema } => schema,
18            SchemaReference::Full { schema, catalog: _ } => schema,
19        }
20    }
21}
22
23impl std::fmt::Display for SchemaReference {
24    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25        match self {
26            Self::Bare { schema } => write!(f, "{schema}"),
27            Self::Full { schema, catalog } => write!(f, "{catalog}.{schema}"),
28        }
29    }
30}