Skip to main content

reifydb_rql/
nodes.rs

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