Skip to content

Commit 95270ab

Browse files
committed
doc: update extensions types and links
1 parent ca1e133 commit 95270ab

File tree

6 files changed

+73
-47
lines changed

6 files changed

+73
-47
lines changed

src/parse/text/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
// SPDX-License-Identifier: Apache-2.0
22

3-
//! Parsing of [text](crate::text) types.
3+
//! Utilities for working with Substrait *text* objects.
4+
//!
5+
//! The generated [`crate::text`] module exposes the raw YAML-derived structs
6+
//! (e.g. [`crate::text::simple_extensions::SimpleExtensions`]). This module
7+
//! provides parsing helpers that validate those raw values and offer
8+
//! higher-level wrappers for validation, lookups, and combining into protobuf
9+
//! objects.
410
511
pub mod simple_extensions;

src/parse/text/simple_extensions/argument.rs

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// SPDX-License-Identifier: Apache-2.0
22

3-
//! Parsing of [simple_extensions::ArgumentsItem].
3+
//! Parsing of type arguments: [`simple_extensions::ArgumentsItem`].
44
55
use std::{collections::HashSet, ops::Deref};
66

@@ -11,21 +11,24 @@ use crate::{
1111
text::simple_extensions,
1212
};
1313

14-
/// A parsed [simple_extensions::ArgumentsItem].
14+
/// A parsed [`simple_extensions::ArgumentsItem`].
1515
#[derive(Clone, Debug)]
1616
pub enum ArgumentsItem {
17-
/// Arguments that support a fixed set of declared values as constant arguments.
17+
/// Arguments that support a fixed set of declared values as constant
18+
/// arguments.
1819
EnumArgument(EnumerationArg),
1920

2021
/// Arguments that refer to a data value.
2122
ValueArgument(ValueArg),
2223

23-
/// Arguments that are used only to inform the evaluation and/or type derivation of the function.
24+
/// Arguments that are used only to inform the evaluation and/or type
25+
/// derivation of the function.
2426
TypeArgument(TypeArg),
2527
}
2628

