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//! * [`ScalarFunction`] – validated scalar function definitions with resolved
15//! signatures.
16//! * [`Registry`] – a reusable lookup structure that stores validated extension
17//! files and exposes typed access to their contents.
18
19use thiserror::Error;
20
21pub mod argument;
22mod extensions;
23mod file;
24mod registry;
25mod scalar_functions;
26mod type_ast;
27mod types;
28
29pub use extensions::SimpleExtensions;
30pub use file::ExtensionFile;
31pub use registry::Registry;
32pub use scalar_functions::{
33 Impl as ScalarFunctionImpl, NullabilityHandling, Options, ScalarFunction, VariadicBehavior,
34};
35pub use type_ast::TypeExpr;
36pub use types::{ConcreteType, CustomType, ExtensionTypeError};
37
38use crate::urn::Urn;
39
40/// Errors for converting from YAML to [SimpleExtensions].
41#[derive(Debug, Error)]
42pub enum SimpleExtensionsError {
43 /// Duplicate URNs in the registry
44 #[error("duplicate URNs in the registry: {0}")]
45 DuplicateUrn(Urn),
46 /// Extension type error
47 #[error("Extension type error: {0}")]
48 ExtensionTypeError(#[from] ExtensionTypeError),
49 /// Scalar function error
50 #[error("Scalar function error: {0}")]
51 ScalarFunctionError(#[from] scalar_functions::ScalarFunctionError),
52 /// Failed to parse SimpleExtensions YAML
53 #[error("YAML parse error: {0}")]
54 YamlParse(#[from] serde_yaml::Error),
55 /// I/O error while reading extension content
56 #[error("io error: {0}")]
57 Io(#[from] std::io::Error),
58 /// Invalid URN provided
59 #[error("invalid urn")]
60 InvalidUrn(#[from] crate::urn::InvalidUrn),
61 /// Unresolved type reference in structure field
62 #[error("Type '{type_name}' referenced in structure not found")]
63 UnresolvedTypeReference {
64 /// The type name that could not be resolved
65 type_name: String,
66 // TODO: the location in the file where this came from would be nice
67 },
68 /// Duplicate type definition within the same extension
69 #[error("duplicate type definition for `{name}`")]
70 DuplicateTypeName {
71 /// The repeated type name
72 name: String,
73 },
74}