Skip to content

Commit 542bfc2

Browse files
committed
WIP
1 parent 7e80632 commit 542bfc2

File tree

26 files changed

+814
-324
lines changed

26 files changed

+814
-324
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proto/substrait/validator/simple_extensions.proto

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,25 @@ message ExtensionDefinition {
211211
WindowProperties window_function = 9;
212212
}
213213

214+
// For table functions, when defined; to be added to above oneof.
215+
reserved 10;
216+
217+
// Nullability behavior that the function was declared with. Note that the
218+
// patterns have already been desugared to represent this, so this can be
219+
// ignored; it exists only for completeness.
220+
oneof consistency {
221+
// Nullability of toplevel binding and data type patterns of all argument
222+
// and return types was overridden to `??nullable`.
223+
google.protobuf.Empty mirror = 11;
224+
225+
// Nullability of toplevel binding and data type patterns of all argument
226+
// types was overridden to `??nullable`.
227+
google.protobuf.Empty declared_output = 12;
228+
229+
// No desugaring overrides were applied.
230+
google.protobuf.Empty discrete = 13;
231+
}
232+
214233
// Properties common to aggregate and window functions.
215234
message AggregateProperties {
216235
// When specified, the function is decomposable.
@@ -250,9 +269,8 @@ message ExtensionDefinition {
250269
}
251270
}
252271

253-
// Represents a parameter pack for a user-defined compound type class or a
254-
// function argument slot list. In the latter case, the patterns will only
255-
// ever be passed typenames.
272+
// Represents a positional parameter pack for a user-defined compound type
273+
// class or a function argument slot list.
256274
//
257275
// The order of operations for the various patterns is:
258276
//
@@ -303,7 +321,7 @@ message ExtensionDefinition {
303321
// for aggregate and window functions.
304322
google.protobuf.Empty literal = 6;
305323

306-
// An data value must be bound to the slot. This is done by means of
324+
// A data value must be bound to the slot. This is done by means of
307325
// binding an expression, but the expression can always be evaluated or
308326
// reduced before the function is invoked. This is used for value
309327
// function arguments that are not marked as constant. The data type of
@@ -350,6 +368,18 @@ message ExtensionDefinition {
350368
// The maximum number of arguments that can be bound to the slot. Zero
351369
// is treated as unspecified/no upper limit.
352370
uint64 maximum = 2;
371+
372+
// Consistency that the variadic slot was declared with. Note that the
373+
// patterns have already been desugared to represent this, so this can be
374+
// ignored; it exists only for completeness.
375+
oneof consistency {
376+
// No desugaring overrides were applied.
377+
google.protobuf.Empty consistent = 3;
378+
379+
// All consistent bindings in the last argument slot were overridden to
380+
// inconsistent bindings.
381+
google.protobuf.Empty inconsistent = 4;
382+
}
353383
}
354384

355385
// Optional additional constraints to apply when determining whether a

rs/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ serde_yaml = "0.9"
4040
# both the schema and the input, so we need to depend on that as well, even
4141
# though we don't actually do any JSON serialization and deserialization.
4242
jsonschema = { version = "=0.15.0", default-features = false }
43-
serde_json = "1"
43+
serde_json = { version = "1", features = ["preserve_order"] }
4444

4545
# Used for checking identifier syntax (could be removed if regexes don't end up
4646
# being useful elsewhere too).

rs/src/export/proto.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -353,25 +353,6 @@ impl From<&extension::simple::type_class::Reference> for validator::data_type::U
353353
}
354354
}
355355

