Skip to content

Commit

Permalink
fix: Minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
can-keklik committed Nov 29, 2024
1 parent 198cbec commit 28f36eb
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lykiadb-server/src/plan/planner.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::engine::{error::ExecutionError, interpreter::{HaltReason, Interpreter}};
use crate::{engine::{error::ExecutionError, interpreter::{HaltReason, Interpreter}}, value::RV};

use lykiadb_lang::ast::{
expr::Expr,
Expand Down Expand Up @@ -75,6 +75,10 @@ impl<'a> Planner<'a> {
Ok(node)
}

fn eval_constant(&mut self, expr: &Expr) -> Result<RV, HaltReason> {
self.interpreter.visit_expr(expr)
}

fn build_select(&mut self, query: &SqlSelect) -> Result<Node, HaltReason> {
let mut node: Node = self.build_select_core(&query.core)?;

Expand All @@ -92,19 +96,15 @@ impl<'a> Planner<'a> {
if let Some(offset) = &limit.offset {
node = Node::Offset {
source: Box::new(node),
offset: self
.interpreter
.visit_expr(offset)?
offset: self.eval_constant(offset)?
.as_number()
.expect("Offset is not correct")
.floor() as usize,
}
}
node = Node::Limit {
source: Box::new(node),
limit: self
.interpreter
.visit_expr(&limit.count)?
limit: self.eval_constant(&limit.count)?
.as_number()
.expect("Limit is not correct")
.floor() as usize,
Expand Down

0 comments on commit 28f36eb

Please sign in to comment.