|
| 1 | +//! Function header values as Python holds them and what Python's attachment parses from them. |
| 2 | +
|
| 3 | +/// One authored header value: text, a mapping, a list or tuple, or anything else. |
| 4 | +#[derive(Clone, Debug, PartialEq, Eq)] |
| 5 | +pub enum HeaderValue { |
| 6 | + Text(String), |
| 7 | + Map(Vec<(HeaderValue, HeaderValue)>), |
| 8 | + Sequence(Vec<HeaderValue>), |
| 9 | + Other, |
| 10 | +} |
| 11 | + |
| 12 | +/// Which function file kind's header rules apply. |
| 13 | +#[derive(Clone, Copy, Debug, PartialEq, Eq)] |
| 14 | +pub enum FunctionLanguage { |
| 15 | + Sql, |
| 16 | + Python, |
| 17 | +} |
| 18 | + |
| 19 | +/// One argument or return column: the authored name, the stripped name and the stripped type. |
| 20 | +#[derive(Clone, Debug, PartialEq, Eq)] |
| 21 | +pub struct NamedType { |
| 22 | + /// Python's error messages quote the name as authored. |
| 23 | + pub raw_name: String, |
| 24 | + pub name: String, |
| 25 | + pub type_text: String, |
| 26 | +} |
| 27 | + |
| 28 | +/// A scalar return type or table function columns, with types before template expansion. |
| 29 | +#[derive(Clone, Debug, PartialEq, Eq)] |
| 30 | +pub enum FunctionReturns { |
| 31 | + Type(String), |
| 32 | + Table(Vec<NamedType>), |
| 33 | +} |
| 34 | + |
| 35 | +/// Stripped header values; argument, return and column types are still unexpanded templates. |
| 36 | +#[derive(Clone, Debug, PartialEq, Eq)] |
| 37 | +pub struct FunctionHeader { |
| 38 | + pub arguments: Vec<NamedType>, |
| 39 | + pub returns: FunctionReturns, |
| 40 | + pub tags: Vec<String>, |
| 41 | + pub description: Option<String>, |
| 42 | + /// Python functions only: `runtime_version`, `entry_point` and `packages`. |
| 43 | + pub runtime_version: Option<String>, |
| 44 | + pub entry_point: Option<String>, |
| 45 | + pub packages: Vec<String>, |
| 46 | +} |
| 47 | + |
| 48 | +/// The project and target namespace a function resolves against, already expanded. |
| 49 | +#[derive(Clone, Debug, PartialEq, Eq)] |
| 50 | +pub struct NamespaceInputs { |
| 51 | + /// The function header's own `database` and `schema`, when they are strings. |
| 52 | + pub header_database: Option<String>, |
| 53 | + pub header_schema: Option<String>, |
| 54 | + pub default_database: Option<String>, |
| 55 | + pub default_schema: Option<String>, |
| 56 | + pub target_database: Option<String>, |
| 57 | + pub target_schema: Option<String>, |
| 58 | + /// Python functions without their own namespace inherit the project defaults. |
| 59 | + pub language: FunctionLanguage, |
| 60 | + pub inherit_default_namespace: bool, |
| 61 | +} |
| 62 | + |
| 63 | +/// Python's resolved physical, logical and fingerprint namespace of one function. |
| 64 | +#[derive(Clone, Debug, Default, PartialEq, Eq)] |
| 65 | +pub struct FunctionNamespace { |
| 66 | + pub database: Option<String>, |
| 67 | + pub schema: Option<String>, |
| 68 | + pub logical_database: Option<String>, |
| 69 | + pub logical_schema: Option<String>, |
| 70 | + pub fingerprint_database: Option<String>, |
| 71 | + pub fingerprint_schema: Option<String>, |
| 72 | + pub fingerprint_logical_database: Option<String>, |
| 73 | + pub fingerprint_logical_schema: Option<String>, |
| 74 | +} |
0 commit comments