356-
impl From<&extension::simple::type_class::Definition>
357-
for validator::data_type::user_defined_type::Definition
358-
{
359-
fn from(node: &extension::simple::type_class::Definition) -> Self {
360-
Self {
361-
structure: node
362-
.structure
363-
.iter()
364-
.map(
365-
|(name, simple)| validator::data_type::user_defined_type::Element {
366-
name: name.to_string(),
367-
kind: simple.into(),
368-
},
369-
)
370-
.collect(),
371-
}
372-
}
373-
}
374-
375356
impl From<&data::Variation> for validator::data_type::Variation {
376357
fn from(node: &data::Variation) -> Self {
377358
match node {

rs/src/output/diagnostic.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,9 @@ pub enum Classification {
246246
#[strum(props(HiddenDescription = "invalid compound vs. simple function name usage"))]
247247
LinkCompoundVsSimpleFunctionName = 3010,
248248

249+
#[strum(props(Description = "discouraged name"))]
250+
LinkDiscouragedName = 3011,
251+
249252
// Type-related diagnostics (group 4).
250253
#[strum(props(HiddenDescription = "type-related diagnostics"))]
251254
Type = 4000,

rs/src/output/extension/namespace.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,22 @@ impl<T> ResolutionResult<T> {
531531
self.expect(parse_context, if_not_applicable, |_, _| true, true, false)
532532
}
533533

534+
/// Emits an error if one or more definitions were found for this name
535+
/// resolution, to be used just before defining a new item.
536+
pub fn expect_not_yet_defined(&self, parse_context: &mut context::Context) {
537+
if !self.visible.is_empty() {
538+
traversal::push_diagnostic(
539+
parse_context,
540+
diagnostic::Level::Error,
541+
cause!(
542+
LinkDuplicateDefinition,
543+
"{} is already defined",
544+
self.unresolved_reference
545+
),
546+
);
547+
}
548+
}
549+
534550
/// Silently returns the first matching item, if any. If there are none,
535551
/// this just returns an unresolved reference. Use
536552
/// filter_items().expect_one() to formulate error messages if there are
@@ -567,18 +583,4 @@ impl<T> ResolutionResult<T> {
567583
.next()
568584
.flatten()
569585
}
570-
571-
/// Return an error if one or more definitions were found for this name
572-
/// resolution, to be used just before defining a new item.
573-
pub fn expect_not_yet_defined(&self) -> diagnostic::Result<()> {
574-
if self.visible.is_empty() {
575-
Ok(())
576-
} else {
577-
Err(cause!(
578-
LinkDuplicateDefinition,
579-
"{} is already defined",
580-
self.unresolved_reference
581-
))
582-
}
583-
}
584586
}

rs/src/output/extension/reference.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ use crate::output::path;
66
use crate::util;
77
use std::sync::Arc;
88

9-
/// Represents an identifier that was used to reference something. It is
10-
/// stored along with a resolution result to retain information about the
11-
/// reference even if the resolution failed, and is generally only used for
12-
/// identity/equality checks and diagnostic information.
9+
/// Represents an identifier that was used to reference an extension at the
10+
/// protobuf level. It is stored along with a resolution result to retain
11+
/// information about the reference even if the resolution failed, and is
12+
/// generally only used for identity/equality checks and diagnostic
13+
/// information.
1314
#[derive(Clone, Debug, Default)]
1415
pub struct Identifier {
1516
/// The name of the object being referred to, if known. Always stored using
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
//! Module for the common types involved with representing extension
4+
//! definitions.
5+
6+
/// Identifying information associated with an extension, that can be used to
7+
/// refer to the extension from elsewhere.
8+
#[derive(Clone, Debug)]
9+
pub struct Identifier {
10+
/// The URI that the extension was declared with. Matched case-sensitively.
11+
pub uri: String,
12+
13+
/// One or more aliases for this extension within the scope of the URI.
14+
/// Matched case-insensitively.
15+
pub names: Vec<String>,
16+
17+
/// Unique number for the extension, generated during traversal. The
18+
/// number is only unique within the scope of a single run of the
19+
/// validator, and may change between runs.
20+
pub extension_id: u64,
21+
}
22+
23+
/// Non-functional metadata common to all extension types.
24+
#[derive(Clone, Debug, Default)]
25+
pub struct Metadata {
26+
// Optional description of the extension. Only serves as documentation.
27+
pub description: String,
28+
}

rs/src/output/extension/simple/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
//! Module for representing simple extensions.
44
5+
pub mod common;
56
pub mod function;
67
pub mod module;
78
pub mod type_class;

rs/src/output/extension/simple/module.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,13 @@ impl<T: Scope> DynScope for T {
7272
}
7373

7474
/// A parsed simple extension module/file.
75-
#[derive(Clone, Debug, Default)]
75+
#[derive(Clone, Debug)]
7676
pub struct Definition {
77-
/// Unique number within the tree that can be used to refer to this
78-
/// extension when exporting in protobuf form.
79-
pub extension_id: u64,
77+
/// Identifier for the extension.
78+
pub identifier: extension::simple::common::Identifier,
8079

81-
/// Description of the module.
82-
pub description: String,
80+
/// Common metadata for the extension.
81+
pub metadata: extension::simple::common::Metadata,
8382

8483
/// The URI that was actually used to resolve the module.
8584
pub actual_uri: String,

0 commit comments

Comments
 (0)