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	pub ttl: Option<RowTtl>,
180}
181
182#[derive(Debug, Clone)]
183pub struct CreateTransactionalViewNode {
184	pub namespace: Namespace, // FIXME REsolvedNamespace
185	pub view: Fragment,
186	pub if_not_exists: bool,
187	pub columns: Vec<ViewColumnToCreate>,
188	pub as_clause: Box<QueryPlan>,
189	pub storage_kind: CompiledViewStorageKind,
190	pub tick: Option<Duration>,
191	pub ttl: Option<RowTtl>,
192}
193
194#[derive(Debug, Clone)]
195pub struct CreateNamespaceNode {
196	pub segments: Vec<Fragment>,
197	pub if_not_exists: bool,
198}
199
200#[derive(Debug, Clone)]
201pub struct CreateRemoteNamespaceNode {
202	pub segments: Vec<Fragment>,
203	pub if_not_exists: bool,
204	pub grpc: Fragment,
205	pub token: Option<Fragment>,
206}
207
208#[derive(Debug, Clone)]
209pub struct AlterRemoteNamespaceNode {
210	pub namespace: Fragment,
211	pub grpc: Fragment,
212}
213
214#[derive(Debug, Clone)]
215pub struct CreateTableNode {
216	pub namespace: ResolvedNamespace,
217	pub table: Fragment,
218	pub if_not_exists: bool,
219	pub columns: Vec<TableColumnToCreate>,
220	pub ttl: Option<RowTtl>,
221}
222
223#[derive(Debug, Clone)]
224pub struct CreateRingBufferNode {
225	pub namespace: ResolvedNamespace,
226	pub ringbuffer: Fragment,
227	pub if_not_exists: bool,
228	pub columns: Vec<RingBufferColumnToCreate>,
229	pub capacity: u64,
230	pub partition_by: Vec<String>,
231	pub ttl: Option<RowTtl>,
232}
233
234#[derive(Debug, Clone)]
235pub struct CreateDictionaryNode {
236	pub namespace: Namespace,
237	pub dictionary: Fragment,
238	pub if_not_exists: bool,
239	pub value_type: Type,
240	pub id_type: Type,
241}
242
243#[derive(Debug, Clone)]
244pub struct CreateSumTypeNode {
245	pub namespace: Namespace,
246	pub name: Fragment,
247	pub if_not_exists: bool,
248	pub variants: Vec<CreateSumTypeVariant>,
249}
250
251#[derive(Debug, Clone)]
252pub struct CreateSumTypeVariant {
253	pub name: String,
254	pub columns: Vec<CreateSumTypeColumn>,
255}
256
257#[derive(Debug, Clone)]
258pub struct CreateSumTypeColumn {
259	pub name: String,
260	pub column_type: TypeConstraint,
261}
262
263#[derive(Debug, Clone)]
264pub struct SubscriptionColumnToCreate {
265	pub name: String,
266	pub ty: Type,
267}
268
269#[derive(Debug, Clone)]
270pub struct CreateSubscriptionNode {
271	pub columns: Vec<SubscriptionColumnToCreate>,
272	pub as_clause: Option<Box<QueryPlan>>,
273}
274
275#[derive(Debug, Clone)]
276pub struct AlterSequenceNode {
277	pub sequence: ResolvedSequence,
278	pub column: ResolvedColumn,
279	pub value: Expression,
280}
281
282#[derive(Debug, Clone)]
283pub struct AlterTableNode {
284	pub namespace: ResolvedNamespace,
285	pub table: Fragment,
286	pub action: AlterTableAction,
287}
288
289#[derive(Debug, Clone)]
290pub enum AlterTableAction {
291	AddColumn {
292		column: TableColumnToCreate,
293	},
294	DropColumn {
295		column: Fragment,
296	},
297	RenameColumn {
298		old_name: Fragment,
299		new_name: Fragment,
300	},
301}
302
303// Create Primary Key node
304#[derive(Debug, Clone)]
305pub struct CreatePrimaryKeyNode {
306	pub namespace: ResolvedNamespace,
307	pub table: Fragment,
308	pub columns: Vec<PrimaryKeyColumn>,
309}
310
311// Create Procedure node
312#[derive(Debug, Clone)]
313pub struct CreateProcedureNode {
314	pub namespace: Namespace,
315	pub name: Fragment,
316	pub params: Vec<ProcedureParam>,
317	pub body_source: String,
318	pub trigger: ProcedureTrigger,
319	pub is_test: bool,
320}
321
322/// Physical node for CREATE SERIES
323#[derive(Debug, Clone)]
324pub struct CreateSeriesNode {
325	pub namespace: ResolvedNamespace,
326	pub series: Fragment,
327	pub columns: Vec<SeriesColumnToCreate>,
328	pub tag: Option<SumTypeId>,
329	pub key: SeriesKey,
330	pub ttl: Option<RowTtl>,
331}
332
333/// Physical node for CREATE EVENT
334#[derive(Debug, Clone)]
335pub struct CreateEventNode {
336	pub namespace: Namespace,
337	pub name: Fragment,
338	pub variants: Vec<CreateSumTypeVariant>,
339}
340
341/// Physical node for CREATE TAG
342#[derive(Debug, Clone)]
343pub struct CreateTagNode {
344	pub namespace: Namespace,
345	pub name: Fragment,
346	pub variants: Vec<CreateSumTypeVariant>,
347}
348
349/// A resolved key-value config pair
350#[derive(Debug, Clone)]
351pub struct ConfigPair {
352	pub key: Fragment,
353	pub value: Fragment,
354}
355
356/// Physical node for CREATE SOURCE
357#[derive(Debug, Clone)]
358pub struct CreateSourceNode {
359	pub namespace: Namespace,
360	pub name: Fragment,
361	pub connector: Fragment,
362	pub config: Vec<ConfigPair>,
363	pub target_namespace: Namespace,
364	pub target_name: Fragment,
365}
366
367/// Physical node for CREATE SINK
368#[derive(Debug, Clone)]
369pub struct CreateSinkNode {
370	pub namespace: Namespace,
371	pub name: Fragment,
372	pub source_namespace: Namespace,
373	pub source_name: Fragment,
374	pub connector: Fragment,
375	pub config: Vec<ConfigPair>,
376}
377
378/// Physical node for DROP SOURCE
379#[derive(Debug, Clone)]
380pub struct DropSourceNode {
381	pub if_exists: bool,
382	pub namespace: Namespace,
383	pub name: Fragment,
384	pub cascade: bool,
385}
386
387/// Physical node for DROP SINK
388#[derive(Debug, Clone)]
389pub struct DropSinkNode {
390	pub if_exists: bool,
391	pub namespace: Namespace,
392	pub name: Fragment,
393	pub cascade: bool,
394}
395
396// Assert Block node (multi-statement ASSERT or ASSERT ERROR)
397#[derive(Debug, Clone)]
398pub struct AssertBlockNode {
399	pub rql: String,
400	pub expect_error: bool,
401	pub message: Option<String>,
402}
403
404// Create Test node
405#[derive(Debug, Clone)]
406pub struct CreateTestNode {
407	pub namespace: Namespace,
408	pub name: Fragment,
409	pub cases: Option<String>,
410	pub body_source: String,
411}
412
413// Run Tests node
414#[derive(Debug, Clone)]
415pub struct RunTestsNode {
416	pub scope: RunTestsScope,
417}
418
419#[derive(Debug, Clone)]
420pub enum RunTestsScope {
421	All,
422	Namespace(ResolvedNamespace),
423	Single(ResolvedNamespace, String),
424}
425
426/// Physical node for CREATE MIGRATION
427#[derive(Debug, Clone)]
428pub struct CreateMigrationNode {
429	pub name: String,
430	pub body_source: String,
431	pub rollback_body_source: Option<String>,
432}
433
434/// Physical node for MIGRATE
435#[derive(Debug, Clone)]
436pub struct MigrateNode {
437	pub target: Option<String>,
438}
439
440/// Physical node for ROLLBACK MIGRATION
441#[derive(Debug, Clone)]
442pub struct RollbackMigrationNode {
443	pub target: Option<String>,
444}
445
446/// Physical node for DISPATCH
447#[derive(Debug, Clone)]
448pub struct DispatchNode {
449	pub namespace: Namespace,
450	pub on_sumtype_id: SumTypeId,
451	pub variant_name: String,
452	pub fields: Vec<(String, Expression)>,
453}
454
455// Create Policy node
456#[derive(Debug, Clone)]
457pub struct CreateColumnPropertyNode {
458	pub namespace: ResolvedNamespace,
459	pub table: Fragment,
460	pub column: Fragment,
461	pub properties: Vec<ColumnPropertyKind>,
462}
463
464#[derive(Debug, Clone)]
465pub enum LetValue {
466	Expression(Expression),
467	Statement(QueryPlan),
468	EmptyFrame,
469}
470
471impl fmt::Display for LetValue {
472	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
473		match self {
474			LetValue::Expression(expr) => write!(f, "{}", expr),
475			LetValue::Statement(query) => write!(f, "Statement({:?})", query),
476			LetValue::EmptyFrame => write!(f, "EmptyFrame"),
477		}
478	}
479}
480
481#[derive(Debug, Clone)]
482pub struct DeclareNode {
483	pub name: Fragment,
484	pub value: LetValue,
485}
486
487#[derive(Debug, Clone)]
488pub enum AssignValue {
489	Expression(Expression),
490	Statement(QueryPlan),
491}
492
493impl fmt::Display for AssignValue {
494	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
495		match self {
496			AssignValue::Expression(expr) => write!(f, "{}", expr),
497			AssignValue::Statement(query) => write!(f, "Statement({:?})", query),
498		}
499	}
500}
501
502#[derive(Debug, Clone)]
503pub struct AssignNode {
504	pub name: Fragment,
505	pub value: AssignValue,
506}
507
508#[derive(Debug, Clone)]
509pub struct VariableNode {
510	pub variable_expr: VariableExpression,
511}
512
513#[derive(Debug, Clone)]
514pub struct EnvironmentNode {}
515
516/// A function parameter in the physical plan
517#[derive(Debug, Clone)]
518pub struct FunctionParameter {
519	/// Parameter name (includes $)
520	pub name: Fragment,
521	/// Optional type constraint
522	pub type_constraint: Option<TypeConstraint>,
523}
524
525#[derive(Debug, Clone)]
526pub struct ScalarizeNode {
527	pub input: Box<QueryPlan>,
528	pub fragment: Fragment,
529}
530
531#[derive(Debug, Clone)]
532pub struct AggregateNode {
533	pub input: Box<QueryPlan>,
534	pub by: Vec<Expression>,
535	pub map: Vec<Expression>,
536}
537
538#[derive(Debug, Clone)]
539pub struct DistinctNode {
540	pub input: Box<QueryPlan>,
541	pub columns: Vec<ResolvedColumn>,
542}
543
544#[derive(Debug, Clone)]
545pub struct AssertNode {
546	pub input: Option<Box<QueryPlan>>,
547	pub conditions: Vec<Expression>,
548	pub message: Option<String>,
549}
550
551#[derive(Debug, Clone)]
552pub struct FilterNode {
553	pub input: Box<QueryPlan>,
554	pub conditions: Vec<Expression>,
555}
556
557#[derive(Debug, Clone)]
558pub struct GateNode {
559	pub input: Box<QueryPlan>,
560	pub conditions: Vec<Expression>,
561}
562
563#[derive(Debug, Clone)]
564pub struct DeleteTableNode {
565	pub input: Option<Box<QueryPlan>>,
566	pub target: Option<ResolvedTable>,
567	pub returning: Option<Vec<Expression>>,
568}
569
570#[derive(Debug, Clone)]
571pub struct InsertTableNode {
572	pub input: Box<QueryPlan>,
573	pub target: ResolvedTable,
574	pub returning: Option<Vec<Expression>>,
575}
576
577#[derive(Debug, Clone)]
578pub struct InsertRingBufferNode {
579	pub input: Box<QueryPlan>,
580	pub target: ResolvedRingBuffer,
581	pub returning: Option<Vec<Expression>>,
582}
583
584#[derive(Debug, Clone)]
585pub struct InsertDictionaryNode {
586	pub input: Box<QueryPlan>,
587	pub target: ResolvedDictionary,
588	pub returning: Option<Vec<Expression>>,
589}
590
591#[derive(Debug, Clone)]
592pub struct UpdateTableNode {
593	pub input: Box<QueryPlan>,
594	pub target: Option<ResolvedTable>,
595	pub returning: Option<Vec<Expression>>,
596}
597
598#[derive(Debug, Clone)]
599pub struct DeleteRingBufferNode {
600	pub input: Option<Box<QueryPlan>>,
601	pub target: ResolvedRingBuffer,
602	pub returning: Option<Vec<Expression>>,
603}
604
605#[derive(Debug, Clone)]
606pub struct UpdateRingBufferNode {
607	pub input: Box<QueryPlan>,
608	pub target: ResolvedRingBuffer,
609	pub returning: Option<Vec<Expression>>,
610}
611
612#[derive(Debug, Clone)]
613pub struct UpdateSeriesNode {
614	pub input: Box<QueryPlan>,
615	pub target: ResolvedSeries,
616	pub returning: Option<Vec<Expression>>,
617}
618
619#[derive(Debug, Clone)]
620pub struct JoinInnerNode {
621	pub left: Box<QueryPlan>,
622	pub right: Box<QueryPlan>,
623	pub on: Vec<Expression>,
624	pub alias: Option<Fragment>,
625}
626
627#[derive(Debug, Clone)]
628pub struct JoinLeftNode {
629	pub left: Box<QueryPlan>,
630	pub right: Box<QueryPlan>,
631	pub on: Vec<Expression>,
632	pub alias: Option<Fragment>,
633}
634
635#[derive(Debug, Clone)]
636pub struct JoinNaturalNode {
637	pub left: Box<QueryPlan>,
638	pub right: Box<QueryPlan>,
639	pub join_type: JoinType,
640	pub alias: Option<Fragment>,
641}
642
643#[derive(Debug, Clone)]
644pub struct AppendQueryNode {
645	pub left: Box<QueryPlan>,
646	pub right: Box<QueryPlan>,
647}
648
649#[derive(Debug, Clone)]
650pub struct SortNode {
651	pub input: Box<QueryPlan>,
652	pub by: Vec<SortKey>,
653}
654
655#[derive(Debug, Clone)]
656pub struct MapNode {
657	pub input: Option<Box<QueryPlan>>,
658	pub map: Vec<Expression>,
659}
660
661#[derive(Debug, Clone)]
662pub struct ExtendNode {
663	pub input: Option<Box<QueryPlan>>,
664	pub extend: Vec<Expression>,
665}
666
667#[derive(Debug, Clone)]
668pub struct PatchNode {
669	pub input: Option<Box<QueryPlan>>,
670	pub assignments: Vec<Expression>,
671}
672
673#[derive(Debug, Clone)]
674pub struct ApplyNode {
675	pub input: Option<Box<QueryPlan>>,
676	pub operator: Fragment, // FIXME becomes OperatorIdentifier
677	pub expressions: Vec<Expression>,
678}
679
680#[derive(Debug, Clone)]
681pub struct InlineDataNode {
682	pub rows: Vec<Vec<AliasExpression>>,
683}
684
685#[derive(Debug, Clone)]
686pub struct IndexScanNode {
687	pub source: ResolvedTable,
688	pub index_name: String,
689}
690
691#[derive(Debug, Clone)]
692pub struct RemoteScanNode {
693	pub address: String,
694	pub token: Option<String>,
695	pub remote_rql: String,
696	pub local_namespace: String,
697	pub remote_name: String,
698	pub variables: Vec<String>,
699}
700
701#[derive(Debug, Clone)]
702pub struct TableScanNode {
703	pub source: ResolvedTable,
704}
705
706#[derive(Debug, Clone)]
707pub struct ViewScanNode {
708	pub source: ResolvedView,
709}
710
711#[derive(Debug, Clone)]
712pub struct RingBufferScanNode {
713	pub source: ResolvedRingBuffer,
714}
715
716#[derive(Debug, Clone)]
717pub struct DictionaryScanNode {
718	pub source: ResolvedDictionary,
719}
720
721#[derive(Debug, Clone)]
722pub struct SeriesScanNode {
723	pub source: ResolvedSeries,
724	pub key_range_start: Option<u64>,
725	pub key_range_end: Option<u64>,
726	pub variant_tag: Option<u8>,
727}
728
729#[derive(Debug, Clone)]
730pub struct InsertSeriesNode {
731	pub input: Box<QueryPlan>,
732	pub target: ResolvedSeries,
733	pub returning: Option<Vec<Expression>>,
734}
735
736#[derive(Debug, Clone)]
737pub struct DeleteSeriesNode {
738	pub input: Option<Box<QueryPlan>>,
739	pub target: ResolvedSeries,
740	pub returning: Option<Vec<Expression>>,
741}
742
743#[derive(Debug, Clone)]
744pub struct GeneratorNode {
745	pub name: Fragment,
746	pub expressions: Vec<Expression>,
747}
748
749#[derive(Debug, Clone)]
750pub struct TableVirtualScanNode {
751	pub source: ResolvedTableVirtual,
752	pub pushdown_context: Option<TableVirtualPushdownContext>,
753}
754
755#[derive(Debug, Clone)]
756pub struct TableVirtualPushdownContext {
757	pub filters: Vec<Expression>,
758	pub projections: Vec<Expression>,
759	pub order_by: Vec<SortKey>,
760	pub limit: Option<usize>,
761}
762
763#[derive(Debug, Clone)]
764pub enum TakeLimit {
765	Literal(usize),
766	Variable(String),
767}
768
769impl fmt::Display for TakeLimit {
770	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
771		match self {
772			TakeLimit::Literal(n) => write!(f, "{}", n),
773			TakeLimit::Variable(name) => write!(f, "${}", name),
774		}
775	}
776}
777
778#[derive(Debug, Clone)]
779pub struct TakeNode {
780	pub input: Box<QueryPlan>,
781	pub take: TakeLimit,
782}
783
784#[derive(Debug, Clone)]
785pub struct WindowNode {
786	pub input: Option<Box<QueryPlan>>,
787	pub kind: WindowKind,
788	pub group_by: Vec<Expression>,
789	pub aggregations: Vec<Expression>,
790	pub ts: Option<String>,
791}
792
793/// O(1) point lookup by row number: `filter rownum == N`
794#[derive(Debug, Clone)]
795pub struct RowPointLookupNode {
796	/// The source to look up in (table, ring buffer, etc.)
797	pub source: ResolvedShape,
798	/// The row number to fetch
799	pub row_number: u64,
800}
801
802/// O(k) list lookup by row numbers: `filter rownum in [a, b, c]`
803#[derive(Debug, Clone)]
804pub struct RowListLookupNode {
805	/// The source to look up in
806	pub source: ResolvedShape,
807	/// The row numbers to fetch
808	pub row_numbers: Vec<u64>,
809}
810
811/// Range scan by row numbers: `filter rownum between X and Y`
812#[derive(Debug, Clone)]
813pub struct RowRangeScanNode {
814	/// The source to scan
815	pub source: ResolvedShape,
816	/// Start of the range (inclusive)
817	pub start: u64,
818	/// End of the range (inclusive)
819	pub end: u64,
820}
821
822/// APPEND statement physical plan node
823#[derive(Debug, Clone)]
824pub enum AppendPhysicalNode {
825	IntoVariable {
826		target: Fragment,
827		source: AppendPhysicalSource,
828	},
829	Query {
830		left: Box<QueryPlan>,
831		right: Box<QueryPlan>,
832	},
833}
834
835/// Source for an APPEND physical plan
836#[derive(Debug, Clone)]
837pub enum AppendPhysicalSource {
838	Statement(Vec<PhysicalPlan>),
839	Inline(InlineDataNode),
840}
841
842#[derive(Debug, Clone)]
843pub struct ConditionalNode {
844	pub condition: Expression,
845	pub then_branch: Box<PhysicalPlan>,
846	pub else_ifs: Vec<ElseIfBranch>,
847	pub else_branch: Option<Box<PhysicalPlan>>,
848}
849
850#[derive(Debug, Clone)]
851pub struct ElseIfBranch {
852	pub condition: Expression,
853	pub then_branch: Box<PhysicalPlan>,
854}
855
856#[derive(Debug, Clone)]
857pub struct LoopPhysicalNode {
858	pub body: Vec<PhysicalPlan>,
859}
860
861#[derive(Debug, Clone)]
862pub struct WhilePhysicalNode {
863	pub condition: Expression,
864	pub body: Vec<PhysicalPlan>,
865}
866
867#[derive(Debug, Clone)]
868pub struct ForPhysicalNode {
869	pub variable_name: Fragment,
870	pub iterable: Box<PhysicalPlan>,
871	pub body: Vec<PhysicalPlan>,
872}
873
874#[derive(Debug, Clone)]
875pub struct DefineFunctionNode {
876	pub name: Fragment,
877	pub parameters: Vec<FunctionParameter>,
878	pub return_type: Option<TypeConstraint>,
879	pub body: Vec<PhysicalPlan>,
880}
881
882#[derive(Debug, Clone)]
883pub struct ReturnNode {
884	pub value: Option<Expression>,
885}
886
887#[derive(Debug, Clone)]
888pub struct CallFunctionNode {
889	pub name: Fragment,
890	pub arguments: Vec<Expression>,
891	pub is_procedure_call: bool,
892}
893
894#[derive(Debug, Clone)]
895pub struct DropNamespaceNode {
896	pub namespace_name: Fragment,
897	pub namespace_id: Option<NamespaceId>,
898	pub if_exists: bool,
899	pub cascade: bool,
900}
901
902#[derive(Debug, Clone)]
903pub struct DropTableNode {
904	pub namespace_name: Fragment,
905	pub table_name: Fragment,
906	pub table_id: Option<TableId>,
907	pub if_exists: bool,
908	pub cascade: bool,
909}
910
911#[derive(Debug, Clone)]
912pub struct DropViewNode {
913	pub namespace_name: Fragment,
914	pub view_name: Fragment,
915	pub view_id: Option<ViewId>,
916	pub if_exists: bool,
917	pub cascade: bool,
918}
919
920#[derive(Debug, Clone)]
921pub struct DropRingBufferNode {
922	pub namespace_name: Fragment,
923	pub ringbuffer_name: Fragment,
924	pub ringbuffer_id: Option<RingBufferId>,
925	pub if_exists: bool,
926	pub cascade: bool,
927}
928
929#[derive(Debug, Clone)]
930pub struct DropDictionaryNode {
931	pub namespace_name: Fragment,
932	pub dictionary_name: Fragment,
933	pub dictionary_id: Option<DictionaryId>,
934	pub if_exists: bool,
935	pub cascade: bool,
936}
937
938#[derive(Debug, Clone)]
939pub struct DropSumTypeNode {
940	pub namespace_name: Fragment,
941	pub sumtype_name: Fragment,
942	pub sumtype_id: Option<SumTypeId>,
943	pub if_exists: bool,
944	pub cascade: bool,
945}
946
947#[derive(Debug, Clone)]
948pub struct DropSubscriptionNode {
949	pub subscription_name: Fragment,
950	pub if_exists: bool,
951	pub cascade: bool,
952}
953
954#[derive(Debug, Clone)]
955pub struct DropSeriesNode {
956	pub namespace_name: Fragment,
957	pub series_name: Fragment,
958	pub series_id: Option<SeriesId>,
959	pub if_exists: bool,
960	pub cascade: bool,
961}
962
963#[derive(Debug, Clone)]
964pub struct CreateIdentityNode {
965	pub name: Fragment,
966}
967
968#[derive(Debug, Clone)]
969pub struct CreateRoleNode {
970	pub name: Fragment,
971}
972
973#[derive(Debug, Clone)]
974pub struct GrantNode {
975	pub role: Fragment,
976	pub user: Fragment,
977}
978
979#[derive(Debug, Clone)]
980pub struct RevokeNode {
981	pub role: Fragment,
982	pub user: Fragment,
983}
984
985#[derive(Debug, Clone)]
986pub struct DropIdentityNode {
987	pub name: Fragment,
988	pub if_exists: bool,
989}
990
991#[derive(Debug, Clone)]
992pub struct DropRoleNode {
993	pub name: Fragment,
994	pub if_exists: bool,
995}
996
997#[derive(Debug, Clone)]
998pub struct CreateAuthenticationNode {
999	pub user: Fragment,
1000	pub method: Fragment,
1001	pub config: collections::HashMap<String, String>,
1002}
1003
1004#[derive(Debug, Clone)]
1005pub struct DropAuthenticationNode {
1006	pub user: Fragment,
1007	pub method: Fragment,
1008	pub if_exists: bool,
1009}
1010
1011#[derive(Debug, Clone)]
1012pub struct CreatePolicyNode {
1013	pub name: Option<Fragment>,
1014	pub target_type: String,
1015	pub scope_namespace: Option<Fragment>,
1016	pub scope_shape: Option<Fragment>,
1017	pub operations: Vec<PolicyOperationNode>,
1018}
1019
1020#[derive(Debug, Clone)]
1021pub struct PolicyOperationNode {
1022	pub operation: String,
1023	pub body_source: String,
1024}
1025
1026#[derive(Debug, Clone)]
1027pub struct AlterPolicyNode {
1028	pub target_type: String,
1029	pub name: Fragment,
1030	pub enable: bool,
1031}
1032
1033#[derive(Debug, Clone)]
1034pub struct DropPolicyNode {
1035	pub target_type: String,
1036	pub name: Fragment,
1037	pub if_exists: bool,
1038}