Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#81] async_recursion 모듈 제거 #82

Merged
merged 1 commit into from
Mar 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ chrono = "0.4.22"
bson = "2.4.0"
colored = "2.0.0"
uuid = "1.1.2"
async-recursion = "1.0.0"
itertools = "0.10.5"

[target.'cfg(windows)'.dependencies]
Expand Down
37 changes: 18 additions & 19 deletions src/executor/reduce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ pub struct ReduceContext {
}

impl Executor {
#[async_recursion::async_recursion]
pub async fn reduce_expression(
&self,
expression: SQLExpression,
Expand All @@ -37,7 +36,7 @@ impl Executor {
SQLExpression::Null => Ok(TableDataFieldType::Null),
SQLExpression::List(list) => {
let futures = list.value.into_iter().map(|e|{self.reduce_expression(e, context.clone())});
let fields = join_all(futures).await.into_iter().collect::<Result<Vec<_>,
let fields = Box::pin(join_all(futures)).await.into_iter().collect::<Result<Vec<_>,
_>>()?;

#[allow(unstable_name_collisions)]
Expand All @@ -47,7 +46,7 @@ impl Executor {
}
SQLExpression::Unary(unary) => match unary.operator {
UnaryOperator::Neg => {
let operand = self.reduce_expression(unary.operand, context).await?;
let operand = Box::pin(self.reduce_expression(unary.operand, context)).await?;

match operand {
TableDataFieldType::Integer(value) => {
Expand Down Expand Up @@ -78,7 +77,7 @@ impl Executor {
}
}
UnaryOperator::Pos => {
let operand = self.reduce_expression(unary.operand, context).await?;
let operand = Box::pin(self.reduce_expression(unary.operand, context)).await?;

match operand {
TableDataFieldType::Integer(_) => Ok(operand),
Expand All @@ -89,7 +88,7 @@ impl Executor {
}
}
UnaryOperator::Not => {
let operand = self.reduce_expression(unary.operand, context).await?;
let operand = Box::pin(self.reduce_expression(unary.operand, context)).await?;

match operand {
TableDataFieldType::Boolean(value) => {
Expand All @@ -102,8 +101,8 @@ impl Executor {
}
},
SQLExpression::Binary(binary) => {
let lhs = self.reduce_expression(binary.lhs.clone(), context.clone()).await?;
let rhs = self.reduce_expression(binary.rhs.clone(), context.clone()).await?;
let lhs = Box::pin(self.reduce_expression(binary.lhs.clone(), context.clone())).await?;
let rhs = Box::pin(self.reduce_expression(binary.rhs.clone(), context.clone())).await?;

if lhs.type_code() != rhs.type_code() {
return Err(TypeError::dyn_boxed(
Expand All @@ -125,14 +124,14 @@ impl Executor {
rhs: right_array[i].clone().into(),
};

match self.reduce_expression(expression.into(), context.clone()).await {
match Box::pin(self.reduce_expression(expression.into(), context.clone())).await {
Ok(expression)=> Ok(expression),
Err(error)=>Err(error),
}
}
});

let result = join_all(futures).await.into_iter().collect::<Result<Vec<_>, _>>()?;
let result = Box::pin(join_all(futures)).await.into_iter().collect::<Result<Vec<_>, _>>()?;
return Ok(TableDataFieldType::Array(result));
} else {
let futures = left_array.iter().map(|e|async {
Expand All @@ -142,13 +141,13 @@ impl Executor {
rhs: rhs.clone().into(),
};

match self.reduce_expression(expression.into(), context.clone()).await {
match Box::pin(self.reduce_expression(expression.into(), context.clone())).await {
Ok(expression)=> Ok(expression),
Err(error)=>Err(error),
}
});

let result = join_all(futures).await.into_iter().collect::<Result<Vec<_>, _>>()?;
let result = Box::pin(join_all(futures)).await.into_iter().collect::<Result<Vec<_>, _>>()?;
return Ok(TableDataFieldType::Array(result));
}
} else if let TableDataFieldType::Array(ref right_array) = rhs{
Expand All @@ -159,13 +158,13 @@ impl Executor {
rhs: e.clone().into(),
};

match self.reduce_expression(expression.into(), context.clone()).await {
match Box::pin(self.reduce_expression(expression.into(), context.clone())).await {
Ok(expression)=> Ok(expression),
Err(error)=>Err(error),
}
});

let result = join_all(futures).await.into_iter().collect::<Result<Vec<_>, _>>()?;
let result = Box::pin(join_all(futures)).await.into_iter().collect::<Result<Vec<_>, _>>()?;
return Ok(TableDataFieldType::Array(result));
}

Expand Down Expand Up @@ -373,17 +372,17 @@ impl Executor {
}
}
SQLExpression::Between(between) => {
let _a = self.reduce_expression(between.a, context.clone()).await?;
let _x = self.reduce_expression(between.x, context.clone()).await?;
let _y = self.reduce_expression(between.y, context).await?;
let _a = Box::pin(self.reduce_expression(between.a, context.clone())).await?;
let _x = Box::pin(self.reduce_expression(between.x, context.clone())).await?;
let _y = Box::pin(self.reduce_expression(between.y, context)).await?;

//Ok(TableDataFieldType::Boolean(x <= a && a <= y ))

unimplemented!("미구현")
},
SQLExpression::NotBetween(_between) => unimplemented!("미구현"),
SQLExpression::Parentheses(paren) => {
self.reduce_expression(paren.expression, context).await
Box::pin(self.reduce_expression(paren.expression, context)).await
}
SQLExpression::FunctionCall(call) => {
match call.function {
Expand All @@ -399,7 +398,7 @@ impl Executor {
}

let argument = call.arguments[0].clone();
let value = self.reduce_expression(argument, context.clone()).await?;
let value = Box::pin(self.reduce_expression(argument, context.clone())).await?;

match value {
TableDataFieldType::Array(array) => {
Expand Down Expand Up @@ -445,7 +444,7 @@ impl Executor {
}

let argument = call.arguments[0].clone();
let value = self.reduce_expression(argument, context.clone()).await?;
let value = Box::pin(self.reduce_expression(argument, context.clone())).await?;

match value {
TableDataFieldType::Array(array) => {
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async fn main() -> Result<(), Box<dyn Error + Send>> {

match args.action {
SubCommand::Init(init) => {
let init_option = init.init;
let _init_option = init.init;

let executor = Executor::new();

Expand Down
Loading