2729
impl ArgumentsItem {
28-
/// Parses an `Option<String>` field, rejecting it if an empty string is provided.
30+
/// Parses an `Option<String>` field, rejecting it if an empty string is
31+
/// provided.
2932
#[inline]
3033
fn parse_optional_string(
3134
name: &str,
@@ -75,7 +78,7 @@ impl From<ArgumentsItem> for simple_extensions::ArgumentsItem {
7578
}
7679
}
7780

78-
/// Parse errors for [simple_extensions::ArgumentsItem].
81+
/// Parse errors for [`simple_extensions::ArgumentsItem`].
7982
#[derive(Debug, Error, PartialEq)]
8083
pub enum ArgumentsItemError {
8184
/// Invalid enumeration options.
@@ -103,21 +106,21 @@ pub struct EnumerationArg {
103106
impl EnumerationArg {
104107
/// Returns the name of this argument.
105108
///
106-
/// See [simple_extensions::EnumerationArg::name].
109+
/// See [`simple_extensions::EnumerationArg::name`].
107110
pub fn name(&self) -> Option<&String> {
108111
self.name.as_ref()
109112
}
110113

111114
/// Returns the description of this argument.
112115
///
113-
/// See [simple_extensions::EnumerationArg::description].
116+
/// See [`simple_extensions::EnumerationArg::description`].
114117
pub fn description(&self) -> Option<&String> {
115118
self.description.as_ref()
116119
}
117120

118121
/// Returns the options of this argument.
119122
///
120-
/// See [simple_extensions::EnumerationArg::options].
123+
/// See [`simple_extensions::EnumerationArg::options`].
121124
pub fn options(&self) -> &EnumOptions {
122125
&self.options
123126
}
@@ -210,7 +213,7 @@ impl From<EnumOptions> for simple_extensions::EnumOptions {
210213
}
211214
}
212215

213-
/// Parse errors for [simple_extensions::EnumOptions].
216+
/// Parse errors for [`simple_extensions::EnumOptions`].
214217
#[derive(Debug, Error, PartialEq)]
215218
pub enum EnumOptionsError {
216219
/// Empty list.
@@ -237,35 +240,35 @@ pub struct ValueArg {
237240

238241
/// A fully defined type or a type expression.
239242
///
240-
/// TODO: parse this to a typed representation (likely using the `TypeExpr` parser)
241-
/// so the caller does not have to interpret the raw string.
243+
/// TODO: parse this to a typed representation (likely using the `TypeExpr`
244+
/// parser) so the caller does not have to interpret the raw string.
242245
value: simple_extensions::Type,
243246

244-
/// Whether this argument is required to be a constant for invocation.
245-
/// For example, in some system a regular expression pattern would only be accepted as a literal
246-
/// and not a column value reference.
247+
/// Whether this argument is required to be a constant for invocation. For
248+
/// example, in some system a regular expression pattern would only be
249+
/// accepted as a literal and not a column value reference.
247250
constant: Option<bool>,
248251
}
249252

250253
impl ValueArg {
251254
/// Returns the name of this argument.
252255
///
253-
/// See [simple_extensions::ValueArg::name].
256+
/// See [`simple_extensions::ValueArg::name`].
254257
pub fn name(&self) -> Option<&String> {
255258
self.name.as_ref()
256259
}
257260

258261
/// Returns the description of this argument.
259262
///
260-
/// See [simple_extensions::ValueArg::description].
263+
/// See [`simple_extensions::ValueArg::description`].
261264
pub fn description(&self) -> Option<&String> {
262265
self.description.as_ref()
263266
}
264267

265268
/// Returns the constant of this argument.
266269
/// Defaults to `false` if the underlying value is `None`.
267270
///
268-
/// See [simple_extensions::ValueArg::constant].
271+
/// See [`simple_extensions::ValueArg::constant`].
269272
pub fn constant(&self) -> bool {
270273
self.constant.unwrap_or(false)
271274
}
@@ -309,33 +312,33 @@ impl From<ValueArg> for ArgumentsItem {
309312
}
310313
}
311314

312-
/// Arguments that are used only to inform the evaluation and/or type derivation of the function.
315+
/// A type argument to a parameterized type, e.g. the `T` in `List<T>`.
313316
#[derive(Clone, Debug, PartialEq)]
314317
pub struct TypeArg {
315-
/// A human-readable name for this argument to help clarify use.
318+
/// A human-readable name for this argument to clarify use.
316319
name: Option<String>,
317320

318321
/// Additional description for this argument.
319322
description: Option<String>,
320323

321324
/// A partially or completely parameterized type. E.g. `List<K>` or `K`.
322325
///
323-
/// TODO: parse this to a typed representation (likely using the `TypeExpr` parser)
324-
/// so the caller does not have to interpret the raw string.
326+
/// TODO: parse this to a typed representation (likely using the `TypeExpr`
327+
/// parser) so the caller does not have to interpret the raw string.
325328
type_: String,
326329
}
327330

328331
impl TypeArg {
329332
/// Returns the name of this argument.
330333
///
331-
/// See [simple_extensions::TypeArg::name].
334+
/// See [`simple_extensions::TypeArg::name`].
332335
pub fn name(&self) -> Option<&String> {
333336
self.name.as_ref()
334337
}
335338

336339
/// Returns the description of this argument.
337340
///
338-
/// See [simple_extensions::TypeArg::description].
341+
/// See [`simple_extensions::TypeArg::description`].
339342
pub fn description(&self) -> Option<&String> {
340343
self.description.as_ref()
341344
}

src/parse/text/simple_extensions/extensions.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,22 @@ use crate::{
1212
urn::Urn,
1313
};
1414

15-
/// Parsing context for extension processing
15+
/// The contents (types) in an [`ExtensionFile`](super::file::ExtensionFile).
1616
///
17-
/// The context provides access to types defined in the same extension file during parsing.
18-
/// This allows type references to be resolved within the same extension file. The corresponding
19-
/// URN is tracked by [`ExtensionFile`](super::file::ExtensionFile) so this structure can focus on
20-
/// validated type information.
17+
/// This structure stores and provides access to the individual objects defined
18+
/// in an [`ExtensionFile`](super::file::ExtensionFile); [`SimpleExtensions`]
19+
/// represents the contents of an extensions file.
20+
///
21+
/// Currently, only the [`CustomType`]s are included; any scalar, window, or
22+
/// aggregate functions are not yet included.
2123
#[derive(Clone, Debug, Default)]
2224
pub struct SimpleExtensions {
2325
/// Types defined in this extension file
2426
types: HashMap<String, CustomType>,
2527
}
2628

2729
impl SimpleExtensions {
28-
/// Add a type to the context
30+
/// Add a type to the context. Name must be unique.
2931
pub fn add_type(&mut self, custom_type: &CustomType) -> Result<(), SimpleExtensionsError> {
3032
if self.types.contains_key(&custom_type.name) {
3133
return Err(SimpleExtensionsError::DuplicateTypeName {
@@ -59,7 +61,8 @@ impl SimpleExtensions {
5961
}
6062
}
6163

62-
/// A context for parsing simple extensions.
64+
/// A context for parsing simple extensions, tracking what type names are
65+
/// resolved or unresolved.
6366
#[derive(Debug, Default)]
6467
pub struct TypeContext {
6568
/// Types that have been seen so far, now resolved.
@@ -75,7 +78,8 @@ impl TypeContext {
7578
self.known.insert(name.to_string());
7679
}
7780

78-
/// Mark a type as linked to - some other type or function references it, but we haven't seen it.
81+
/// Mark a type as linked to - some other type or function references it,
82+
/// but we haven't seen it.
7983
pub fn linked(&mut self, name: &str) {
8084
if !self.known.contains(name) {
8185
self.linked.insert(name.to_string());

src/parse/text/simple_extensions/file.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ use crate::text::simple_extensions::SimpleExtensions as RawExtensions;
77
use crate::urn::Urn;
88
use std::io::Read;
99

10-
/// A parsed and validated [RawExtensions].
10+
/// A parsed and validated [`RawExtensions`]: a simple extensions file.
1111
///
12-
/// `ExtensionFile` owns the canonical URN for a simple extension file along with the parsed
13-
/// [`SimpleExtensions`](super::SimpleExtensions) data. Keeping the URN here (instead of on the inner
14-
/// type map) lets us thread it through I/O, registries, and conversions without duplicating state.
12+
/// An [`ExtensionFile`] has a canonical [`Urn`] and a parsed set of
13+
/// [`SimpleExtensions`] data. It represents the extensions file as a whole.
1514
#[derive(Debug)]
1615
pub struct ExtensionFile {
1716
/// The URN this extension was loaded from
@@ -21,13 +20,13 @@ pub struct ExtensionFile {
2120
}
2221

2322
impl ExtensionFile {
24-
/// Create a new, empty SimpleExtensions
23+
/// Create a new, empty [`ExtensionFile`] with an empty set of [`SimpleExtensions`].
2524
pub fn empty(urn: Urn) -> Self {
2625
let extension = SimpleExtensions::default();
2726
Self { urn, extension }
2827
}
2928

30-
/// Create a validated SimpleExtensions from raw data
29+
/// Create an [`ExtensionFile`] from raw simple extension data.
3130
pub fn create(extensions: RawExtensions) -> Result<Self, SimpleExtensionsError> {
3231
// Parse all types (may contain unresolved Extension(String) references)
3332
let mut ctx = TypeContext::default();
@@ -48,31 +47,33 @@ impl ExtensionFile {
4847
self.extension.types()
4948
}
5049

51-
/// Returns the URN for this extension file.
50+
/// Returns the [`Urn`]` for this extension file.
5251
pub fn urn(&self) -> &Urn {
5352
&self.urn
5453
}
5554

56-
/// Get a reference to the underlying SimpleExtension
55+
/// Get a reference to the underlying [`SimpleExtensions`].
5756
pub fn extension(&self) -> &SimpleExtensions {
5857
&self.extension
5958
}
6059

61-
/// Convert the parsed extension file back into the raw text representation by value.
60+
/// Convert the parsed extension file back into the raw text representation
61+
/// by value.
6262
pub fn into_raw(self) -> RawExtensions {
6363
let ExtensionFile { urn, extension } = self;
6464
RawExtensions::from((urn, extension))
6565
}
6666

67-
/// Convert the parsed extension file back into the raw text representation by reference.
67+
/// Convert the parsed extension file back into the raw text representation
68+
/// by reference.
6869
pub fn to_raw(&self) -> RawExtensions {
6970
RawExtensions::from((self.urn.clone(), self.extension.clone()))
7071
}
7172

7273
/// Read an extension file from a reader.
73-
/// - `reader`: any `Read` instance with the YAML content
74+
/// - `reader`: any [`Read`] instance with the YAML content
7475
///
75-
/// Returns a parsed and validated `ExtensionFile` or an error.
76+
/// Returns a parsed and validated [`ExtensionFile`] or an error.
7677
pub fn read<R: Read>(reader: R) -> Result<Self, SimpleExtensionsError> {
7778
let raw: RawExtensions = serde_yaml::from_reader(reader)?;
7879
Self::create(raw)

src/parse/text/simple_extensions/mod.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
// SPDX-License-Identifier: Apache-2.0
22

3-
//! Parsing of [crate::text::simple_extensions] types into [SimpleExtensions].
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.
416
517
use std::convert::Infallible;
618

src/parse/text/simple_extensions/parsed_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub enum TypeParseError {
3434
}
3535

3636
impl<'a> TypeExpr<'a> {
37-
/// Parse a type string into a ParsedType
37+
/// Parse a type string into a [`TypeExpr`].
3838
pub fn parse(type_str: &'a str) -> Result<Self, TypeParseError> {
3939
// Handle type variables like any1, any2, etc.
4040
if let Some(suffix) = type_str.strip_prefix("any") {

0 commit comments

Comments
 (0)