Skip to main content

reifydb_engine/vm/volcano/
environment.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2025 ReifyDB
3
4use std::sync::Arc;
5
6use reifydb_core::value::column::{columns::Columns, headers::ColumnHeaders};
7use reifydb_transaction::transaction::Transaction;
8
9use crate::{
10	Result,
11	environment::create_env_columns,
12	vm::volcano::query::{QueryContext, QueryNode},
13};
14
15pub(crate) struct EnvironmentNode {
16	context: Option<Arc<QueryContext>>,
17	executed: bool,
18}
19
20impl EnvironmentNode {
21	pub fn new() -> Self {
22		Self {
23			context: None,
24			executed: false,
25		}
26	}
27}
28
29impl QueryNode for EnvironmentNode {
30	fn initialize<'a>(&mut self, _rx: &mut Transaction<'a>, ctx: &QueryContext) -> Result<()> {
31		self.context = Some(Arc::new(ctx.clone()));
32		Ok(())
33	}
34
35	fn next<'a>(&mut self, _rx: &mut Transaction<'a>, _ctx: &mut QueryContext) -> Result<Option<Columns>> {
36		debug_assert!(self.context.is_some(), "EnvironmentNode::next() called before initialize()");
37
38		if self.executed {
39			return Ok(None);
40		}
41
42		let columns = create_env_columns();
43		self.executed = true;
44
45		Ok(Some(columns))
46	}
47
48	fn headers(&self) -> Option<ColumnHeaders> {
49		None
50	}
51}