substrait/parse/text/simple_extensions/mod.rs
1// SPDX-License-Identifier: Apache-2.0
2
3//! Rustic types for validating and working with Substrait simple extensions.
4//!
5//! The raw YAML structs live in [`crate::text::simple_extensions`]. This
6//! module parses those values into the typed representations used by this
7//! crate:
8//! * [`ExtensionFile`] – a fully validated extension document (URN plus its
9//! definitions).
10//! * [`SimpleExtensions`] – the validated objects declared by a single
11//! extension file.
12//! * [`CustomType`] / [`ConcreteType`] – type definitions and resolved type
13//! structures used when checking function signatures.
14//! * [`Registry`] – a reusable lookup structure that stores validated extension
15//! files and exposes typed access to their contents.
16
17use thiserror::Error;
18
19pub mod argument;
20mod extensions;
21mod file;
22mod registry;
23mod type_ast;
24mod types;
25
26pub use extensions::SimpleExtensions;
27pub use file::ExtensionFile;
28pub use registry::Registry;
29pub use type_ast::TypeExpr;
30pub use types::{ConcreteType, CustomType, ExtensionTypeError};
31
32use crate::urn::Urn;
33
34/// Errors for converting from YAML to [SimpleExtensions].
35#[derive(Debug, Error)]
36pub enum SimpleExtensionsError {
37 /// Duplicate URNs in the registry
38 #[error("duplicate URNs in the registry: {0}")]
39 DuplicateUrn(Urn),
40 /// Extension type error
41 #[error("Extension type error: {0}")]
42 ExtensionTypeError(#[from] ExtensionTypeError),
43 /// Failed to parse SimpleExtensions YAML
44 #[error("YAML parse error: {0}")]
45 YamlParse(#[from] serde_yaml::Error),
46 /// I/O error while reading extension content
47 #[error("io error: {0}")]
48 Io(#[from] std::io::Error),
49 /// Invalid URN provided
50 #[error("invalid urn")]
51 InvalidUrn(#[from] crate::urn::InvalidUrn),
52 /// Unresolved type reference in structure field
53 #[error("Type '{type_name}' referenced in structure not found")]
54 UnresolvedTypeReference {
55 /// The type name that could not be resolved
56 type_name: String,
57 // TODO: the location in the file where this came from would be nice
58 },
59 /// Duplicate type definition within the same extension
60 #[error("duplicate type definition for `{name}`")]
61 DuplicateTypeName {
62 /// The repeated type name
63 name: String,
64 },
65}