mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-05-29 19:30:37 +00:00
build: bump rust edition to 2024 (#6920)
* bump edition Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * format Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * gen keyword Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * lifetime and env var Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * one more gen fix Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * lifetime of temporaries in tail expressions Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * format again Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * clippy nested if Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * clippy let and return Signed-off-by: Ruihang Xia <waynestxia@gmail.com> --------- Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
This commit is contained in:
@@ -13,10 +13,10 @@
|
||||
// limitations under the License.
|
||||
|
||||
pub use sqlparser::ast::{
|
||||
visit_expressions_mut, visit_statements_mut, BinaryOperator, ColumnDef, ColumnOption,
|
||||
ColumnOptionDef, DataType, Expr, Function, FunctionArg, FunctionArgExpr, FunctionArguments,
|
||||
Ident, ObjectName, ObjectNamePart, SqlOption, TableConstraint, TimezoneInfo, Value,
|
||||
ValueWithSpan, Visit, VisitMut, Visitor, VisitorMut,
|
||||
BinaryOperator, ColumnDef, ColumnOption, ColumnOptionDef, DataType, Expr, Function,
|
||||
FunctionArg, FunctionArgExpr, FunctionArguments, Ident, ObjectName, ObjectNamePart, SqlOption,
|
||||
TableConstraint, TimezoneInfo, Value, ValueWithSpan, Visit, VisitMut, Visitor, VisitorMut,
|
||||
visit_expressions_mut, visit_statements_mut,
|
||||
};
|
||||
|
||||
pub trait ObjectNamePartExt {
|
||||
|
||||
@@ -106,27 +106,21 @@ mod tests {
|
||||
#[test]
|
||||
fn test_invalid_admin_statement() {
|
||||
let sql = "ADMIN";
|
||||
assert!(ParserContext::create_with_dialect(
|
||||
sql,
|
||||
&GreptimeDbDialect {},
|
||||
ParseOptions::default()
|
||||
)
|
||||
.is_err());
|
||||
assert!(
|
||||
ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}, ParseOptions::default())
|
||||
.is_err()
|
||||
);
|
||||
|
||||
let sql = "ADMIN test";
|
||||
assert!(ParserContext::create_with_dialect(
|
||||
sql,
|
||||
&GreptimeDbDialect {},
|
||||
ParseOptions::default()
|
||||
)
|
||||
.is_err());
|
||||
assert!(
|
||||
ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}, ParseOptions::default())
|
||||
.is_err()
|
||||
);
|
||||
|
||||
let sql = "ADMIN test test";
|
||||
assert!(ParserContext::create_with_dialect(
|
||||
sql,
|
||||
&GreptimeDbDialect {},
|
||||
ParseOptions::default()
|
||||
)
|
||||
.is_err());
|
||||
assert!(
|
||||
ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}, ParseOptions::default())
|
||||
.is_err()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ use std::collections::HashMap;
|
||||
|
||||
use common_query::AddColumnLocation;
|
||||
use datatypes::schema::COLUMN_FULLTEXT_CHANGE_OPT_KEY_ENABLE;
|
||||
use snafu::{ensure, ResultExt};
|
||||
use snafu::{ResultExt, ensure};
|
||||
use sqlparser::ast::Ident;
|
||||
use sqlparser::keywords::Keyword;
|
||||
use sqlparser::parser::{Parser, ParserError};
|
||||
@@ -150,7 +150,7 @@ impl ParserContext<'_> {
|
||||
return Err(ParserError::ParserError(format!(
|
||||
"expect table name, actual: {new_table_name_obj}"
|
||||
)))
|
||||
.context(error::SyntaxSnafu)
|
||||
.context(error::SyntaxSnafu);
|
||||
}
|
||||
};
|
||||
AlterTableOperation::RenameTable { new_table_name }
|
||||
@@ -642,11 +642,13 @@ mod tests {
|
||||
assert_eq!(add_columns.len(), 1);
|
||||
assert_eq!("tagk_i", add_columns[0].column_def.name.value);
|
||||
assert_eq!(DataType::String(None), add_columns[0].column_def.data_type);
|
||||
assert!(add_columns[0]
|
||||
.column_def
|
||||
.options
|
||||
.iter()
|
||||
.any(|o| matches!(o.option, ColumnOption::Null)));
|
||||
assert!(
|
||||
add_columns[0]
|
||||
.column_def
|
||||
.options
|
||||
.iter()
|
||||
.any(|o| matches!(o.option, ColumnOption::Null))
|
||||
);
|
||||
assert_eq!(&None, &add_columns[0].location);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
@@ -676,11 +678,13 @@ mod tests {
|
||||
AlterTableOperation::AddColumns { add_columns } => {
|
||||
assert_eq!("tagk_i", add_columns[0].column_def.name.value);
|
||||
assert_eq!(DataType::String(None), add_columns[0].column_def.data_type);
|
||||
assert!(add_columns[0]
|
||||
.column_def
|
||||
.options
|
||||
.iter()
|
||||
.any(|o| matches!(o.option, ColumnOption::Null)));
|
||||
assert!(
|
||||
add_columns[0]
|
||||
.column_def
|
||||
.options
|
||||
.iter()
|
||||
.any(|o| matches!(o.option, ColumnOption::Null))
|
||||
);
|
||||
assert_eq!(&Some(AddColumnLocation::First), &add_columns[0].location);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
@@ -961,7 +965,10 @@ mod tests {
|
||||
ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}, ParseOptions::default())
|
||||
.unwrap_err();
|
||||
let err = result.output_msg();
|
||||
assert_eq!(err, "Invalid SQL syntax: sql parser error: Expected ADD or DROP or MODIFY or RENAME or SET after ALTER TABLE, found: table_t");
|
||||
assert_eq!(
|
||||
err,
|
||||
"Invalid SQL syntax: sql parser error: Expected ADD or DROP or MODIFY or RENAME or SET after ALTER TABLE, found: table_t"
|
||||
);
|
||||
|
||||
let sql = "ALTER TABLE test_table RENAME table_t";
|
||||
let mut result =
|
||||
@@ -1323,14 +1330,20 @@ mod tests {
|
||||
ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}, ParseOptions::default())
|
||||
.unwrap_err();
|
||||
let err = result.output_msg();
|
||||
assert_eq!(err, "Invalid SQL syntax: sql parser error: Expected FULLTEXT OR INVERTED OR SKIPPING INDEX, found: 100");
|
||||
assert_eq!(
|
||||
err,
|
||||
"Invalid SQL syntax: sql parser error: Expected FULLTEXT OR INVERTED OR SKIPPING INDEX, found: 100"
|
||||
);
|
||||
|
||||
let sql = "ALTER TABLE test_table MODIFY COLUMN a SET DEFAULT 100, b SET DEFAULT 200";
|
||||
let result =
|
||||
ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}, ParseOptions::default())
|
||||
.unwrap_err();
|
||||
let err = result.output_msg();
|
||||
assert_eq!(err, "Invalid SQL syntax: sql parser error: Expected: MODIFY, found: b at Line: 1, Column: 57");
|
||||
assert_eq!(
|
||||
err,
|
||||
"Invalid SQL syntax: sql parser error: Expected: MODIFY, found: b at Line: 1, Column: 57"
|
||||
);
|
||||
|
||||
let sql = "ALTER TABLE test_table MODIFY COLUMN a SET DEFAULT 100, MODIFY COLUMN b DROP DEFAULT 200";
|
||||
let result =
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use snafu::{ensure, ResultExt};
|
||||
use snafu::{ResultExt, ensure};
|
||||
use sqlparser::ast::Ident;
|
||||
use sqlparser::parser::Parser;
|
||||
use sqlparser::tokenizer::Token;
|
||||
@@ -6,13 +6,13 @@ use sqlparser::tokenizer::Token;
|
||||
use crate::error::{self, DuplicateClauseSnafu, InvalidSqlSnafu, Result};
|
||||
use crate::parser::ParserContext;
|
||||
use crate::parsers::create_parser::trigger::{ANNOTATIONS, LABELS, NOTIFY, ON};
|
||||
use crate::statements::OptionMap;
|
||||
use crate::statements::alter::trigger::{
|
||||
AlterTrigger, AlterTriggerOperation, AnnotationChange, AnnotationOperations, LabelChange,
|
||||
LabelOperations, NotifyChannelChange, NotifyChannelOperations,
|
||||
};
|
||||
use crate::statements::create::trigger::NotifyChannel;
|
||||
use crate::statements::statement::Statement;
|
||||
use crate::statements::OptionMap;
|
||||
|
||||
/// Some keywords about trigger.
|
||||
pub const RENAME: &str = "RENAME";
|
||||
@@ -119,7 +119,7 @@ impl<'a> ParserContext<'a> {
|
||||
return self.expected(
|
||||
"`LABELS`, `ANNOTATIONS` or `NOTIFY` keyword after `SET`",
|
||||
next_token,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -542,10 +542,10 @@ mod tests {
|
||||
use crate::dialect::GreptimeDbDialect;
|
||||
use crate::parser::ParserContext;
|
||||
use crate::parsers::alter_parser::trigger::{apply_label_change, apply_label_replacement};
|
||||
use crate::statements::OptionMap;
|
||||
use crate::statements::alter::trigger::{LabelChange, LabelOperations};
|
||||
use crate::statements::create::trigger::TriggerOn;
|
||||
use crate::statements::statement::Statement;
|
||||
use crate::statements::OptionMap;
|
||||
|
||||
#[test]
|
||||
fn test_parse_alter_without_alter_options() {
|
||||
|
||||
@@ -321,7 +321,10 @@ mod tests {
|
||||
Test {
|
||||
sql: "COPY catalog0.schema0.tbl FROM 'tbl_file.parquet' WITH (PATTERN = 'demo.*') CONNECTION (FOO='Bar', ONE='two')",
|
||||
expected_pattern: Some("demo.*".into()),
|
||||
expected_connection: [("foo","Bar"),("one","two")].into_iter().map(|(k,v)|{(k.to_string(),v.to_string())}).collect()
|
||||
expected_connection: [("foo", "Bar"), ("one", "two")]
|
||||
.into_iter()
|
||||
.map(|(k, v)| (k.to_string(), v.to_string()))
|
||||
.collect(),
|
||||
},
|
||||
];
|
||||
|
||||
@@ -367,11 +370,17 @@ mod tests {
|
||||
},
|
||||
Test {
|
||||
sql: "COPY catalog0.schema0.tbl TO 'tbl_file.parquet' CONNECTION (FOO='Bar', ONE='two')",
|
||||
expected_connection: [("foo","Bar"),("one","two")].into_iter().map(|(k,v)|{(k.to_string(),v.to_string())}).collect()
|
||||
expected_connection: [("foo", "Bar"), ("one", "two")]
|
||||
.into_iter()
|
||||
.map(|(k, v)| (k.to_string(), v.to_string()))
|
||||
.collect(),
|
||||
},
|
||||
Test {
|
||||
sql:"COPY catalog0.schema0.tbl TO 'tbl_file.parquet' WITH (FORMAT = 'parquet') CONNECTION (FOO='Bar', ONE='two')",
|
||||
expected_connection: [("foo","Bar"),("one","two")].into_iter().map(|(k,v)|{(k.to_string(),v.to_string())}).collect()
|
||||
sql: "COPY catalog0.schema0.tbl TO 'tbl_file.parquet' WITH (FORMAT = 'parquet') CONNECTION (FOO='Bar', ONE='two')",
|
||||
expected_connection: [("foo", "Bar"), ("one", "two")]
|
||||
.into_iter()
|
||||
.map(|(k, v)| (k.to_string(), v.to_string()))
|
||||
.collect(),
|
||||
},
|
||||
];
|
||||
|
||||
@@ -514,32 +523,38 @@ mod tests {
|
||||
{
|
||||
let sql = "COPY SELECT * FROM tbl WHERE ts > 10 TO 'tbl_file.parquet' WITH (FORMAT = 'parquet') CONNECTION (FOO='Bar', ONE='two')";
|
||||
|
||||
assert!(ParserContext::create_with_dialect(
|
||||
sql,
|
||||
&GreptimeDbDialect {},
|
||||
ParseOptions::default()
|
||||
assert!(
|
||||
ParserContext::create_with_dialect(
|
||||
sql,
|
||||
&GreptimeDbDialect {},
|
||||
ParseOptions::default()
|
||||
)
|
||||
.is_err()
|
||||
)
|
||||
.is_err())
|
||||
}
|
||||
{
|
||||
let sql = "COPY SELECT * FROM tbl WHERE ts > 10) TO 'tbl_file.parquet' WITH (FORMAT = 'parquet') CONNECTION (FOO='Bar', ONE='two')";
|
||||
|
||||
assert!(ParserContext::create_with_dialect(
|
||||
sql,
|
||||
&GreptimeDbDialect {},
|
||||
ParseOptions::default()
|
||||
assert!(
|
||||
ParserContext::create_with_dialect(
|
||||
sql,
|
||||
&GreptimeDbDialect {},
|
||||
ParseOptions::default()
|
||||
)
|
||||
.is_err()
|
||||
)
|
||||
.is_err())
|
||||
}
|
||||
{
|
||||
let sql = "COPY (SELECT * FROM tbl WHERE ts > 10 TO 'tbl_file.parquet' WITH (FORMAT = 'parquet') CONNECTION (FOO='Bar', ONE='two')";
|
||||
|
||||
assert!(ParserContext::create_with_dialect(
|
||||
sql,
|
||||
&GreptimeDbDialect {},
|
||||
ParseOptions::default()
|
||||
assert!(
|
||||
ParserContext::create_with_dialect(
|
||||
sql,
|
||||
&GreptimeDbDialect {},
|
||||
ParseOptions::default()
|
||||
)
|
||||
.is_err()
|
||||
)
|
||||
.is_err())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ use datafusion_common::ScalarValue;
|
||||
use datatypes::arrow::datatypes::{DataType as ArrowDataType, IntervalUnit};
|
||||
use datatypes::data_type::ConcreteDataType;
|
||||
use itertools::Itertools;
|
||||
use snafu::{ensure, OptionExt, ResultExt};
|
||||
use snafu::{OptionExt, ResultExt, ensure};
|
||||
use sqlparser::ast::{ColumnOption, ColumnOptionDef, DataType, Expr};
|
||||
use sqlparser::dialect::keywords::Keyword;
|
||||
use sqlparser::keywords::ALL_KEYWORDS;
|
||||
@@ -38,7 +38,7 @@ use crate::error::{
|
||||
InvalidSqlSnafu, InvalidTableOptionSnafu, InvalidTimeIndexSnafu, MissingTimeIndexSnafu, Result,
|
||||
SyntaxSnafu, UnexpectedSnafu, UnsupportedSnafu,
|
||||
};
|
||||
use crate::parser::{ParserContext, FLOW};
|
||||
use crate::parser::{FLOW, ParserContext};
|
||||
use crate::parsers::tql_parser;
|
||||
use crate::parsers::utils::{
|
||||
self, validate_column_fulltext_create_option, validate_column_skipping_index_create_option,
|
||||
@@ -49,7 +49,7 @@ use crate::statements::create::{
|
||||
};
|
||||
use crate::statements::statement::Statement;
|
||||
use crate::statements::transform::type_alias::get_data_type_by_alias_name;
|
||||
use crate::statements::{sql_data_type_to_concrete_data_type, OptionMap};
|
||||
use crate::statements::{OptionMap, sql_data_type_to_concrete_data_type};
|
||||
use crate::util::{location_to_index, parse_option_string};
|
||||
|
||||
pub const ENGINE: &str = "ENGINE";
|
||||
@@ -213,13 +213,14 @@ impl<'a> ParserContext<'a> {
|
||||
}
|
||||
);
|
||||
}
|
||||
if let Some(append_mode) = options.get("append_mode") {
|
||||
if append_mode == "true" && options.contains_key("merge_mode") {
|
||||
return InvalidDatabaseOptionSnafu {
|
||||
key: "merge_mode".to_string(),
|
||||
}
|
||||
.fail();
|
||||
if let Some(append_mode) = options.get("append_mode")
|
||||
&& append_mode == "true"
|
||||
&& options.contains_key("merge_mode")
|
||||
{
|
||||
return InvalidDatabaseOptionSnafu {
|
||||
key: "merge_mode".to_string(),
|
||||
}
|
||||
.fail();
|
||||
}
|
||||
|
||||
Ok(Statement::CreateDatabase(CreateDatabase {
|
||||
@@ -320,7 +321,7 @@ impl<'a> ParserContext<'a> {
|
||||
return self
|
||||
.parser
|
||||
.expected("string", unexpected)
|
||||
.context(SyntaxSnafu)
|
||||
.context(SyntaxSnafu);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -554,8 +555,8 @@ impl<'a> ParserContext<'a> {
|
||||
|
||||
let mut time_index_opt_idx = None;
|
||||
for (index, opt) in column.options().iter().enumerate() {
|
||||
if let ColumnOption::DialectSpecific(tokens) = &opt.option {
|
||||
if matches!(
|
||||
if let ColumnOption::DialectSpecific(tokens) = &opt.option
|
||||
&& matches!(
|
||||
&tokens[..],
|
||||
[
|
||||
Token::Word(Word {
|
||||
@@ -567,21 +568,21 @@ impl<'a> ParserContext<'a> {
|
||||
..
|
||||
})
|
||||
]
|
||||
) {
|
||||
ensure!(
|
||||
time_index_opt_idx.is_none(),
|
||||
InvalidColumnOptionSnafu {
|
||||
name: column.name().to_string(),
|
||||
msg: "duplicated time index",
|
||||
}
|
||||
);
|
||||
time_index_opt_idx = Some(index);
|
||||
)
|
||||
{
|
||||
ensure!(
|
||||
time_index_opt_idx.is_none(),
|
||||
InvalidColumnOptionSnafu {
|
||||
name: column.name().to_string(),
|
||||
msg: "duplicated time index",
|
||||
}
|
||||
);
|
||||
time_index_opt_idx = Some(index);
|
||||
|
||||
let constraint = TableConstraint::TimeIndex {
|
||||
column: Ident::new(column.name().value.clone()),
|
||||
};
|
||||
constraints.push(constraint);
|
||||
}
|
||||
let constraint = TableConstraint::TimeIndex {
|
||||
column: Ident::new(column.name().value.clone()),
|
||||
};
|
||||
constraints.push(constraint);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1310,10 +1311,12 @@ mod tests {
|
||||
let sql = "create database";
|
||||
let result =
|
||||
ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}, ParseOptions::default());
|
||||
assert!(result
|
||||
.unwrap_err()
|
||||
.to_string()
|
||||
.contains("Unexpected token while parsing SQL statement"));
|
||||
assert!(
|
||||
result
|
||||
.unwrap_err()
|
||||
.to_string()
|
||||
.contains("Unexpected token while parsing SQL statement")
|
||||
);
|
||||
|
||||
let sql = "create database prometheus";
|
||||
let stmts =
|
||||
@@ -1735,10 +1738,12 @@ PARTITION ON COLUMNS(x) ()
|
||||
ENGINE=mito";
|
||||
let result =
|
||||
ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}, ParseOptions::default());
|
||||
assert!(result
|
||||
.unwrap_err()
|
||||
.to_string()
|
||||
.contains("Partition column \"x\" not defined"));
|
||||
assert!(
|
||||
result
|
||||
.unwrap_err()
|
||||
.to_string()
|
||||
.contains("Partition column \"x\" not defined")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1990,10 +1995,12 @@ ENGINE=mito";
|
||||
ParseOptions::default(),
|
||||
);
|
||||
|
||||
assert!(result1
|
||||
.unwrap_err()
|
||||
.to_string()
|
||||
.contains("time index column data type should be timestamp"));
|
||||
assert!(
|
||||
result1
|
||||
.unwrap_err()
|
||||
.to_string()
|
||||
.contains("time index column data type should be timestamp")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -2146,10 +2153,12 @@ PARTITION COLUMNS(c, a) (
|
||||
ENGINE=mito";
|
||||
let result =
|
||||
ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}, ParseOptions::default());
|
||||
assert!(result
|
||||
.unwrap_err()
|
||||
.output_msg()
|
||||
.contains("sql parser error: Expected: ON, found: COLUMNS"));
|
||||
assert!(
|
||||
result
|
||||
.unwrap_err()
|
||||
.output_msg()
|
||||
.contains("sql parser error: Expected: ON, found: COLUMNS")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -2395,12 +2404,13 @@ CREATE TABLE log (
|
||||
if let Statement::CreateTable(c) = &result1[0] {
|
||||
c.columns.iter().for_each(|col| {
|
||||
if col.name().value == "msg" {
|
||||
assert!(col
|
||||
.extensions
|
||||
.fulltext_index_options
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.is_empty());
|
||||
assert!(
|
||||
col.extensions
|
||||
.fulltext_index_options
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.is_empty()
|
||||
);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
@@ -2474,10 +2484,12 @@ CREATE TABLE log (
|
||||
let result =
|
||||
ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}, ParseOptions::default());
|
||||
assert!(result.is_err());
|
||||
assert!(result
|
||||
.unwrap_err()
|
||||
.to_string()
|
||||
.contains("FULLTEXT index only supports string type"));
|
||||
assert!(
|
||||
result
|
||||
.unwrap_err()
|
||||
.to_string()
|
||||
.contains("FULLTEXT index only supports string type")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -2490,10 +2502,12 @@ CREATE TABLE log (
|
||||
let result =
|
||||
ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}, ParseOptions::default());
|
||||
assert!(result.is_err());
|
||||
assert!(result
|
||||
.unwrap_err()
|
||||
.to_string()
|
||||
.contains("duplicated FULLTEXT INDEX option"));
|
||||
assert!(
|
||||
result
|
||||
.unwrap_err()
|
||||
.to_string()
|
||||
.contains("duplicated FULLTEXT INDEX option")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -2506,10 +2520,12 @@ CREATE TABLE log (
|
||||
let result =
|
||||
ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}, ParseOptions::default());
|
||||
assert!(result.is_err());
|
||||
assert!(result
|
||||
.unwrap_err()
|
||||
.to_string()
|
||||
.contains("invalid FULLTEXT INDEX option"));
|
||||
assert!(
|
||||
result
|
||||
.unwrap_err()
|
||||
.to_string()
|
||||
.contains("invalid FULLTEXT INDEX option")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -2526,12 +2542,13 @@ CREATE TABLE log (
|
||||
if let Statement::CreateTable(c) = &result[0] {
|
||||
c.columns.iter().for_each(|col| {
|
||||
if col.name().value == "msg" {
|
||||
assert!(!col
|
||||
.extensions
|
||||
.skipping_index_options
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.is_empty());
|
||||
assert!(
|
||||
!col.extensions
|
||||
.skipping_index_options
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.is_empty()
|
||||
);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
@@ -2550,12 +2567,13 @@ CREATE TABLE log (
|
||||
if let Statement::CreateTable(c) = &result[0] {
|
||||
c.columns.iter().for_each(|col| {
|
||||
if col.name().value == "msg" {
|
||||
assert!(col
|
||||
.extensions
|
||||
.skipping_index_options
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.is_empty());
|
||||
assert!(
|
||||
col.extensions
|
||||
.skipping_index_options
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.is_empty()
|
||||
);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
@@ -2748,10 +2766,12 @@ CREATE TABLE log (
|
||||
&mut extensions,
|
||||
);
|
||||
assert!(result.is_err());
|
||||
assert!(result
|
||||
.unwrap_err()
|
||||
.to_string()
|
||||
.contains("FULLTEXT index only supports string type"));
|
||||
assert!(
|
||||
result
|
||||
.unwrap_err()
|
||||
.to_string()
|
||||
.contains("FULLTEXT index only supports string type")
|
||||
);
|
||||
}
|
||||
|
||||
// Test fulltext index with invalid option (won't fail, the parser doesn't check the option's content)
|
||||
@@ -2810,10 +2830,12 @@ CREATE TABLE log (
|
||||
&mut extensions,
|
||||
);
|
||||
assert!(result.is_err());
|
||||
assert!(result
|
||||
.unwrap_err()
|
||||
.to_string()
|
||||
.contains("INVERTED index doesn't support options"));
|
||||
assert!(
|
||||
result
|
||||
.unwrap_err()
|
||||
.to_string()
|
||||
.contains("INVERTED index doesn't support options")
|
||||
);
|
||||
}
|
||||
|
||||
// Test multiple indices
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::collections::HashMap;
|
||||
use std::time::Duration;
|
||||
|
||||
use snafu::{ensure, OptionExt, ResultExt};
|
||||
use snafu::{OptionExt, ResultExt, ensure};
|
||||
use sqlparser::keywords::Keyword;
|
||||
use sqlparser::parser::Parser;
|
||||
use sqlparser::tokenizer::Token;
|
||||
@@ -10,11 +10,11 @@ use crate::error;
|
||||
use crate::error::Result;
|
||||
use crate::parser::ParserContext;
|
||||
use crate::parsers::utils::convert_month_day_nano_to_duration;
|
||||
use crate::statements::OptionMap;
|
||||
use crate::statements::create::trigger::{
|
||||
AlertManagerWebhook, ChannelType, CreateTrigger, NotifyChannel, TriggerOn,
|
||||
};
|
||||
use crate::statements::statement::Statement;
|
||||
use crate::statements::OptionMap;
|
||||
use crate::util::parse_option_string;
|
||||
|
||||
/// Some keywords about trigger.
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use snafu::{ensure, ResultExt};
|
||||
use snafu::{ResultExt, ensure};
|
||||
use sqlparser::keywords::Keyword;
|
||||
use sqlparser::tokenizer::Token;
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use snafu::{ensure, ResultExt};
|
||||
use snafu::{ResultExt, ensure};
|
||||
use sqlparser::keywords::Keyword;
|
||||
|
||||
use crate::error::{self, InvalidTableNameSnafu, Result};
|
||||
|
||||
@@ -12,12 +12,12 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use snafu::{ensure, ResultExt};
|
||||
use snafu::{ResultExt, ensure};
|
||||
use sqlparser::dialect::keywords::Keyword;
|
||||
use sqlparser::tokenizer::Token;
|
||||
|
||||
use crate::error::{self, InvalidFlowNameSnafu, InvalidTableNameSnafu, Result};
|
||||
use crate::parser::{ParserContext, FLOW};
|
||||
use crate::parser::{FLOW, ParserContext};
|
||||
#[cfg(feature = "enterprise")]
|
||||
use crate::statements::drop::trigger::DropTrigger;
|
||||
use crate::statements::drop::{DropDatabase, DropFlow, DropTable, DropView};
|
||||
|
||||
@@ -53,9 +53,11 @@ mod tests {
|
||||
let result =
|
||||
ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}, ParseOptions::default());
|
||||
assert!(result.is_err());
|
||||
assert!(result
|
||||
.unwrap_err()
|
||||
.output_msg()
|
||||
.contains("Expected: an expression"));
|
||||
assert!(
|
||||
result
|
||||
.unwrap_err()
|
||||
.output_msg()
|
||||
.contains("Expected: an expression")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#[cfg(feature = "enterprise")]
|
||||
pub mod trigger;
|
||||
|
||||
use snafu::{ensure, ResultExt};
|
||||
use snafu::{ResultExt, ensure};
|
||||
use sqlparser::keywords::Keyword;
|
||||
use sqlparser::tokenizer::Token;
|
||||
|
||||
@@ -876,7 +876,10 @@ mod tests {
|
||||
let result =
|
||||
ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}, ParseOptions::default());
|
||||
let error = result.unwrap_err();
|
||||
assert_eq!("Unexpected token while parsing SQL statement, expected: '{FROM | IN} table', found: EOF", error.to_string());
|
||||
assert_eq!(
|
||||
"Unexpected token while parsing SQL statement, expected: '{FROM | IN} table', found: EOF",
|
||||
error.to_string()
|
||||
);
|
||||
|
||||
let sql = "SHOW COLUMNS from test";
|
||||
let result =
|
||||
@@ -936,7 +939,10 @@ mod tests {
|
||||
let result =
|
||||
ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}, ParseOptions::default());
|
||||
let error = result.unwrap_err();
|
||||
assert_eq!("Unexpected token while parsing SQL statement, expected: '{FROM | IN} table', found: EOF", error.to_string());
|
||||
assert_eq!(
|
||||
"Unexpected token while parsing SQL statement, expected: '{FROM | IN} table', found: EOF",
|
||||
error.to_string()
|
||||
);
|
||||
|
||||
let sql = "SHOW INDEX from test";
|
||||
let result =
|
||||
@@ -992,7 +998,10 @@ mod tests {
|
||||
let result =
|
||||
ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}, ParseOptions::default());
|
||||
let error = result.unwrap_err();
|
||||
assert_eq!("Unexpected token while parsing SQL statement, expected: '{FROM | IN} table', found: EOF", error.to_string());
|
||||
assert_eq!(
|
||||
"Unexpected token while parsing SQL statement, expected: '{FROM | IN} table', found: EOF",
|
||||
error.to_string()
|
||||
);
|
||||
|
||||
let sql = "SHOW REGION from test";
|
||||
let result =
|
||||
|
||||
@@ -325,7 +325,10 @@ mod tests {
|
||||
assert_eq!(eval.end, "10");
|
||||
assert_eq!(eval.step, "1s");
|
||||
assert_eq!(eval.lookback, None);
|
||||
assert_eq!(eval.query, "http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m");
|
||||
assert_eq!(
|
||||
eval.query,
|
||||
"http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m"
|
||||
);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
};
|
||||
@@ -352,7 +355,10 @@ mod tests {
|
||||
assert_eq!(eval.end, "10");
|
||||
assert_eq!(eval.step, "1s");
|
||||
assert_eq!(eval.lookback, None);
|
||||
assert_eq!(eval.query, "http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m");
|
||||
assert_eq!(
|
||||
eval.query,
|
||||
"http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m"
|
||||
);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
};
|
||||
@@ -366,7 +372,10 @@ mod tests {
|
||||
assert_eq!(eval.end, "15");
|
||||
assert_eq!(eval.step, "1s");
|
||||
assert_eq!(eval.lookback, None);
|
||||
assert_eq!(eval.query, "http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m");
|
||||
assert_eq!(
|
||||
eval.query,
|
||||
"http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m"
|
||||
);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
};
|
||||
@@ -382,7 +391,10 @@ mod tests {
|
||||
assert_eq!(eval.end, "10");
|
||||
assert_eq!(eval.step, "1s");
|
||||
assert_eq!(eval.lookback, None);
|
||||
assert_eq!(eval.query, "http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m");
|
||||
assert_eq!(
|
||||
eval.query,
|
||||
"http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m"
|
||||
);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
@@ -394,7 +406,10 @@ mod tests {
|
||||
assert_eq!(eval.end, "1200");
|
||||
assert_eq!(eval.step, "1m");
|
||||
assert_eq!(eval.lookback, None);
|
||||
assert_eq!(eval.query, "http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m");
|
||||
assert_eq!(
|
||||
eval.query,
|
||||
"http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m"
|
||||
);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
@@ -414,7 +429,10 @@ mod tests {
|
||||
assert_eq!(eval.end, "1676887659");
|
||||
assert_eq!(eval.step, "1m");
|
||||
assert_eq!(eval.lookback, None);
|
||||
assert_eq!(eval.query, "http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m");
|
||||
assert_eq!(
|
||||
eval.query,
|
||||
"http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m"
|
||||
);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
@@ -428,7 +446,10 @@ mod tests {
|
||||
assert_eq!(eval.end, "1676887659.5");
|
||||
assert_eq!(eval.step, "30.3");
|
||||
assert_eq!(eval.lookback, None);
|
||||
assert_eq!(eval.query, "http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m");
|
||||
assert_eq!(
|
||||
eval.query,
|
||||
"http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m"
|
||||
);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
@@ -444,7 +465,10 @@ mod tests {
|
||||
assert_eq!(eval.end, "2015-07-01T20:11:00.781Z");
|
||||
assert_eq!(eval.step, "30s");
|
||||
assert_eq!(eval.lookback, None);
|
||||
assert_eq!(eval.query, "http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m");
|
||||
assert_eq!(
|
||||
eval.query,
|
||||
"http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m"
|
||||
);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
@@ -459,7 +483,10 @@ mod tests {
|
||||
assert_eq!(eval.end, "1676887659");
|
||||
assert_eq!(eval.step, "1m".to_string());
|
||||
assert_eq!(eval.lookback, Some("5m".to_string()));
|
||||
assert_eq!(eval.query, "http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m");
|
||||
assert_eq!(
|
||||
eval.query,
|
||||
"http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m"
|
||||
);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
@@ -471,7 +498,10 @@ mod tests {
|
||||
assert_eq!(eval.end, "1200");
|
||||
assert_eq!(eval.step, "1m");
|
||||
assert_eq!(eval.lookback, Some("7m".to_string()));
|
||||
assert_eq!(eval.query, "http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m");
|
||||
assert_eq!(
|
||||
eval.query,
|
||||
"http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m"
|
||||
);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
@@ -479,7 +509,10 @@ mod tests {
|
||||
let sql = "TQL EXPLAIN (20, 100, 10, '3m') http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m";
|
||||
match parse_into_statement(sql) {
|
||||
Statement::Tql(Tql::Explain(explain)) => {
|
||||
assert_eq!(explain.query, "http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m");
|
||||
assert_eq!(
|
||||
explain.query,
|
||||
"http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m"
|
||||
);
|
||||
assert_eq!(explain.start, "20");
|
||||
assert_eq!(explain.end, "100");
|
||||
assert_eq!(explain.step, "10");
|
||||
@@ -492,7 +525,10 @@ mod tests {
|
||||
let sql = "TQL EXPLAIN VERBOSE (20, 100, 10, '3m') http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m";
|
||||
match parse_into_statement(sql) {
|
||||
Statement::Tql(Tql::Explain(explain)) => {
|
||||
assert_eq!(explain.query, "http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m");
|
||||
assert_eq!(
|
||||
explain.query,
|
||||
"http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m"
|
||||
);
|
||||
assert_eq!(explain.start, "20");
|
||||
assert_eq!(explain.end, "100");
|
||||
assert_eq!(explain.step, "10");
|
||||
@@ -509,7 +545,10 @@ mod tests {
|
||||
assert_eq!(analyze.end, "1676887659");
|
||||
assert_eq!(analyze.step, "1m");
|
||||
assert_eq!(analyze.lookback, Some("9m".to_string()));
|
||||
assert_eq!(analyze.query, "http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m");
|
||||
assert_eq!(
|
||||
analyze.query,
|
||||
"http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m"
|
||||
);
|
||||
assert!(!analyze.is_verbose);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
@@ -522,7 +561,10 @@ mod tests {
|
||||
assert_eq!(analyze.end, "1676887659");
|
||||
assert_eq!(analyze.step, "1m");
|
||||
assert_eq!(analyze.lookback, Some("9m".to_string()));
|
||||
assert_eq!(analyze.query, "http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m");
|
||||
assert_eq!(
|
||||
analyze.query,
|
||||
"http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m"
|
||||
);
|
||||
assert!(analyze.is_verbose);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
@@ -534,7 +576,10 @@ mod tests {
|
||||
let sql = "TQL EXPLAIN http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m";
|
||||
match parse_into_statement(sql) {
|
||||
Statement::Tql(Tql::Explain(explain)) => {
|
||||
assert_eq!(explain.query, "http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m");
|
||||
assert_eq!(
|
||||
explain.query,
|
||||
"http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m"
|
||||
);
|
||||
assert_eq!(explain.start, "0");
|
||||
assert_eq!(explain.end, "0");
|
||||
assert_eq!(explain.step, "5m");
|
||||
@@ -548,7 +593,10 @@ mod tests {
|
||||
let sql = "TQL EXPLAIN VERBOSE http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m";
|
||||
match parse_into_statement(sql) {
|
||||
Statement::Tql(Tql::Explain(explain)) => {
|
||||
assert_eq!(explain.query, "http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m");
|
||||
assert_eq!(
|
||||
explain.query,
|
||||
"http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m"
|
||||
);
|
||||
assert_eq!(explain.start, "0");
|
||||
assert_eq!(explain.end, "0");
|
||||
assert_eq!(explain.step, "5m");
|
||||
@@ -562,7 +610,10 @@ mod tests {
|
||||
let sql = "TQL EXPLAIN FORMAT JSON http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m";
|
||||
match parse_into_statement(sql) {
|
||||
Statement::Tql(Tql::Explain(explain)) => {
|
||||
assert_eq!(explain.query, "http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m");
|
||||
assert_eq!(
|
||||
explain.query,
|
||||
"http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m"
|
||||
);
|
||||
assert_eq!(explain.start, "0");
|
||||
assert_eq!(explain.end, "0");
|
||||
assert_eq!(explain.step, "5m");
|
||||
@@ -576,7 +627,10 @@ mod tests {
|
||||
let sql = "TQL EXPLAIN VERBOSE FORMAT JSON http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m";
|
||||
match parse_into_statement(sql) {
|
||||
Statement::Tql(Tql::Explain(explain)) => {
|
||||
assert_eq!(explain.query, "http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m");
|
||||
assert_eq!(
|
||||
explain.query,
|
||||
"http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m"
|
||||
);
|
||||
assert_eq!(explain.start, "0");
|
||||
assert_eq!(explain.end, "0");
|
||||
assert_eq!(explain.step, "5m");
|
||||
@@ -590,7 +644,10 @@ mod tests {
|
||||
let sql = "TQL EXPLAIN FORMAT TEXT (20,100,10) http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m";
|
||||
match parse_into_statement(sql) {
|
||||
Statement::Tql(Tql::Explain(explain)) => {
|
||||
assert_eq!(explain.query, "http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m");
|
||||
assert_eq!(
|
||||
explain.query,
|
||||
"http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m"
|
||||
);
|
||||
assert_eq!(explain.start, "20");
|
||||
assert_eq!(explain.end, "100");
|
||||
assert_eq!(explain.step, "10");
|
||||
@@ -604,7 +661,10 @@ mod tests {
|
||||
let sql = "TQL EXPLAIN (20,100,10) http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m";
|
||||
match parse_into_statement(sql) {
|
||||
Statement::Tql(Tql::Explain(explain)) => {
|
||||
assert_eq!(explain.query, "http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m");
|
||||
assert_eq!(
|
||||
explain.query,
|
||||
"http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m"
|
||||
);
|
||||
assert_eq!(explain.start, "20");
|
||||
assert_eq!(explain.end, "100");
|
||||
assert_eq!(explain.step, "10");
|
||||
@@ -618,7 +678,10 @@ mod tests {
|
||||
let sql = "TQL EXPLAIN ('1970-01-01T00:05:00'::timestamp, '1970-01-01T00:10:00'::timestamp + '10 minutes'::interval, 10) http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m";
|
||||
match parse_into_statement(sql) {
|
||||
Statement::Tql(Tql::Explain(explain)) => {
|
||||
assert_eq!(explain.query, "http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m");
|
||||
assert_eq!(
|
||||
explain.query,
|
||||
"http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m"
|
||||
);
|
||||
assert_eq!(explain.start, "300");
|
||||
assert_eq!(explain.end, "1200");
|
||||
assert_eq!(explain.step, "10");
|
||||
@@ -632,7 +695,10 @@ mod tests {
|
||||
let sql = "TQL EXPLAIN VERBOSE (20,100,10) http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m";
|
||||
match parse_into_statement(sql) {
|
||||
Statement::Tql(Tql::Explain(explain)) => {
|
||||
assert_eq!(explain.query, "http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m");
|
||||
assert_eq!(
|
||||
explain.query,
|
||||
"http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m"
|
||||
);
|
||||
assert_eq!(explain.start, "20");
|
||||
assert_eq!(explain.end, "100");
|
||||
assert_eq!(explain.step, "10");
|
||||
@@ -646,7 +712,10 @@ mod tests {
|
||||
let sql = "TQL EXPLAIN verbose (20,100,10) http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m";
|
||||
match parse_into_statement(sql) {
|
||||
Statement::Tql(Tql::Explain(explain)) => {
|
||||
assert_eq!(explain.query, "http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m");
|
||||
assert_eq!(
|
||||
explain.query,
|
||||
"http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m"
|
||||
);
|
||||
assert_eq!(explain.start, "20");
|
||||
assert_eq!(explain.end, "100");
|
||||
assert_eq!(explain.step, "10");
|
||||
@@ -660,7 +729,10 @@ mod tests {
|
||||
let sql = "TQL EXPLAIN VERBOSE ('1970-01-01T00:05:00'::timestamp, '1970-01-01T00:10:00'::timestamp + '10 minutes'::interval, 10) http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m";
|
||||
match parse_into_statement(sql) {
|
||||
Statement::Tql(Tql::Explain(explain)) => {
|
||||
assert_eq!(explain.query, "http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m");
|
||||
assert_eq!(
|
||||
explain.query,
|
||||
"http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m"
|
||||
);
|
||||
assert_eq!(explain.start, "300");
|
||||
assert_eq!(explain.end, "1200");
|
||||
assert_eq!(explain.step, "10");
|
||||
@@ -681,7 +753,10 @@ mod tests {
|
||||
assert_eq!(analyze.end, "1676887659.5");
|
||||
assert_eq!(analyze.step, "30.3");
|
||||
assert_eq!(analyze.lookback, None);
|
||||
assert_eq!(analyze.query, "http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m");
|
||||
assert_eq!(
|
||||
analyze.query,
|
||||
"http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m"
|
||||
);
|
||||
assert!(!analyze.is_verbose);
|
||||
assert_eq!(analyze.format, None);
|
||||
}
|
||||
@@ -695,7 +770,10 @@ mod tests {
|
||||
assert_eq!(analyze.end, "1676887659.5");
|
||||
assert_eq!(analyze.step, "30.3");
|
||||
assert_eq!(analyze.lookback, None);
|
||||
assert_eq!(analyze.query, "http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m");
|
||||
assert_eq!(
|
||||
analyze.query,
|
||||
"http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m"
|
||||
);
|
||||
assert!(!analyze.is_verbose);
|
||||
assert_eq!(analyze.format, Some(AnalyzeFormat::JSON));
|
||||
}
|
||||
@@ -709,7 +787,10 @@ mod tests {
|
||||
assert_eq!(analyze.end, "1676887659.5");
|
||||
assert_eq!(analyze.step, "30.3");
|
||||
assert_eq!(analyze.lookback, None);
|
||||
assert_eq!(analyze.query, "http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m");
|
||||
assert_eq!(
|
||||
analyze.query,
|
||||
"http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m"
|
||||
);
|
||||
assert!(analyze.is_verbose);
|
||||
assert_eq!(analyze.format, Some(AnalyzeFormat::JSON));
|
||||
}
|
||||
@@ -723,7 +804,10 @@ mod tests {
|
||||
assert_eq!(analyze.end, "1200");
|
||||
assert_eq!(analyze.step, "10");
|
||||
assert_eq!(analyze.lookback, None);
|
||||
assert_eq!(analyze.query, "http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m");
|
||||
assert_eq!(
|
||||
analyze.query,
|
||||
"http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m"
|
||||
);
|
||||
assert!(!analyze.is_verbose);
|
||||
assert_eq!(analyze.format, None);
|
||||
}
|
||||
@@ -737,7 +821,10 @@ mod tests {
|
||||
assert_eq!(analyze.end, "1676887659.5");
|
||||
assert_eq!(analyze.step, "30.3");
|
||||
assert_eq!(analyze.lookback, None);
|
||||
assert_eq!(analyze.query, "http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m");
|
||||
assert_eq!(
|
||||
analyze.query,
|
||||
"http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m"
|
||||
);
|
||||
assert!(analyze.is_verbose);
|
||||
assert_eq!(analyze.format, None);
|
||||
}
|
||||
@@ -751,7 +838,10 @@ mod tests {
|
||||
assert_eq!(analyze.end, "1676887659.5");
|
||||
assert_eq!(analyze.step, "30.3");
|
||||
assert_eq!(analyze.lookback, None);
|
||||
assert_eq!(analyze.query, "http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m");
|
||||
assert_eq!(
|
||||
analyze.query,
|
||||
"http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m"
|
||||
);
|
||||
assert!(analyze.is_verbose);
|
||||
assert_eq!(analyze.format, None);
|
||||
}
|
||||
@@ -765,7 +855,10 @@ mod tests {
|
||||
assert_eq!(analyze.end, "1200");
|
||||
assert_eq!(analyze.step, "10");
|
||||
assert_eq!(analyze.lookback, None);
|
||||
assert_eq!(analyze.query, "http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m");
|
||||
assert_eq!(
|
||||
analyze.query,
|
||||
"http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m"
|
||||
);
|
||||
assert!(analyze.is_verbose);
|
||||
assert_eq!(analyze.format, None);
|
||||
}
|
||||
@@ -874,7 +967,10 @@ mod tests {
|
||||
assert_eq!(eval.end, "30");
|
||||
assert_eq!(eval.step, "10s");
|
||||
assert_eq!(eval.lookback, None);
|
||||
assert_eq!(eval.query, "(sum by(host) (irate(host_cpu_seconds_total{mode!='idle'}[1m0s])) / sum by (host)((irate(host_cpu_seconds_total[1m0s])))) * 100");
|
||||
assert_eq!(
|
||||
eval.query,
|
||||
"(sum by(host) (irate(host_cpu_seconds_total{mode!='idle'}[1m0s])) / sum by (host)((irate(host_cpu_seconds_total[1m0s])))) * 100"
|
||||
);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
@@ -901,17 +997,21 @@ mod tests {
|
||||
let sql = "TQL EVAL (1676887657, 1676887659, 1m) http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m";
|
||||
let result =
|
||||
ParserContext::create_with_dialect(sql, dialect, parse_options.clone()).unwrap_err();
|
||||
assert!(result
|
||||
.output_msg()
|
||||
.contains("Failed to extract a timestamp value"));
|
||||
assert!(
|
||||
result
|
||||
.output_msg()
|
||||
.contains("Failed to extract a timestamp value")
|
||||
);
|
||||
|
||||
// missing end
|
||||
let sql = "TQL EVAL (1676887657, '1m') http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m";
|
||||
let result =
|
||||
ParserContext::create_with_dialect(sql, dialect, parse_options.clone()).unwrap_err();
|
||||
assert!(result
|
||||
.output_msg()
|
||||
.contains("Failed to extract a timestamp value"));
|
||||
assert!(
|
||||
result
|
||||
.output_msg()
|
||||
.contains("Failed to extract a timestamp value")
|
||||
);
|
||||
|
||||
// empty TQL query
|
||||
let sql = "TQL EVAL (0, 30, '10s')";
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use snafu::{ensure, ResultExt};
|
||||
use snafu::{ResultExt, ensure};
|
||||
use sqlparser::keywords::Keyword;
|
||||
use sqlparser::tokenizer::Token;
|
||||
|
||||
|
||||
@@ -17,16 +17,16 @@ use std::sync::Arc;
|
||||
use chrono::Utc;
|
||||
use datafusion::config::ConfigOptions;
|
||||
use datafusion::error::Result as DfResult;
|
||||
use datafusion::execution::context::SessionState;
|
||||
use datafusion::execution::SessionStateBuilder;
|
||||
use datafusion::execution::context::SessionState;
|
||||
use datafusion::optimizer::simplify_expressions::ExprSimplifier;
|
||||
use datafusion_common::tree_node::{TreeNode, TreeNodeVisitor};
|
||||
use datafusion_common::{DFSchema, ScalarValue};
|
||||
use datafusion_expr::execution_props::ExecutionProps;
|
||||
use datafusion_expr::simplify::SimplifyContext;
|
||||
use datafusion_expr::{AggregateUDF, Expr, ScalarUDF, TableSource, WindowUDF};
|
||||
use datafusion_sql::planner::{ContextProvider, SqlToRel};
|
||||
use datafusion_sql::TableReference;
|
||||
use datafusion_sql::planner::{ContextProvider, SqlToRel};
|
||||
use datatypes::arrow::datatypes::DataType;
|
||||
use datatypes::schema::{
|
||||
COLUMN_FULLTEXT_OPT_KEY_ANALYZER, COLUMN_FULLTEXT_OPT_KEY_BACKEND,
|
||||
@@ -34,7 +34,7 @@ use datatypes::schema::{
|
||||
COLUMN_FULLTEXT_OPT_KEY_GRANULARITY, COLUMN_SKIPPING_INDEX_OPT_KEY_FALSE_POSITIVE_RATE,
|
||||
COLUMN_SKIPPING_INDEX_OPT_KEY_GRANULARITY, COLUMN_SKIPPING_INDEX_OPT_KEY_TYPE,
|
||||
};
|
||||
use snafu::{ensure, ResultExt};
|
||||
use snafu::{ResultExt, ensure};
|
||||
use sqlparser::dialect::Dialect;
|
||||
|
||||
use crate::error::{
|
||||
@@ -88,16 +88,16 @@ pub fn parser_expr_to_scalar_value_literal(
|
||||
&mut self,
|
||||
node: &Self::Node,
|
||||
) -> DfResult<datafusion_common::tree_node::TreeNodeRecursion> {
|
||||
if let Expr::ScalarFunction(func) = node {
|
||||
if func.name().to_lowercase() == "now" {
|
||||
if !func.args.is_empty() {
|
||||
return Err(datafusion_common::DataFusionError::Plan(
|
||||
"now() function should not have arguments".to_string(),
|
||||
));
|
||||
}
|
||||
self.found = true;
|
||||
return Ok(datafusion_common::tree_node::TreeNodeRecursion::Stop);
|
||||
if let Expr::ScalarFunction(func) = node
|
||||
&& func.name().to_lowercase() == "now"
|
||||
{
|
||||
if !func.args.is_empty() {
|
||||
return Err(datafusion_common::DataFusionError::Plan(
|
||||
"now() function should not have arguments".to_string(),
|
||||
));
|
||||
}
|
||||
self.found = true;
|
||||
return Ok(datafusion_common::tree_node::TreeNodeRecursion::Stop);
|
||||
}
|
||||
Ok(datafusion_common::tree_node::TreeNodeRecursion::Continue)
|
||||
}
|
||||
|
||||
@@ -197,14 +197,13 @@ impl ParserContext<'_> {
|
||||
/// Determine if CTE contains TQL or SQL and parse accordingly
|
||||
fn parse_cte_content(&mut self) -> Result<CteContent> {
|
||||
// Check if the next token is TQL
|
||||
if let Token::Word(w) = &self.parser.peek_token().token {
|
||||
if w.keyword == Keyword::NoKeyword
|
||||
&& w.quote_style.is_none()
|
||||
&& w.value.to_uppercase() == tql_parser::TQL
|
||||
{
|
||||
let tql = self.parse_tql_content_in_cte()?;
|
||||
return Ok(CteContent::Tql(tql));
|
||||
}
|
||||
if let Token::Word(w) = &self.parser.peek_token().token
|
||||
&& w.keyword == Keyword::NoKeyword
|
||||
&& w.quote_style.is_none()
|
||||
&& w.value.to_uppercase() == tql_parser::TQL
|
||||
{
|
||||
let tql = self.parse_tql_content_in_cte()?;
|
||||
return Ok(CteContent::Tql(tql));
|
||||
}
|
||||
|
||||
// Parse as SQL query
|
||||
|
||||
@@ -222,10 +222,9 @@ mod tests {
|
||||
value: Value::SingleQuotedString(leftmost),
|
||||
..
|
||||
}) = *right.clone()
|
||||
&& uuid < leftmost
|
||||
{
|
||||
if uuid < leftmost {
|
||||
return i;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
} else if i == rules.len() - 1 {
|
||||
// Hit the rightmost rule.
|
||||
@@ -233,10 +232,9 @@ mod tests {
|
||||
value: Value::SingleQuotedString(rightmost),
|
||||
..
|
||||
}) = *right.clone()
|
||||
&& uuid >= rightmost
|
||||
{
|
||||
if uuid >= rightmost {
|
||||
return i;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
} else {
|
||||
// Hit the middle rules.
|
||||
@@ -245,29 +243,23 @@ mod tests {
|
||||
op: _,
|
||||
right: inner_right,
|
||||
} = *left.clone()
|
||||
{
|
||||
if let Expr::Value(ValueWithSpan {
|
||||
&& let Expr::Value(ValueWithSpan {
|
||||
value: Value::SingleQuotedString(lower),
|
||||
..
|
||||
}) = *inner_right.clone()
|
||||
{
|
||||
if let Expr::BinaryOp {
|
||||
left: _,
|
||||
op: _,
|
||||
right: inner_right,
|
||||
} = *right.clone()
|
||||
{
|
||||
if let Expr::Value(ValueWithSpan {
|
||||
value: Value::SingleQuotedString(upper),
|
||||
..
|
||||
}) = *inner_right.clone()
|
||||
{
|
||||
if uuid >= lower && uuid < upper {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
&& let Expr::BinaryOp {
|
||||
left: _,
|
||||
op: _,
|
||||
right: inner_right,
|
||||
} = *right.clone()
|
||||
&& let Expr::Value(ValueWithSpan {
|
||||
value: Value::SingleQuotedString(upper),
|
||||
..
|
||||
}) = *inner_right.clone()
|
||||
&& uuid >= lower
|
||||
&& uuid < upper
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ use api::v1::SemanticType;
|
||||
use common_sql::default_constraint::parse_column_default_constraint;
|
||||
use common_time::timezone::Timezone;
|
||||
use datatypes::prelude::ConcreteDataType;
|
||||
use datatypes::schema::{ColumnDefaultConstraint, ColumnSchema, COMMENT_KEY};
|
||||
use datatypes::schema::{COMMENT_KEY, ColumnDefaultConstraint, ColumnSchema};
|
||||
use datatypes::types::TimestampType;
|
||||
use datatypes::value::Value;
|
||||
use snafu::ResultExt;
|
||||
@@ -324,14 +324,14 @@ pub fn concrete_data_type_to_sql_data_type(data_type: &ConcreteDataType) -> Resu
|
||||
mod tests {
|
||||
use api::v1::ColumnDataType;
|
||||
use datatypes::schema::{
|
||||
FulltextAnalyzer, COLUMN_FULLTEXT_OPT_KEY_ANALYZER, COLUMN_FULLTEXT_OPT_KEY_CASE_SENSITIVE,
|
||||
COLUMN_FULLTEXT_OPT_KEY_ANALYZER, COLUMN_FULLTEXT_OPT_KEY_CASE_SENSITIVE, FulltextAnalyzer,
|
||||
};
|
||||
use sqlparser::ast::{ColumnOptionDef, Expr};
|
||||
|
||||
use super::*;
|
||||
use crate::ast::TimezoneInfo;
|
||||
use crate::statements::create::ColumnExtensions;
|
||||
use crate::statements::ColumnOption;
|
||||
use crate::statements::create::ColumnExtensions;
|
||||
|
||||
fn check_type(sql_type: SqlDataType, data_type: ConcreteDataType) {
|
||||
assert_eq!(
|
||||
|
||||
@@ -201,7 +201,11 @@ impl Display for AlterTableOperation {
|
||||
column_name,
|
||||
options,
|
||||
} => {
|
||||
write!(f, "MODIFY COLUMN {column_name} SET FULLTEXT INDEX WITH(analyzer={0}, case_sensitive={1}, backend={2})", options.analyzer, options.case_sensitive, options.backend)
|
||||
write!(
|
||||
f,
|
||||
"MODIFY COLUMN {column_name} SET FULLTEXT INDEX WITH(analyzer={0}, case_sensitive={1}, backend={2})",
|
||||
options.analyzer, options.case_sensitive, options.backend
|
||||
)
|
||||
}
|
||||
SetIndexOperation::Inverted { column_name } => {
|
||||
write!(f, "MODIFY COLUMN {column_name} SET INVERTED INDEX")
|
||||
@@ -210,7 +214,11 @@ impl Display for AlterTableOperation {
|
||||
column_name,
|
||||
options,
|
||||
} => {
|
||||
write!(f, "MODIFY COLUMN {column_name} SET SKIPPING INDEX WITH(granularity={0}, index_type={1})", options.granularity, options.index_type)
|
||||
write!(
|
||||
f,
|
||||
"MODIFY COLUMN {column_name} SET SKIPPING INDEX WITH(granularity={0}, index_type={1})",
|
||||
options.granularity, options.index_type
|
||||
)
|
||||
}
|
||||
},
|
||||
AlterTableOperation::UnsetIndex { options } => match options {
|
||||
|
||||
@@ -4,8 +4,8 @@ use serde::Serialize;
|
||||
use sqlparser::ast::ObjectName;
|
||||
use sqlparser_derive::{Visit, VisitMut};
|
||||
|
||||
use crate::statements::create::trigger::{NotifyChannel, TriggerOn};
|
||||
use crate::statements::OptionMap;
|
||||
use crate::statements::create::trigger::{NotifyChannel, TriggerOn};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Visit, VisitMut, Serialize)]
|
||||
pub struct AlterTrigger {
|
||||
|
||||
@@ -18,8 +18,8 @@ use serde::Serialize;
|
||||
use sqlparser::ast::ObjectName;
|
||||
use sqlparser_derive::{Visit, VisitMut};
|
||||
|
||||
use crate::statements::statement::Statement;
|
||||
use crate::statements::OptionMap;
|
||||
use crate::statements::statement::Statement;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Visit, VisitMut, Serialize)]
|
||||
pub enum Copy {
|
||||
|
||||
@@ -27,9 +27,9 @@ use crate::ast::{ColumnDef, Ident, ObjectName, Value as SqlValue};
|
||||
use crate::error::{
|
||||
InvalidFlowQuerySnafu, Result, SetFulltextOptionSnafu, SetSkippingIndexOptionSnafu,
|
||||
};
|
||||
use crate::statements::OptionMap;
|
||||
use crate::statements::statement::Statement;
|
||||
use crate::statements::tql::Tql;
|
||||
use crate::statements::OptionMap;
|
||||
|
||||
const LINE_SEP: &str = ",\n";
|
||||
const COMMA_SEP: &str = ", ";
|
||||
@@ -150,11 +150,11 @@ impl Column {
|
||||
|
||||
impl Display for Column {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
if let Some(vector_options) = &self.extensions.vector_options {
|
||||
if let Some(dim) = vector_options.get(VECTOR_OPT_DIM) {
|
||||
write!(f, "{} VECTOR({})", self.column_def.name, dim)?;
|
||||
return Ok(());
|
||||
}
|
||||
if let Some(vector_options) = &self.extensions.vector_options
|
||||
&& let Some(dim) = vector_options.get(VECTOR_OPT_DIM)
|
||||
{
|
||||
write!(f, "{} VECTOR({})", self.column_def.name, dim)?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
write!(f, "{}", self.column_def)?;
|
||||
|
||||
@@ -8,8 +8,8 @@ use sqlparser::ast::{Query, Visit, VisitMut, Visitor, VisitorMut};
|
||||
use sqlparser_derive::{Visit, VisitMut};
|
||||
|
||||
use crate::ast::{Ident, ObjectName};
|
||||
use crate::statements::create::{COMMA_SEP, INDENT, LINE_SEP};
|
||||
use crate::statements::OptionMap;
|
||||
use crate::statements::create::{COMMA_SEP, INDENT, LINE_SEP};
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Visit, VisitMut, Serialize)]
|
||||
pub struct CreateTrigger {
|
||||
|
||||
@@ -111,12 +111,10 @@ mod tests {
|
||||
#[test]
|
||||
pub fn test_describe_missing_table_name() {
|
||||
let sql = "DESCRIBE TABLE";
|
||||
assert!(ParserContext::create_with_dialect(
|
||||
sql,
|
||||
&GreptimeDbDialect {},
|
||||
ParseOptions::default()
|
||||
)
|
||||
.is_err());
|
||||
assert!(
|
||||
ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}, ParseOptions::default())
|
||||
.is_err()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -426,23 +426,19 @@ mod tests {
|
||||
#[test]
|
||||
pub fn test_show_create_missing_table_name() {
|
||||
let sql = "SHOW CREATE TABLE";
|
||||
assert!(ParserContext::create_with_dialect(
|
||||
sql,
|
||||
&GreptimeDbDialect {},
|
||||
ParseOptions::default()
|
||||
)
|
||||
.is_err());
|
||||
assert!(
|
||||
ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}, ParseOptions::default())
|
||||
.is_err()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_show_create_unknown_for() {
|
||||
let sql = "SHOW CREATE TABLE t FOR UNKNOWN";
|
||||
assert!(ParserContext::create_with_dialect(
|
||||
sql,
|
||||
&GreptimeDbDialect {},
|
||||
ParseOptions::default()
|
||||
)
|
||||
.is_err());
|
||||
assert!(
|
||||
ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}, ParseOptions::default())
|
||||
.is_err()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -466,12 +462,10 @@ mod tests {
|
||||
#[test]
|
||||
pub fn test_show_create_missing_flow() {
|
||||
let sql = "SHOW CREATE FLOW";
|
||||
assert!(ParserContext::create_with_dialect(
|
||||
sql,
|
||||
&GreptimeDbDialect {},
|
||||
ParseOptions::default()
|
||||
)
|
||||
.is_err());
|
||||
assert!(
|
||||
ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}, ParseOptions::default())
|
||||
.is_err()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -23,8 +23,8 @@ impl Display for ShowTriggers {
|
||||
mod tests {
|
||||
use crate::dialect::GreptimeDbDialect;
|
||||
use crate::parser::{ParseOptions, ParserContext};
|
||||
use crate::statements::show::trigger::ShowTriggers;
|
||||
use crate::statements::show::ShowKind;
|
||||
use crate::statements::show::trigger::ShowTriggers;
|
||||
use crate::statements::statement::Statement;
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -20,7 +20,7 @@ use std::sync::Arc;
|
||||
|
||||
use expand_interval::ExpandIntervalTransformRule;
|
||||
use lazy_static::lazy_static;
|
||||
use sqlparser::ast::{visit_expressions_mut, Expr};
|
||||
use sqlparser::ast::{Expr, visit_expressions_mut};
|
||||
use type_alias::TypeAliasTransformRule;
|
||||
|
||||
use crate::error::Result;
|
||||
|
||||
@@ -215,10 +215,10 @@ mod tests {
|
||||
|
||||
use sqlparser::ast::{BinaryOperator, CastKind, DataType, Expr, Interval, Value};
|
||||
|
||||
use crate::statements::transform::expand_interval::{
|
||||
normalize_interval_name, single_quoted_string_expr, ExpandIntervalTransformRule,
|
||||
};
|
||||
use crate::statements::transform::TransformRule;
|
||||
use crate::statements::transform::expand_interval::{
|
||||
ExpandIntervalTransformRule, normalize_interval_name, single_quoted_string_expr,
|
||||
};
|
||||
|
||||
fn create_interval(value: Box<Expr>) -> Expr {
|
||||
Expr::Interval(Interval {
|
||||
|
||||
@@ -26,7 +26,7 @@ use crate::statements::alter::AlterTableOperation;
|
||||
use crate::statements::create::{CreateExternalTable, CreateTable};
|
||||
use crate::statements::statement::Statement;
|
||||
use crate::statements::transform::TransformRule;
|
||||
use crate::statements::{sql_data_type_to_concrete_data_type, TimezoneInfo};
|
||||
use crate::statements::{TimezoneInfo, sql_data_type_to_concrete_data_type};
|
||||
|
||||
/// SQL data type alias transformer:
|
||||
/// - `TimestampSecond`, `Timestamp_s`, `Timestamp_sec` for `Timestamp(0)`.
|
||||
@@ -337,7 +337,12 @@ mod tests {
|
||||
transform_statements(&mut stmts).unwrap();
|
||||
|
||||
match &stmts[0] {
|
||||
Statement::Query(q) => assert_eq!(format!("SELECT arrow_cast(TIMESTAMP '2020-01-01 01:23:45.12345678', 'Timestamp({expected}, None)')"), q.to_string()),
|
||||
Statement::Query(q) => assert_eq!(
|
||||
format!(
|
||||
"SELECT arrow_cast(TIMESTAMP '2020-01-01 01:23:45.12345678', 'Timestamp({expected}, None)')"
|
||||
),
|
||||
q.to_string()
|
||||
),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
@@ -355,7 +360,10 @@ mod tests {
|
||||
transform_statements(&mut stmts).unwrap();
|
||||
|
||||
match &stmts[0] {
|
||||
Statement::CreateTable(c) => assert_eq!("CREATE TABLE test (\n b BOOLEAN,\n ts TIMESTAMP NOT NULL,\n TIME INDEX (ts)\n)\nENGINE=mito\n", c.to_string()),
|
||||
Statement::CreateTable(c) => assert_eq!(
|
||||
"CREATE TABLE test (\n b BOOLEAN,\n ts TIMESTAMP NOT NULL,\n TIME INDEX (ts)\n)\nENGINE=mito\n",
|
||||
c.to_string()
|
||||
),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user