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`] / [`Type`] – type definitions and type expressions.
13//! * [`ScalarFunctionVariant`] – parsed scalar function implementations, one per signature.
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 boolean_expr;
21mod extensions;
22mod file;
23mod registry;
24mod return_type;
25mod scalar_functions;
26mod type_parser;
27mod types;
28
29pub use boolean_expr::{BooleanExpr, ComparisonOp};
30pub use extensions::SimpleExtensions;
31pub use file::ExtensionFile;
32pub use registry::Registry;
33pub use return_type::{Assignment, AssignmentValue, ReturnType};
34pub use scalar_functions::{NullabilityHandling, Options, ScalarFunctionVariant, VariadicBehavior};
35pub use type_parser::TypeParseError;
36pub use types::{
37 BinaryOp, CustomType, ExtensionTypeError, IntegerParameter, NumericFunction, Type, TypeKind,
38 TypeParameter,
39};
40
41use crate::urn::Urn;
42
43/// Errors for converting from YAML to [SimpleExtensions].
44#[derive(Debug, Error)]
45pub enum SimpleExtensionsError {
46 /// Duplicate URNs in the registry
47 #[error("duplicate URNs in the registry: {0}")]
48 DuplicateUrn(Urn),
49 /// Extension type error
50 #[error("Extension type error: {0}")]
51 ExtensionTypeError(#[from] ExtensionTypeError),
52 /// Scalar function error
53 #[error("Scalar function error: {0}")]
54 ScalarFunctionError(#[from] scalar_functions::ScalarFunctionError),
55 /// Failed to parse SimpleExtensions YAML
56 #[error("YAML parse error: {0}")]
57 YamlParse(#[from] serde_yaml::Error),
58 /// I/O error while reading extension content
59 #[error("io error: {0}")]
60 Io(#[from] std::io::Error),
61 /// Invalid URN provided
62 #[error("invalid urn")]
63 InvalidUrn(#[from] crate::urn::InvalidUrn),
64 /// Unresolved type reference in structure field
65 #[error("Type '{type_name}' referenced in structure not found")]
66 UnresolvedTypeReference {
67 /// The type name that could not be resolved
68 type_name: String,
69 // TODO: the location in the file where this came from would be nice
70 },
71 /// Duplicate type definition within the same extension
72 #[error("duplicate type definition for `{name}`")]
73 DuplicateTypeName {
74 /// The repeated type name
75 name: String,
76 },
77 /// Two function implementations in the same extension share a signature
78 #[error("duplicate function signature `{signature}`")]
79 DuplicateFunctionSignature {
80 /// The repeated function signature, such as `add:i32_i32`
81 signature: String,
82 },
83}