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

feat(planner): support udf #5751

Merged
merged 6 commits into from
Jun 6, 2022
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
18 changes: 18 additions & 0 deletions common/ast/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use common_exception::ErrorCode;
use common_exception::Result;

use self::error::DisplayError;
use crate::ast::Expr;
use crate::ast::Statement;
use crate::parser::error::Backtrace;
use crate::parser::statement::statements;
Expand Down Expand Up @@ -52,3 +53,20 @@ pub fn parse_sql<'a>(
Err(nom::Err::Incomplete(_)) => unreachable!(),
}
}

/// Parse udf function into Expr
pub fn parse_expr<'a>(
sql_tokens: &'a [Token<'a>],
backtrace: &'a Backtrace<'a>,
) -> Result<Expr<'a>> {
match expr::expr(Input(sql_tokens, backtrace)) {
Ok((rest, expr)) if rest[0].kind == TokenKind::EOI => Ok(expr),
Ok((rest, _)) => Err(ErrorCode::SyntaxException(
rest[0].display_error("unable to parse rest of the sql".to_string()),
)),
Err(nom::Err::Error(err) | nom::Err::Failure(err)) => {
Err(ErrorCode::SyntaxException(err.display_error(())))
}
Err(nom::Err::Incomplete(_)) => unreachable!(),
}
}
Loading