Skip to main content

reifydb_rql/
nodes.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2025 ReifyDB
3
4use std::{collections, fmt};
5
6use reifydb_catalog::catalog::{
7	ringbuffer::RingBufferColumnToCreate, series::SeriesColumnToCreate, table::TableColumnToCreate,
8	view::ViewColumnToCreate,
9};
10use reifydb_core::{
11	common::{JoinType, WindowKind},
12	interface::{
13		catalog::{
14			id::{NamespaceId, RingBufferId, SeriesId, TableId, ViewId},
15			namespace::Namespace,
16			procedure::{ProcedureParam, ProcedureTrigger},
17			property::ColumnPropertyKind,
18			series::SeriesKey,
19		},
20		resolved::{
21			ResolvedColumn, ResolvedDictionary, ResolvedNamespace, ResolvedRingBuffer, ResolvedSequence,
22			ResolvedSeries, ResolvedShape, ResolvedTable, ResolvedTableVirtual, ResolvedView,
23		},
24	},
25	row::RowTtl,
26	sort::{SortDirection, SortKey},
27};
28use reifydb_type::{
29	fragment::Fragment,
30	value::{
31		constraint::TypeConstraint, dictionary::DictionaryId, duration::Duration, sumtype::SumTypeId,
32		r#type::Type,
33	},
34};
35
36use crate::{
37	expression::{AliasExpression, Expression, VariableExpression},
38	query::QueryPlan,
39};
40
41/// Owned primary key definition for physical plan nodes (materialized from bump-allocated logical plan)
42#[derive(Debug, Clone)]
43pub struct PrimaryKey {
44	pub columns: Vec<PrimaryKeyColumn>,
45}
46
47/// Owned primary key column for physical plan nodes
48#[derive(Debug, Clone)]
49pub struct PrimaryKeyColumn {
50	pub column: Fragment,
51	pub order: Option<SortDirection>,
52}
53
54#[derive(Debug, Clone)]
55pub enum PhysicalPlan {
56	CreateDeferredView(CreateDeferredViewNode),
57	CreateTransactionalView(CreateTransactionalViewNode),
58	CreateNamespace(CreateNamespaceNode),
59	CreateRemoteNamespace(CreateRemoteNamespaceNode),
60	CreateTable(CreateTableNode),
61	CreateRingBuffer(CreateRingBufferNode),
62	CreateDictionary(CreateDictionaryNode),
63	CreateSumType(CreateSumTypeNode),
64	CreateSubscription(CreateSubscriptionNode),
65	CreatePrimaryKey(CreatePrimaryKeyNode),
66	CreateColumnProperty(CreateColumnPropertyNode),
67	CreateProcedure(CreateProcedureNode),
68	CreateSeries(CreateSeriesNode),
69	CreateEvent(CreateEventNode),
70	CreateTag(CreateTagNode),
71	CreateTest(CreateTestNode),
72	RunTests(RunTestsNode),
73
74	CreateMigration(CreateMigrationNode),
75	Migrate(MigrateNode),
76	RollbackMigration(RollbackMigrationNode),
77	Dispatch(DispatchNode),
78	// Alter
79	AlterSequence(AlterSequenceNode),
80	AlterTable(AlterTableNode),
81	AlterRemoteNamespace(AlterRemoteNamespaceNode),
82	// Mutate
83	Delete(DeleteTableNode),
84	DeleteRingBuffer(DeleteRingBufferNode),
85	InsertTable(InsertTableNode),
86	InsertRingBuffer(InsertRingBufferNode),
87	InsertDictionary(InsertDictionaryNode),
88	Update(UpdateTableNode),
89	UpdateRingBuffer(UpdateRingBufferNode),
90	UpdateSeries(UpdateSeriesNode),
91	// Variable assignment
92	Declare(DeclareNode),
93	Assign(AssignNode),
94	Append(AppendPhysicalNode),
95	// Variable resolution
96	Variable(VariableNode),
97	Environment(EnvironmentNode),
98	// Control flow
99	Conditional(ConditionalNode),
100	Loop(LoopPhysicalNode),
101	While(WhilePhysicalNode),
102	For(ForPhysicalNode),
103	Break,
104	Continue,
105	// User-defined functions
106	DefineFunction(DefineFunctionNode),
107	Return(ReturnNode),
108	CallFunction(CallFunctionNode),
109
110	// Query
111	Aggregate(AggregateNode),
112	Distinct(DistinctNode),
113	Filter(FilterNode),
114	IndexScan(IndexScanNode),
115	// Row-number optimized access
116	RowPointLookup(RowPointLookupNode),
117	RowListLookup(RowListLookupNode),
118	RowRangeScan(RowRangeScanNode),
119	JoinInner(JoinInnerNode),
120	JoinLeft(JoinLeftNode),
121	JoinNatural(JoinNaturalNode),
122	Take(TakeNode),
123	Sort(SortNode),
124	Map(MapNode),
125	Extend(ExtendNode),
126	Patch(PatchNode),
127	Apply(ApplyNode),
128	InlineData(InlineDataNode),
129	RemoteScan(RemoteScanNode),
130	TableScan(TableScanNode),
131	TableVirtualScan(TableVirtualScanNode),
132	ViewScan(ViewScanNode),
133	RingBufferScan(RingBufferScanNode),
134	DictionaryScan(DictionaryScanNode),
135	SeriesScan(SeriesScanNode),
136	// Series DML
137	InsertSeries(InsertSeriesNode),
138	DeleteSeries(DeleteSeriesNode),
139	Generator(GeneratorNode),
140	Window(WindowNode),
141	// Auto-scalarization for 1x1 frames
142	Scalarize(ScalarizeNode),
143	// Auth/Permissions
144	CreateIdentity(CreateIdentityNode),
145	CreateRole(CreateRoleNode),
146	Grant(GrantNode),
147	Revoke(RevokeNode),
148	DropIdentity(DropIdentityNode),
149	DropRole(DropRoleNode),
150	CreateAuthentication(CreateAuthenticationNode),
151	DropAuthentication(DropAuthenticationNode),
152	CreatePolicy(CreatePolicyNode),
153	AlterPolicy(AlterPolicyNode),
154	DropPolicy(DropPolicyNode),
155}
156
157#[derive(Debug, Clone)]
158pub enum CompiledViewStorageKind {
159	Table,
160	RingBuffer {
161		capacity: u64,
162		propagate_evictions: bool,
163		partition_by: Vec<String>,
164	},
165	Series {
166		key: SeriesKey,
167	},
168}
169
170#[derive(Debug, Clone)]
171pub struct CreateDeferredViewNode {
172	pub namespace: Namespace, // FIXME REsolvedNamespace
173	pub view: Fragment,
174	pub if_not_exists: bool,
175	pub columns: Vec<ViewColumnToCreate>,
176	pub as_clause: Box<QueryPlan>,
177	pub storage_kind: CompiledViewStorageKind,
178	pub tick: Option<Duration>,
179}
180
181#[derive(Debug, Clone)]
182pub struct CreateTransactionalViewNode {
183	pub namespace: Namespace, // FIXME REsolvedNamespace
184	pub view: Fragment,
185	pub if_not_exists: bool,
186	pub columns: Vec<ViewColumnToCreate>,
187	pub as_clause: Box<QueryPlan>,
188	pub storage_kind: CompiledViewStorageKind,
189	pub tick: Option<Duration>,
190}
191
192#[derive(Debug, Clone)]
193pub struct CreateNamespaceNode {
194	pub segments: Vec<Fragment>,
195	pub if_not_exists: bool,
196}
197
198#[derive(Debug, Clone)]
199pub struct CreateRemoteNamespaceNode {
200	pub segments: Vec<Fragment>,
201	pub if_not_exists: bool,
202	pub grpc: Fragment,
203	pub token: Option<Fragment>,
204}
205
206#[derive(Debug, Clone)]
207pub struct AlterRemoteNamespaceNode {
208	pub namespace: Fragment,
209	pub grpc: Fragment,
210}
211
212#[derive(Debug, Clone)]
213pub struct CreateTableNode {
214	pub namespace: ResolvedNamespace,
215	pub table: Fragment,
216	pub if_not_exists: bool,
217	pub columns: Vec<TableColumnToCreate>,
218	pub ttl: Option<RowTtl>,
219}
220
221#[derive(Debug, Clone)]
222pub struct CreateRingBufferNode {
223	pub namespace: ResolvedNamespace,
224	pub ringbuffer: Fragment,
225	pub if_not_exists: bool,
226	pub columns: Vec<RingBufferColumnToCreate>,
227	pub capacity: u64,
228	pub partition_by: Vec<String>,
229	pub ttl: Option<RowTtl>,
230}
231
232#[derive(Debug, Clone)]
233pub struct CreateDictionaryNode {
234	pub namespace: Namespace,
235	pub dictionary: Fragment,
236	pub if_not_exists: bool,
237	pub value_type: Type,
238	pub id_type: Type,
239}
240
241#[derive(Debug, Clone)]
242pub struct CreateSumTypeNode {
243	pub namespace: Namespace,
244	pub name: Fragment,
245	pub if_not_exists: bool,
246	pub variants: Vec<CreateSumTypeVariant>,
247}
248
249#[derive(Debug, Clone)]
250pub struct CreateSumTypeVariant {
251	pub name: String,
252	pub columns: Vec<CreateSumTypeColumn>,
253}
254
255#[derive(Debug, Clone)]
256pub struct CreateSumTypeColumn {
257	pub name: String,
258	pub column_type: TypeConstraint,
259}
260
261#[derive(Debug, Clone)]
262pub struct SubscriptionColumnToCreate {
263	pub name: String,
264	pub ty: Type,
265}
266
267#[derive(Debug, Clone)]
268pub struct CreateSubscriptionNode {
269	pub columns: Vec<SubscriptionColumnToCreate>,
270	pub as_clause: Option<Box<QueryPlan>>,
271}
272
273#[derive(Debug, Clone)]
274pub struct AlterSequenceNode {
275	pub sequence: ResolvedSequence,
276	pub column: ResolvedColumn,
277	pub value: Expression,
278}
279
280#[derive(Debug, Clone)]
281pub struct AlterTableNode {
282	pub namespace: ResolvedNamespace,
283	pub table: Fragment,
284	pub action: AlterTableAction,
285}
286
287#[derive(Debug, Clone)]
288pub enum AlterTableAction {
289	AddColumn {
290		column: TableColumnToCreate,
291	},
292	DropColumn {
293		column: Fragment,
294	},
295	RenameColumn {
296		old_name: Fragment,
297		new_name: Fragment,
298	},
299}
300
301// Create Primary Key node
302#[derive(Debug, Clone)]
303pub struct CreatePrimaryKeyNode {
304	pub namespace: ResolvedNamespace,
305	pub table: Fragment,
306	pub columns: Vec<PrimaryKeyColumn>,
307}
308
309// Create Procedure node
310#[derive(Debug, Clone)]
311pub struct CreateProcedureNode {
312	pub namespace: Namespace,
313	pub name: Fragment,
314	pub params: Vec<ProcedureParam>,
315	pub body_source: String,
316	pub trigger: ProcedureTrigger,
317	pub is_test: bool,
318}
319
320/// Physical node for CREATE SERIES
321#[derive(Debug, Clone)]
322pub struct CreateSeriesNode {
323	pub namespace: ResolvedNamespace,
324	pub series: Fragment,
325	pub columns: Vec<SeriesColumnToCreate>,
326	pub tag: Option<SumTypeId>,
327	pub key: SeriesKey,
328	pub ttl: Option<RowTtl>,
329}
330
331/// Physical node for CREATE EVENT
332#[derive(Debug, Clone)]
333pub struct CreateEventNode {
334	pub namespace: Namespace,
335	pub name: Fragment,
336	pub variants: Vec<CreateSumTypeVariant>,
337}
338
339/// Physical node for CREATE TAG
340#[derive(Debug, Clone)]
341pub struct CreateTagNode {
342	pub namespace: Namespace,
343	pub name: Fragment,
344	pub variants: Vec<CreateSumTypeVariant>,
345}
346
347/// A resolved key-value config pair
348#[derive(Debug, Clone)]
349pub struct ConfigPair {
350	pub key: Fragment,
351	pub value: Fragment,
352}
353
354/// Physical node for CREATE SOURCE
355#[derive(Debug, Clone)]
356pub struct CreateSourceNode {
357	pub namespace: Namespace,
358	pub name: Fragment,
359	pub connector: Fragment,
360	pub config: Vec<ConfigPair>,
361	pub target_namespace: Namespace,
362	pub target_name: Fragment,
363}
364
365/// Physical node for CREATE SINK
366#[derive(Debug, Clone)]
367pub struct CreateSinkNode {
368	pub namespace: Namespace,
369	pub name: Fragment,
370	pub source_namespace: Namespace,
371	pub source_name: Fragment,
372	pub connector: Fragment,
373	pub config: Vec<ConfigPair>,
374}
375
376/// Physical node for DROP SOURCE
377#[derive(Debug, Clone)]
378pub struct DropSourceNode {
379	pub if_exists: bool,
380	pub namespace: Namespace,
381	pub name: Fragment,
382	pub cascade: bool,
383}
384
385/// Physical node for DROP SINK
386#[derive(Debug, Clone)]
387pub struct DropSinkNode {
388	pub if_exists: bool,
389	pub namespace: Namespace,
390	pub name: Fragment,
391	pub cascade: bool,
392}
393
394// Assert Block node (multi-statement ASSERT or ASSERT ERROR)
395#[derive(Debug, Clone)]
396pub struct AssertBlockNode {
397	pub rql: String,
398	pub expect_error: bool,
399	pub message: Option<String>,
400}
401
402// Create Test node
403#[derive(Debug, Clone)]
404pub struct CreateTestNode {
405	pub namespace: Namespace,
406	pub name: Fragment,
407	pub cases: Option<String>,
408	pub body_source: String,
409}
410
411// Run Tests node
412#[derive(Debug, Clone)]
413pub struct RunTestsNode {
414	pub scope: RunTestsScope,
415}
416
417#[derive(Debug, Clone)]
418pub enum RunTestsScope {
419	All,
420	Namespace(ResolvedNamespace),
421	Single(ResolvedNamespace, String),
422}
423
424/// Physical node for CREATE MIGRATION
425#[derive(Debug, Clone)]
426pub struct CreateMigrationNode {
427	pub name: String,
428	pub body_source: String,
429	pub rollback_body_source: Option<String>,
430}
431
432/// Physical node for MIGRATE
433#[derive(Debug, Clone)]
434pub struct MigrateNode {
435	pub target: Option<String>,
436}
437
438/// Physical node for ROLLBACK MIGRATION
439#[derive(Debug, Clone)]
440pub struct RollbackMigrationNode {
441	pub target: Option<String>,
442}
443
444/// Physical node for DISPATCH
445#[derive(Debug, Clone)]
446pub struct DispatchNode {
447	pub namespace: Namespace,
448	pub on_sumtype_id: SumTypeId,
449	pub variant_name: String,
450	pub fields: Vec<(String, Expression)>,
451}
452
453// Create Policy node
454#[derive(Debug, Clone)]
455pub struct CreateColumnPropertyNode {
456	pub namespace: ResolvedNamespace,
457	pub table: Fragment,
458	pub column: Fragment,
459	pub properties: Vec<ColumnPropertyKind>,
460}
461
462#[derive(Debug, Clone)]
463pub enum LetValue {
464	Expression(Expression),
465	Statement(QueryPlan),
466	EmptyFrame,
467}
468
469impl fmt::Display for LetValue {
470	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
471		match self {
472			LetValue::Expression(expr) => write!(f, "{}", expr),
473			LetValue::Statement(query) => write!(f, "Statement({:?})", query),
474			LetValue::EmptyFrame => write!(f, "EmptyFrame"),
475		}
476	}
477}
478
479#[derive(Debug, Clone)]
480pub struct DeclareNode {
481	pub name: Fragment,
482	pub value: LetValue,
483}
484
485#[derive(Debug, Clone)]
486pub enum AssignValue {
487	Expression(Expression),
488	Statement(QueryPlan),
489}
490
491impl fmt::Display for AssignValue {
492	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
493		match self {
494			AssignValue::Expression(expr) => write!(f, "{}", expr),
495			AssignValue::Statement(query) => write!(f, "Statement({:?})", query),
496		}
497	}
498}
499
500#[derive(Debug, Clone)]
501pub struct AssignNode {
502	pub name: Fragment,
503	pub value: AssignValue,
504}
505
506#[derive(Debug, Clone)]
507pub struct VariableNode {
508	pub variable_expr: VariableExpression,
509}
510
511#[derive(Debug, Clone)]
512pub struct EnvironmentNode {}
513
514/// A function parameter in the physical plan
515#[derive(Debug, Clone)]
516pub struct FunctionParameter {
517	/// Parameter name (includes $)
518	pub name: Fragment,
519	/// Optional type constraint
520	pub type_constraint: Option<TypeConstraint>,
521}
522
523#[derive(Debug, Clone)]
524pub struct ScalarizeNode {
525	pub input: Box<QueryPlan>,
526	pub fragment: Fragment,
527}
528
529#[derive(Debug, Clone)]
530pub struct AggregateNode {
531	pub input: Box<QueryPlan>,
532	pub by: Vec<Expression>,
533	pub map: Vec<Expression>,
534}
535
536#[derive(Debug, Clone)]
537pub struct DistinctNode {
538	pub input: Box<QueryPlan>,
539	pub columns: Vec<ResolvedColumn>,
540}
541
542#[derive(Debug, Clone)]
543pub struct AssertNode {
544	pub input: Option<Box<QueryPlan>>,
545	pub conditions: Vec<Expression>,
546	pub message: Option<String>,
547}
548
549#[derive(Debug, Clone)]
550pub struct FilterNode {
551	pub input: Box<QueryPlan>,
552	pub conditions: Vec<Expression>,
553}
554
555#[derive(Debug, Clone)]
556pub struct GateNode {
557	pub input: Box<QueryPlan>,
558	pub conditions: Vec<Expression>,
559}
560
561#[derive(Debug, Clone)]
562pub struct DeleteTableNode {
563	pub input: Option<Box<QueryPlan>>,
564	pub target: Option<ResolvedTable>,
565	pub returning: Option<Vec<Expression>>,
566}
567
568#[derive(Debug, Clone)]
569pub struct InsertTableNode {
570	pub input: Box<QueryPlan>,
571	pub target: ResolvedTable,
572	pub returning: Option<Vec<Expression>>,
573}
574
575#[derive(Debug, Clone)]
576pub struct InsertRingBufferNode {
577	pub input: Box<QueryPlan>,
578	pub target: ResolvedRingBuffer,
579	pub returning: Option<Vec<Expression>>,
580}
581
582#[derive(Debug, Clone)]
583pub struct InsertDictionaryNode {
584	pub input: Box<QueryPlan>,
585	pub target: ResolvedDictionary,
586	pub returning: Option<Vec<Expression>>,
587}
588
589#[derive(Debug, Clone)]
590pub struct UpdateTableNode {
591	pub input: Box<QueryPlan>,
592	pub target: Option<ResolvedTable>,
593	pub returning: Option<Vec<Expression>>,
594}
595
596#[derive(Debug, Clone)]
597pub struct DeleteRingBufferNode {
598	pub input: Option<Box<QueryPlan>>,
599	pub target: ResolvedRingBuffer,
600	pub returning: Option<Vec<Expression>>,
601}
602
603#[derive(Debug, Clone)]
604pub struct UpdateRingBufferNode {
605	pub input: Box<QueryPlan>,
606	pub target: ResolvedRingBuffer,
607	pub returning: Option<Vec<Expression>>,
608}
609
610#[derive(Debug, Clone)]
611pub struct UpdateSeriesNode {
612	pub input: Box<QueryPlan>,
613	pub target: ResolvedSeries,
614	pub returning: Option<Vec<Expression>>,
615}
616
617#[derive(Debug, Clone)]
618pub struct JoinInnerNode {
619	pub left: Box<QueryPlan>,
620	pub right: Box<QueryPlan>,
621	pub on: Vec<Expression>,
622	pub alias: Option<Fragment>,
623}
624
625#[derive(Debug, Clone)]
626pub struct JoinLeftNode {
627	pub left: Box<QueryPlan>,
628	pub right: Box<QueryPlan>,
629	pub on: Vec<Expression>,
630	pub alias: Option<Fragment>,
631}
632
633#[derive(Debug, Clone)]
634pub struct JoinNaturalNode {
635	pub left: Box<QueryPlan>,
636	pub right: Box<QueryPlan>,
637	pub join_type: JoinType,
638	pub alias: Option<Fragment>,
639}
640
641#[derive(Debug, Clone)]
642pub struct AppendQueryNode {
643	pub left: Box<QueryPlan>,
644	pub right: Box<QueryPlan>,
645}
646
647#[derive(Debug, Clone)]
648pub struct SortNode {
649	pub input: Box<QueryPlan>,
650	pub by: Vec<SortKey>,
651}
652
653#[derive(Debug, Clone)]
654pub struct MapNode {
655	pub input: Option<Box<QueryPlan>>,
656	pub map: Vec<Expression>,
657}
658
659#[derive(Debug, Clone)]
660pub struct ExtendNode {
661	pub input: Option<Box<QueryPlan>>,
662	pub extend: Vec<Expression>,
663}
664
665#[derive(Debug, Clone)]
666pub struct PatchNode {
667	pub input: Option<Box<QueryPlan>>,
668	pub assignments: Vec<Expression>,
669}
670
671#[derive(Debug, Clone)]
672pub struct ApplyNode {
673	pub input: Option<Box<QueryPlan>>,
674	pub operator: Fragment, // FIXME becomes OperatorIdentifier
675	pub expressions: Vec<Expression>,
676}
677
678#[derive(Debug, Clone)]
679pub struct InlineDataNode {
680	pub rows: Vec<Vec<AliasExpression>>,
681}
682
683#[derive(Debug, Clone)]
684pub struct IndexScanNode {
685	pub source: ResolvedTable,
686	pub index_name: String,
687}
688
689#[derive(Debug, Clone)]
690pub struct RemoteScanNode {
691	pub address: String,
692	pub token: Option<String>,
693	pub remote_rql: String,
694	pub local_namespace: String,
695	pub remote_name: String,
696	pub variables: Vec<String>,
697}
698
699#[derive(Debug, Clone)]
700pub struct TableScanNode {
701	pub source: ResolvedTable,
702}
703
704#[derive(Debug, Clone)]
705pub struct ViewScanNode {
706	pub source: ResolvedView,
707}
708
709#[derive(Debug, Clone)]
710pub struct RingBufferScanNode {
711	pub source: ResolvedRingBuffer,
712}
713
714#[derive(Debug, Clone)]
715pub struct DictionaryScanNode {
716	pub source: ResolvedDictionary,
717}
718
719#[derive(Debug, Clone)]
720pub struct SeriesScanNode {
721	pub source: ResolvedSeries,
722	pub key_range_start: Option<u64>,
723	pub key_range_end: Option<u64>,
724	pub variant_tag: Option<u8>,
725}
726
727#[derive(Debug, Clone)]
728pub struct InsertSeriesNode {
729	pub input: Box<QueryPlan>,
730	pub target: ResolvedSeries,
731	pub returning: Option<Vec<Expression>>,
732}
733
734#[derive(Debug, Clone)]
735pub struct DeleteSeriesNode {
736	pub input: Option<Box<QueryPlan>>,
737	pub target: ResolvedSeries,
738	pub returning: Option<Vec<Expression>>,
739}
740
741#[derive(Debug, Clone)]
742pub struct GeneratorNode {
743	pub name: Fragment,
744	pub expressions: Vec<Expression>,
745}
746
747#[derive(Debug, Clone)]
748pub struct TableVirtualScanNode {
749	pub source: ResolvedTableVirtual,
750	pub pushdown_context: Option<TableVirtualPushdownContext>,
751}
752
753#[derive(Debug, Clone)]
754pub struct TableVirtualPushdownContext {
755	pub filters: Vec<Expression>,
756	pub projections: Vec<Expression>,
757	pub order_by: Vec<SortKey>,
758	pub limit: Option<usize>,
759}
760
761#[derive(Debug, Clone)]
762pub enum TakeLimit {
763	Literal(usize),
764	Variable(String),
765}
766
767impl fmt::Display for TakeLimit {
768	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
769		match self {
770			TakeLimit::Literal(n) => write!(f, "{}", n),
771			TakeLimit::Variable(name) => write!(f, "${}", name),
772		}
773	}
774}
775
776#[derive(Debug, Clone)]
777pub struct TakeNode {
778	pub input: Box<QueryPlan>,
779	pub take: TakeLimit,
780}
781
782#[derive(Debug, Clone)]
783pub struct WindowNode {
784	pub input: Option<Box<QueryPlan>>,
785	pub kind: WindowKind,
786	pub group_by: Vec<Expression>,
787	pub aggregations: Vec<Expression>,
788	pub ts: Option<String>,
789}
790
791/// O(1) point lookup by row number: `filter rownum == N`
792#[derive(Debug, Clone)]
793pub struct RowPointLookupNode {
794	/// The source to look up in (table, ring buffer, etc.)
795	pub source: ResolvedShape,
796	/// The row number to fetch
797	pub row_number: u64,
798}
799
800/// O(k) list lookup by row numbers: `filter rownum in [a, b, c]`
801#[derive(Debug, Clone)]
802pub struct RowListLookupNode {
803	/// The source to look up in
804	pub source: ResolvedShape,
805	/// The row numbers to fetch
806	pub row_numbers: Vec<u64>,
807}
808
809/// Range scan by row numbers: `filter rownum between X and Y`
810#[derive(Debug, Clone)]
811pub struct RowRangeScanNode {
812	/// The source to scan
813	pub source: ResolvedShape,
814	/// Start of the range (inclusive)
815	pub start: u64,
816	/// End of the range (inclusive)
817	pub end: u64,
818}
819
820/// APPEND statement physical plan node
821#[derive(Debug, Clone)]
822pub enum AppendPhysicalNode {
823	IntoVariable {
824		target: Fragment,
825		source: AppendPhysicalSource,
826	},
827	Query {
828		left: Box<QueryPlan>,
829		right: Box<QueryPlan>,
830	},
831}
832
833/// Source for an APPEND physical plan
834#[derive(Debug, Clone)]
835pub enum AppendPhysicalSource {
836	Statement(Vec<PhysicalPlan>),
837	Inline(InlineDataNode),
838}
839
840#[derive(Debug, Clone)]
841pub struct ConditionalNode {
842	pub condition: Expression,
843	pub then_branch: Box<PhysicalPlan>,
844	pub else_ifs: Vec<ElseIfBranch>,
845	pub else_branch: Option<Box<PhysicalPlan>>,
846}
847
848#[derive(Debug, Clone)]
849pub struct ElseIfBranch {
850	pub condition: Expression,
851	pub then_branch: Box<PhysicalPlan>,
852}
853
854#[derive(Debug, Clone)]
855pub struct LoopPhysicalNode {
856	pub body: Vec<PhysicalPlan>,
857}
858
859#[derive(Debug, Clone)]
860pub struct WhilePhysicalNode {
861	pub condition: Expression,
862	pub body: Vec<PhysicalPlan>,
863}
864
865#[derive(Debug, Clone)]
866pub struct ForPhysicalNode {
867	pub variable_name: Fragment,
868	pub iterable: Box<PhysicalPlan>,
869	pub body: Vec<PhysicalPlan>,
870}
871
872#[derive(Debug, Clone)]
873pub struct DefineFunctionNode {
874	pub name: Fragment,
875	pub parameters: Vec<FunctionParameter>,
876	pub return_type: Option<TypeConstraint>,
877	pub body: Vec<PhysicalPlan>,
878}
879
880#[derive(Debug, Clone)]
881pub struct ReturnNode {
882	pub value: Option<Expression>,
883}
884
885#[derive(Debug, Clone)]
886pub struct CallFunctionNode {
887	pub name: Fragment,
888	pub arguments: Vec<Expression>,
889	pub is_procedure_call: bool,
890}
891
892#[derive(Debug, Clone)]
893pub struct DropNamespaceNode {
894	pub namespace_name: Fragment,
895	pub namespace_id: Option<NamespaceId>,
896	pub if_exists: bool,
897	pub cascade: bool,
898}
899
900#[derive(Debug, Clone)]
901pub struct DropTableNode {
902	pub namespace_name: Fragment,
903	pub table_name: Fragment,
904	pub table_id: Option<TableId>,
905	pub if_exists: bool,
906	pub cascade: bool,
907}
908
909#[derive(Debug, Clone)]
910pub struct DropViewNode {
911	pub namespace_name: Fragment,
912	pub view_name: Fragment,
913	pub view_id: Option<ViewId>,
914	pub if_exists: bool,
915	pub cascade: bool,
916}
917
918#[derive(Debug, Clone)]
919pub struct DropRingBufferNode {
920	pub namespace_name: Fragment,
921	pub ringbuffer_name: Fragment,
922	pub ringbuffer_id: Option<RingBufferId>,
923	pub if_exists: bool,
924	pub cascade: bool,
925}
926
927#[derive(Debug, Clone)]
928pub struct DropDictionaryNode {
929	pub namespace_name: Fragment,
930	pub dictionary_name: Fragment,
931	pub dictionary_id: Option<DictionaryId>,
932	pub if_exists: bool,
933	pub cascade: bool,
934}
935
936#[derive(Debug, Clone)]
937pub struct DropSumTypeNode {
938	pub namespace_name: Fragment,
939	pub sumtype_name: Fragment,
940	pub sumtype_id: Option<SumTypeId>,
941	pub if_exists: bool,
942	pub cascade: bool,
943}
944
945#[derive(Debug, Clone)]
946pub struct DropSubscriptionNode {
947	pub subscription_name: Fragment,
948	pub if_exists: bool,
949	pub cascade: bool,
950}
951
952#[derive(Debug, Clone)]
953pub struct DropSeriesNode {
954	pub namespace_name: Fragment,
955	pub series_name: Fragment,
956	pub series_id: Option<SeriesId>,
957	pub if_exists: bool,
958	pub cascade: bool,
959}
960
961#[derive(Debug, Clone)]
962pub struct CreateIdentityNode {
963	pub name: Fragment,
964}
965
966#[derive(Debug, Clone)]
967pub struct CreateRoleNode {
968	pub name: Fragment,
969}
970
971#[derive(Debug, Clone)]
972pub struct GrantNode {
973	pub role: Fragment,
974	pub user: Fragment,
975}
976
977#[derive(Debug, Clone)]
978pub struct RevokeNode {
979	pub role: Fragment,
980	pub user: Fragment,
981}
982
983#[derive(Debug, Clone)]
984pub struct DropIdentityNode {
985	pub name: Fragment,
986	pub if_exists: bool,
987}
988
989#[derive(Debug, Clone)]
990pub struct DropRoleNode {
991	pub name: Fragment,
992	pub if_exists: bool,
993}
994
995#[derive(Debug, Clone)]
996pub struct CreateAuthenticationNode {
997	pub user: Fragment,
998	pub method: Fragment,
999	pub config: collections::HashMap<String, String>,
1000}
1001
1002#[derive(Debug, Clone)]
1003pub struct DropAuthenticationNode {
1004	pub user: Fragment,
1005	pub method: Fragment,
1006	pub if_exists: bool,
1007}
1008
1009#[derive(Debug, Clone)]
1010pub struct CreatePolicyNode {
1011	pub name: Option<Fragment>,
1012	pub target_type: String,
1013	pub scope_namespace: Option<Fragment>,
1014	pub scope_shape: Option<Fragment>,
1015	pub operations: Vec<PolicyOperationNode>,
1016}
1017
1018#[derive(Debug, Clone)]
1019pub struct PolicyOperationNode {
1020	pub operation: String,
1021	pub body_source: String,
1022}
1023
1024#[derive(Debug, Clone)]
1025pub struct AlterPolicyNode {
1026	pub target_type: String,
1027	pub name: Fragment,
1028	pub enable: bool,
1029}
1030
1031#[derive(Debug, Clone)]
1032pub struct DropPolicyNode {
1033	pub target_type: String,
1034	pub name: Fragment,
1035	pub if_exists: bool,
1036}