Skip to content

Commit eb2ad2d

Browse files
committed
add documentation
1 parent f44715a commit eb2ad2d

File tree

2 files changed

+60
-6
lines changed

2 files changed

+60
-6
lines changed

src/analysis.rs

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,47 @@ pub struct AnalysisOptions {
5252
pub default_scope: Scope,
5353
/// Type information for event records being queried.
5454
pub event_type_info: Type,
55-
/// Collections of types that are not defined in the EventQL reference but yet
56-
/// allow the user to use.
55+
/// Custom types that are not defined in the EventQL reference.
56+
///
57+
/// This set allows users to register custom type names that can be used
58+
/// in type conversion expressions (e.g., `field AS CustomType`). Custom
59+
/// type names are case-insensitive.
60+
///
61+
/// # Examples
62+
///
63+
/// ```
64+
/// use eventql_parser::prelude::AnalysisOptions;
65+
///
66+
/// let options = AnalysisOptions::default()
67+
/// .add_custom_type("Foobar");
68+
/// ```
5769
pub custom_types: HashSet<Ascii<String>>,
5870
}
5971

6072
impl AnalysisOptions {
73+
/// Adds a custom type name to the analysis options.
74+
///
75+
/// Custom types allow you to use type conversion syntax with types that are
76+
/// not part of the standard EventQL type system. The type name is stored
77+
/// case-insensitively.
78+
///
79+
/// # Arguments
80+
///
81+
/// * `value` - The custom type name to register
82+
///
83+
/// # Returns
84+
///
85+
/// Returns `self` to allow for method chaining.
86+
///
87+
/// # Examples
88+
///
89+
/// ```
90+
/// use eventql_parser::prelude::AnalysisOptions;
91+
///
92+
/// let options = AnalysisOptions::default()
93+
/// .add_custom_type("Timestamp")
94+
/// .add_custom_type("UUID");
95+
/// ```
6196
pub fn add_custom_type<'a>(mut self, value: impl Into<Cow<'a, str>>) -> Self {
6297
match value.into() {
6398
Cow::Borrowed(t) => self.custom_types.insert(Ascii::new(t.to_owned())),

src/ast.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,32 @@ pub enum Type {
7373
Subject,
7474
/// Function type
7575
App { args: Vec<Type>, result: Box<Type> },
76-
/// A date (e.g 2026-01-03)
76+
/// Date type (e.g., `2026-01-03`)
77+
///
78+
/// Used when a field is explicitly converted to a date using the `AS DATE` syntax.
7779
Date,
78-
/// Time (e.g 13:45:39)
80+
/// Time type (e.g., `13:45:39`)
81+
///
82+
/// Used when a field is explicitly converted to a time using the `AS TIME` syntax.
7983
Time,
80-
/// A DateTime (e.g 2026-01-01T13:45:39Z).
84+
/// DateTime type (e.g., `2026-01-01T13:45:39Z`)
85+
///
86+
/// Used when a field is explicitly converted to a datetime using the `AS DATETIME` syntax.
8187
DateTime,
82-
/// A type that is not defined in the EventQL reference
88+
/// Custom type not defined in the EventQL reference
89+
///
90+
/// Used when a field is converted to a custom type registered in [`AnalysisOptions::custom_types`].
91+
/// The string contains the custom type name as it appears in the query.
92+
///
93+
/// # Examples
94+
///
95+
/// ```
96+
/// use eventql_parser::prelude::{parse_query, AnalysisOptions};
97+
///
98+
/// let query = parse_query("FROM e IN events PROJECT INTO { ts: e.data.timestamp as CustomTimestamp }").unwrap();
99+
/// let options = AnalysisOptions::default().add_custom_type("CustomTimestamp");
100+
/// let typed_query = query.run_static_analysis(&options).unwrap();
101+
/// ```
83102
Custom(String),
84103
}
85104

0 commit comments

Comments
 (0)