mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-01-08 06:12:55 +00:00
feat: adds parse options for SQL parser (#3193)
* feat: adds parse options for parser and timezone to scan request * chore: remove timezone in ScanRequest * feat: remove timezone in parse options and adds type checking to parititon columns * fix: comment * chore: apply suggestions Co-authored-by: Yingwen <realevenyag@gmail.com> * fix: format --------- Co-authored-by: Yingwen <realevenyag@gmail.com>
This commit is contained in:
@@ -411,7 +411,7 @@ pub(crate) fn to_alter_expr(
|
||||
mod tests {
|
||||
use session::context::QueryContext;
|
||||
use sql::dialect::GreptimeDbDialect;
|
||||
use sql::parser::ParserContext;
|
||||
use sql::parser::{ParseOptions, ParserContext};
|
||||
use sql::statements::statement::Statement;
|
||||
|
||||
use super::*;
|
||||
@@ -419,10 +419,11 @@ mod tests {
|
||||
#[test]
|
||||
fn test_create_to_expr() {
|
||||
let sql = "CREATE TABLE monitor (host STRING,ts TIMESTAMP,TIME INDEX (ts),PRIMARY KEY(host)) ENGINE=mito WITH(regions=1, ttl='3days', write_buffer_size='1024KB');";
|
||||
let stmt = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {})
|
||||
.unwrap()
|
||||
.pop()
|
||||
.unwrap();
|
||||
let stmt =
|
||||
ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}, ParseOptions::default())
|
||||
.unwrap()
|
||||
.pop()
|
||||
.unwrap();
|
||||
|
||||
let Statement::CreateTable(create_table) = stmt else {
|
||||
unreachable!()
|
||||
|
||||
@@ -632,7 +632,7 @@ fn merge_options(mut table_opts: TableOptions, schema_opts: SchemaNameValue) ->
|
||||
mod test {
|
||||
use session::context::QueryContext;
|
||||
use sql::dialect::GreptimeDbDialect;
|
||||
use sql::parser::ParserContext;
|
||||
use sql::parser::{ParseOptions, ParserContext};
|
||||
use sql::statements::statement::Statement;
|
||||
|
||||
use super::*;
|
||||
@@ -698,7 +698,12 @@ ENGINE=mito",
|
||||
),
|
||||
];
|
||||
for (sql, expected) in cases {
|
||||
let result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}).unwrap();
|
||||
let result = ParserContext::create_with_dialect(
|
||||
sql,
|
||||
&GreptimeDbDialect {},
|
||||
ParseOptions::default(),
|
||||
)
|
||||
.unwrap();
|
||||
match &result[0] {
|
||||
Statement::CreateTable(c) => {
|
||||
let expr = expr_factory::create_to_expr(c, QueryContext::arc()).unwrap();
|
||||
|
||||
@@ -35,7 +35,7 @@ impl StatementExecutor {
|
||||
step: eval.step,
|
||||
query: eval.query,
|
||||
};
|
||||
QueryLanguageParser::parse_promql(&promql).context(ParseQuerySnafu)?
|
||||
QueryLanguageParser::parse_promql(&promql, &query_ctx).context(ParseQuerySnafu)?
|
||||
}
|
||||
Tql::Explain(explain) => {
|
||||
let promql = PromQuery {
|
||||
@@ -43,7 +43,7 @@ impl StatementExecutor {
|
||||
..PromQuery::default()
|
||||
};
|
||||
let params = HashMap::from([("name".to_string(), EXPLAIN_NODE_NAME.to_string())]);
|
||||
QueryLanguageParser::parse_promql(&promql)
|
||||
QueryLanguageParser::parse_promql(&promql, &query_ctx)
|
||||
.context(ParseQuerySnafu)?
|
||||
.post_process(params)
|
||||
.unwrap()
|
||||
@@ -56,7 +56,7 @@ impl StatementExecutor {
|
||||
query: tql_analyze.query,
|
||||
};
|
||||
let params = HashMap::from([("name".to_string(), ANALYZE_NODE_NAME.to_string())]);
|
||||
QueryLanguageParser::parse_promql(&promql)
|
||||
QueryLanguageParser::parse_promql(&promql, &query_ctx)
|
||||
.context(ParseQuerySnafu)?
|
||||
.post_process(params)
|
||||
.unwrap()
|
||||
|
||||
Reference in New Issue
Block a user