mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-05-15 20:40:39 +00:00
feat: sql dialect for different protocols (#1631)
* feat: add SqlDialect to query context * feat: use session in postgrel handlers * chore: refactor sql dialect * feat: use different dialects for different sql protocols * feat: adds GreptimeDbDialect * refactor: replace GenericDialect with GreptimeDbDialect * feat: save user info to session * fix: compile error * fix: test
This commit is contained in:
@@ -6,7 +6,6 @@ license.workspace = true
|
||||
|
||||
[dependencies]
|
||||
api = { path = "../api" }
|
||||
catalog = { path = "../catalog" }
|
||||
common-base = { path = "../common/base" }
|
||||
common-catalog = { path = "../common/catalog" }
|
||||
common-datasource = { path = "../common/datasource" }
|
||||
|
||||
@@ -12,6 +12,32 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// todo(hl) wrap sqlparser dialects
|
||||
pub use sqlparser::dialect::{Dialect, MySqlDialect, PostgreSqlDialect};
|
||||
|
||||
pub use sqlparser::dialect::{Dialect, GenericDialect};
|
||||
/// GreptimeDb dialect
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct GreptimeDbDialect {}
|
||||
|
||||
impl Dialect for GreptimeDbDialect {
|
||||
fn is_identifier_start(&self, ch: char) -> bool {
|
||||
ch.is_alphabetic() || ch == '_' || ch == '#' || ch == '@'
|
||||
}
|
||||
|
||||
fn is_identifier_part(&self, ch: char) -> bool {
|
||||
ch.is_alphabetic()
|
||||
|| ch.is_ascii_digit()
|
||||
|| ch == '@'
|
||||
|| ch == '$'
|
||||
|| ch == '#'
|
||||
|| ch == '_'
|
||||
}
|
||||
|
||||
// Accepts both `identifier` and "identifier".
|
||||
fn is_delimited_identifier_start(&self, ch: char) -> bool {
|
||||
ch == '`' || ch == '"'
|
||||
}
|
||||
|
||||
fn supports_filter_during_aggregation(&self) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -393,16 +393,16 @@ mod tests {
|
||||
use sqlparser::ast::{
|
||||
Ident, ObjectName, Query as SpQuery, Statement as SpStatement, WildcardAdditionalOptions,
|
||||
};
|
||||
use sqlparser::dialect::GenericDialect;
|
||||
|
||||
use super::*;
|
||||
use crate::dialect::GreptimeDbDialect;
|
||||
use crate::statements::create::CreateTable;
|
||||
use crate::statements::sql_data_type_to_concrete_data_type;
|
||||
|
||||
#[test]
|
||||
pub fn test_show_database_all() {
|
||||
let sql = "SHOW DATABASES";
|
||||
let result = ParserContext::create_with_dialect(sql, &GenericDialect {});
|
||||
let result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {});
|
||||
let stmts = result.unwrap();
|
||||
assert_eq!(1, stmts.len());
|
||||
|
||||
@@ -417,7 +417,7 @@ mod tests {
|
||||
#[test]
|
||||
pub fn test_show_database_like() {
|
||||
let sql = "SHOW DATABASES LIKE test_database";
|
||||
let result = ParserContext::create_with_dialect(sql, &GenericDialect {});
|
||||
let result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {});
|
||||
let stmts = result.unwrap();
|
||||
assert_eq!(1, stmts.len());
|
||||
|
||||
@@ -435,7 +435,7 @@ mod tests {
|
||||
#[test]
|
||||
pub fn test_show_database_where() {
|
||||
let sql = "SHOW DATABASES WHERE Database LIKE '%whatever1%' OR Database LIKE '%whatever2%'";
|
||||
let result = ParserContext::create_with_dialect(sql, &GenericDialect {});
|
||||
let result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {});
|
||||
let stmts = result.unwrap();
|
||||
assert_eq!(1, stmts.len());
|
||||
|
||||
@@ -454,7 +454,7 @@ mod tests {
|
||||
#[test]
|
||||
pub fn test_show_tables_all() {
|
||||
let sql = "SHOW TABLES";
|
||||
let result = ParserContext::create_with_dialect(sql, &GenericDialect {});
|
||||
let result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {});
|
||||
let stmts = result.unwrap();
|
||||
assert_eq!(1, stmts.len());
|
||||
|
||||
@@ -470,7 +470,7 @@ mod tests {
|
||||
#[test]
|
||||
pub fn test_show_tables_like() {
|
||||
let sql = "SHOW TABLES LIKE test_table";
|
||||
let result = ParserContext::create_with_dialect(sql, &GenericDialect {});
|
||||
let result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {});
|
||||
let stmts = result.unwrap();
|
||||
assert_eq!(1, stmts.len());
|
||||
|
||||
@@ -486,7 +486,7 @@ mod tests {
|
||||
);
|
||||
|
||||
let sql = "SHOW TABLES in test_db LIKE test_table";
|
||||
let result = ParserContext::create_with_dialect(sql, &GenericDialect {});
|
||||
let result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {});
|
||||
let stmts = result.unwrap();
|
||||
assert_eq!(1, stmts.len());
|
||||
|
||||
@@ -505,7 +505,7 @@ mod tests {
|
||||
#[test]
|
||||
pub fn test_show_tables_where() {
|
||||
let sql = "SHOW TABLES where name like test_table";
|
||||
let result = ParserContext::create_with_dialect(sql, &GenericDialect {});
|
||||
let result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {});
|
||||
let stmts = result.unwrap();
|
||||
assert_eq!(1, stmts.len());
|
||||
|
||||
@@ -518,7 +518,7 @@ mod tests {
|
||||
);
|
||||
|
||||
let sql = "SHOW TABLES in test_db where name LIKE test_table";
|
||||
let result = ParserContext::create_with_dialect(sql, &GenericDialect {});
|
||||
let result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {});
|
||||
let stmts = result.unwrap();
|
||||
assert_eq!(1, stmts.len());
|
||||
|
||||
@@ -534,7 +534,7 @@ mod tests {
|
||||
#[test]
|
||||
pub fn test_explain() {
|
||||
let sql = "EXPLAIN select * from foo";
|
||||
let result = ParserContext::create_with_dialect(sql, &GenericDialect {});
|
||||
let result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {});
|
||||
let stmts = result.unwrap();
|
||||
assert_eq!(1, stmts.len());
|
||||
|
||||
@@ -589,7 +589,7 @@ mod tests {
|
||||
#[test]
|
||||
pub fn test_drop_table() {
|
||||
let sql = "DROP TABLE foo";
|
||||
let result = ParserContext::create_with_dialect(sql, &GenericDialect {});
|
||||
let result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {});
|
||||
let mut stmts = result.unwrap();
|
||||
assert_eq!(
|
||||
stmts.pop().unwrap(),
|
||||
@@ -597,7 +597,7 @@ mod tests {
|
||||
);
|
||||
|
||||
let sql = "DROP TABLE my_schema.foo";
|
||||
let result = ParserContext::create_with_dialect(sql, &GenericDialect {});
|
||||
let result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {});
|
||||
let mut stmts = result.unwrap();
|
||||
assert_eq!(
|
||||
stmts.pop().unwrap(),
|
||||
@@ -608,7 +608,7 @@ mod tests {
|
||||
);
|
||||
|
||||
let sql = "DROP TABLE my_catalog.my_schema.foo";
|
||||
let result = ParserContext::create_with_dialect(sql, &GenericDialect {});
|
||||
let result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {});
|
||||
let mut stmts = result.unwrap();
|
||||
assert_eq!(
|
||||
stmts.pop().unwrap(),
|
||||
@@ -621,7 +621,7 @@ mod tests {
|
||||
}
|
||||
|
||||
fn test_timestamp_precision(sql: &str, expected_type: ConcreteDataType) {
|
||||
match ParserContext::create_with_dialect(sql, &GenericDialect {})
|
||||
match ParserContext::create_with_dialect(sql, &GreptimeDbDialect {})
|
||||
.unwrap()
|
||||
.pop()
|
||||
.unwrap()
|
||||
@@ -673,7 +673,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_parse_function() {
|
||||
let expr =
|
||||
ParserContext::parse_function("current_timestamp()", &GenericDialect {}).unwrap();
|
||||
ParserContext::parse_function("current_timestamp()", &GreptimeDbDialect {}).unwrap();
|
||||
assert!(matches!(expr, Expr::Function(_)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,14 +79,14 @@ mod tests {
|
||||
use std::assert_matches::assert_matches;
|
||||
|
||||
use sqlparser::ast::{ColumnOption, DataType};
|
||||
use sqlparser::dialect::GenericDialect;
|
||||
|
||||
use super::*;
|
||||
use crate::dialect::GreptimeDbDialect;
|
||||
|
||||
#[test]
|
||||
fn test_parse_alter_add_column() {
|
||||
let sql = "ALTER TABLE my_metric_1 ADD tagk_i STRING Null;";
|
||||
let mut result = ParserContext::create_with_dialect(sql, &GenericDialect {}).unwrap();
|
||||
let mut result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}).unwrap();
|
||||
assert_eq!(1, result.len());
|
||||
|
||||
let statement = result.remove(0);
|
||||
@@ -116,13 +116,13 @@ mod tests {
|
||||
#[test]
|
||||
fn test_parse_alter_drop_column() {
|
||||
let sql = "ALTER TABLE my_metric_1 DROP a";
|
||||
let result = ParserContext::create_with_dialect(sql, &GenericDialect {}).unwrap_err();
|
||||
let result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}).unwrap_err();
|
||||
assert!(result
|
||||
.to_string()
|
||||
.contains("expect keyword COLUMN after ALTER TABLE DROP"));
|
||||
|
||||
let sql = "ALTER TABLE my_metric_1 DROP COLUMN a";
|
||||
let mut result = ParserContext::create_with_dialect(sql, &GenericDialect {}).unwrap();
|
||||
let mut result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}).unwrap();
|
||||
assert_eq!(1, result.len());
|
||||
|
||||
let statement = result.remove(0);
|
||||
@@ -147,13 +147,13 @@ mod tests {
|
||||
#[test]
|
||||
fn test_parse_alter_rename_table() {
|
||||
let sql = "ALTER TABLE test_table table_t";
|
||||
let result = ParserContext::create_with_dialect(sql, &GenericDialect {}).unwrap_err();
|
||||
let result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}).unwrap_err();
|
||||
assert!(result
|
||||
.to_string()
|
||||
.contains("expect keyword ADD or DROP or RENAME after ALTER TABLE"));
|
||||
|
||||
let sql = "ALTER TABLE test_table RENAME table_t";
|
||||
let mut result = ParserContext::create_with_dialect(sql, &GenericDialect {}).unwrap();
|
||||
let mut result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}).unwrap();
|
||||
assert_eq!(1, result.len());
|
||||
|
||||
let statement = result.remove(0);
|
||||
|
||||
@@ -139,16 +139,15 @@ mod tests {
|
||||
use std::assert_matches::assert_matches;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use sqlparser::dialect::GenericDialect;
|
||||
|
||||
use super::*;
|
||||
use crate::dialect::GreptimeDbDialect;
|
||||
|
||||
#[test]
|
||||
fn test_parse_copy_table() {
|
||||
let sql0 = "COPY catalog0.schema0.tbl TO 'tbl_file.parquet'";
|
||||
let sql1 = "COPY catalog0.schema0.tbl TO 'tbl_file.parquet' WITH (FORMAT = 'parquet')";
|
||||
let result0 = ParserContext::create_with_dialect(sql0, &GenericDialect {}).unwrap();
|
||||
let result1 = ParserContext::create_with_dialect(sql1, &GenericDialect {}).unwrap();
|
||||
let result0 = ParserContext::create_with_dialect(sql0, &GreptimeDbDialect {}).unwrap();
|
||||
let result1 = ParserContext::create_with_dialect(sql1, &GreptimeDbDialect {}).unwrap();
|
||||
|
||||
for mut result in vec![result0, result1] {
|
||||
assert_eq!(1, result.len());
|
||||
@@ -190,7 +189,7 @@ mod tests {
|
||||
"COPY catalog0.schema0.tbl FROM 'tbl_file.parquet' WITH (FORMAT = 'parquet')",
|
||||
]
|
||||
.iter()
|
||||
.map(|sql| ParserContext::create_with_dialect(sql, &GenericDialect {}).unwrap())
|
||||
.map(|sql| ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}).unwrap())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
for mut result in results {
|
||||
@@ -249,7 +248,7 @@ mod tests {
|
||||
|
||||
for test in tests {
|
||||
let mut result =
|
||||
ParserContext::create_with_dialect(test.sql, &GenericDialect {}).unwrap();
|
||||
ParserContext::create_with_dialect(test.sql, &GreptimeDbDialect {}).unwrap();
|
||||
assert_eq!(1, result.len());
|
||||
|
||||
let statement = result.remove(0);
|
||||
@@ -290,7 +289,7 @@ mod tests {
|
||||
|
||||
for test in tests {
|
||||
let mut result =
|
||||
ParserContext::create_with_dialect(test.sql, &GenericDialect {}).unwrap();
|
||||
ParserContext::create_with_dialect(test.sql, &GreptimeDbDialect {}).unwrap();
|
||||
assert_eq!(1, result.len());
|
||||
|
||||
let statement = result.remove(0);
|
||||
|
||||
@@ -784,9 +784,9 @@ mod tests {
|
||||
|
||||
use common_catalog::consts::IMMUTABLE_FILE_ENGINE;
|
||||
use sqlparser::ast::ColumnOption::NotNull;
|
||||
use sqlparser::dialect::GenericDialect;
|
||||
|
||||
use super::*;
|
||||
use crate::dialect::GreptimeDbDialect;
|
||||
|
||||
#[test]
|
||||
fn test_parse_create_external_table() {
|
||||
@@ -822,7 +822,8 @@ mod tests {
|
||||
];
|
||||
|
||||
for test in tests {
|
||||
let stmts = ParserContext::create_with_dialect(test.sql, &GenericDialect {}).unwrap();
|
||||
let stmts =
|
||||
ParserContext::create_with_dialect(test.sql, &GreptimeDbDialect {}).unwrap();
|
||||
assert_eq!(1, stmts.len());
|
||||
match &stmts[0] {
|
||||
Statement::CreateExternalTable(c) => {
|
||||
@@ -852,7 +853,7 @@ mod tests {
|
||||
("format".to_string(), "csv".to_string()),
|
||||
]);
|
||||
|
||||
let stmts = ParserContext::create_with_dialect(sql, &GenericDialect {}).unwrap();
|
||||
let stmts = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}).unwrap();
|
||||
assert_eq!(1, stmts.len());
|
||||
match &stmts[0] {
|
||||
Statement::CreateExternalTable(c) => {
|
||||
@@ -888,14 +889,14 @@ mod tests {
|
||||
#[test]
|
||||
fn test_parse_create_database() {
|
||||
let sql = "create database";
|
||||
let result = ParserContext::create_with_dialect(sql, &GenericDialect {});
|
||||
let result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {});
|
||||
assert!(result
|
||||
.unwrap_err()
|
||||
.to_string()
|
||||
.contains("Unexpected token while parsing SQL statement"));
|
||||
|
||||
let sql = "create database prometheus";
|
||||
let stmts = ParserContext::create_with_dialect(sql, &GenericDialect {}).unwrap();
|
||||
let stmts = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}).unwrap();
|
||||
|
||||
assert_eq!(1, stmts.len());
|
||||
match &stmts[0] {
|
||||
@@ -907,7 +908,7 @@ mod tests {
|
||||
}
|
||||
|
||||
let sql = "create database if not exists prometheus";
|
||||
let stmts = ParserContext::create_with_dialect(sql, &GenericDialect {}).unwrap();
|
||||
let stmts = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}).unwrap();
|
||||
|
||||
assert_eq!(1, stmts.len());
|
||||
match &stmts[0] {
|
||||
@@ -929,7 +930,7 @@ PARTITION BY RANGE COLUMNS(b, a) (
|
||||
PARTITION r3 VALUES LESS THAN (MAXVALUE, MAXVALUE),
|
||||
)
|
||||
ENGINE=mito";
|
||||
let result = ParserContext::create_with_dialect(sql, &GenericDialect {});
|
||||
let result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {});
|
||||
assert!(result.is_ok());
|
||||
|
||||
let sql = r"
|
||||
@@ -940,7 +941,7 @@ PARTITION BY RANGE COLUMNS(b, x) (
|
||||
PARTITION r3 VALUES LESS THAN (MAXVALUE, MAXVALUE),
|
||||
)
|
||||
ENGINE=mito";
|
||||
let result = ParserContext::create_with_dialect(sql, &GenericDialect {});
|
||||
let result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {});
|
||||
assert!(result
|
||||
.unwrap_err()
|
||||
.to_string()
|
||||
@@ -955,7 +956,7 @@ PARTITION BY RANGE COLUMNS(b, a) (
|
||||
PARTITION r1 VALUES LESS THAN (MAXVALUE, MAXVALUE),
|
||||
)
|
||||
ENGINE=mito";
|
||||
let result = ParserContext::create_with_dialect(sql, &GenericDialect {});
|
||||
let result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {});
|
||||
assert!(result
|
||||
.unwrap_err()
|
||||
.to_string()
|
||||
@@ -969,7 +970,7 @@ PARTITION BY RANGE COLUMNS(b, a) (
|
||||
PARTITION r3 VALUES LESS THAN (MAXVALUE, MAXVALUE),
|
||||
)
|
||||
ENGINE=mito";
|
||||
let result = ParserContext::create_with_dialect(sql, &GenericDialect {});
|
||||
let result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {});
|
||||
assert!(result
|
||||
.unwrap_err()
|
||||
.to_string()
|
||||
@@ -1010,7 +1011,7 @@ PARTITION BY RANGE COLUMNS(b, a) (
|
||||
ENGINE=mito",
|
||||
];
|
||||
for sql in cases {
|
||||
let result = ParserContext::create_with_dialect(sql, &GenericDialect {});
|
||||
let result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {});
|
||||
assert!(result
|
||||
.unwrap_err()
|
||||
.to_string()
|
||||
@@ -1025,7 +1026,7 @@ PARTITION BY RANGE COLUMNS(b, a) (
|
||||
PARTITION r3 VALUES LESS THAN (MAXVALUE, 9999),
|
||||
)
|
||||
ENGINE=mito";
|
||||
let result = ParserContext::create_with_dialect(sql, &GenericDialect {});
|
||||
let result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {});
|
||||
assert!(result
|
||||
.unwrap_err()
|
||||
.to_string()
|
||||
@@ -1051,7 +1052,7 @@ PARTITION BY RANGE COLUMNS(idc, host_id) (
|
||||
PARTITION r3 VALUES LESS THAN (MAXVALUE, MAXVALUE),
|
||||
)
|
||||
ENGINE=mito";
|
||||
let result = ParserContext::create_with_dialect(sql, &GenericDialect {}).unwrap();
|
||||
let result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}).unwrap();
|
||||
assert_eq!(result.len(), 1);
|
||||
match &result[0] {
|
||||
Statement::CreateTable(c) => {
|
||||
@@ -1117,7 +1118,7 @@ CREATE TABLE monitor (
|
||||
PRIMARY KEY (host),
|
||||
)
|
||||
ENGINE=mito";
|
||||
let result1 = ParserContext::create_with_dialect(sql1, &GenericDialect {}).unwrap();
|
||||
let result1 = ParserContext::create_with_dialect(sql1, &GreptimeDbDialect {}).unwrap();
|
||||
|
||||
if let Statement::CreateTable(c) = &result1[0] {
|
||||
assert_eq!(c.constraints.len(), 2);
|
||||
@@ -1152,7 +1153,7 @@ CREATE TABLE monitor (
|
||||
PRIMARY KEY (host),
|
||||
)
|
||||
ENGINE=mito";
|
||||
let result2 = ParserContext::create_with_dialect(sql2, &GenericDialect {}).unwrap();
|
||||
let result2 = ParserContext::create_with_dialect(sql2, &GreptimeDbDialect {}).unwrap();
|
||||
|
||||
assert_eq!(result1, result2);
|
||||
|
||||
@@ -1169,7 +1170,7 @@ CREATE TABLE monitor (
|
||||
)
|
||||
ENGINE=mito";
|
||||
|
||||
let result3 = ParserContext::create_with_dialect(sql3, &GenericDialect {}).unwrap();
|
||||
let result3 = ParserContext::create_with_dialect(sql3, &GreptimeDbDialect {}).unwrap();
|
||||
|
||||
assert_ne!(result1, result3);
|
||||
|
||||
@@ -1184,7 +1185,7 @@ CREATE TABLE monitor (
|
||||
PRIMARY KEY (host),
|
||||
)
|
||||
ENGINE=mito";
|
||||
let result1 = ParserContext::create_with_dialect(sql1, &GenericDialect {}).unwrap();
|
||||
let result1 = ParserContext::create_with_dialect(sql1, &GreptimeDbDialect {}).unwrap();
|
||||
|
||||
if let Statement::CreateTable(c) = &result1[0] {
|
||||
assert_eq!(c.constraints.len(), 2);
|
||||
@@ -1220,7 +1221,7 @@ CREATE TABLE monitor (
|
||||
PRIMARY KEY (host),
|
||||
)
|
||||
ENGINE=mito";
|
||||
let result = ParserContext::create_with_dialect(sql, &GenericDialect {}).unwrap();
|
||||
let result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}).unwrap();
|
||||
|
||||
assert_eq!(result.len(), 1);
|
||||
if let Statement::CreateTable(c) = &result[0] {
|
||||
@@ -1243,7 +1244,7 @@ CREATE TABLE monitor (
|
||||
)
|
||||
ENGINE=mito";
|
||||
|
||||
let result1 = ParserContext::create_with_dialect(sql1, &GenericDialect {}).unwrap();
|
||||
let result1 = ParserContext::create_with_dialect(sql1, &GreptimeDbDialect {}).unwrap();
|
||||
assert_eq!(result, result1);
|
||||
|
||||
let sql2 = r"
|
||||
@@ -1258,7 +1259,7 @@ CREATE TABLE monitor (
|
||||
)
|
||||
ENGINE=mito";
|
||||
|
||||
let result2 = ParserContext::create_with_dialect(sql2, &GenericDialect {}).unwrap();
|
||||
let result2 = ParserContext::create_with_dialect(sql2, &GreptimeDbDialect {}).unwrap();
|
||||
assert_eq!(result, result2);
|
||||
|
||||
let sql3 = r"
|
||||
@@ -1273,7 +1274,7 @@ CREATE TABLE monitor (
|
||||
)
|
||||
ENGINE=mito";
|
||||
|
||||
let result3 = ParserContext::create_with_dialect(sql3, &GenericDialect {});
|
||||
let result3 = ParserContext::create_with_dialect(sql3, &GreptimeDbDialect {});
|
||||
assert!(result3.is_err());
|
||||
|
||||
let sql4 = r"
|
||||
@@ -1288,7 +1289,7 @@ CREATE TABLE monitor (
|
||||
)
|
||||
ENGINE=mito";
|
||||
|
||||
let result4 = ParserContext::create_with_dialect(sql4, &GenericDialect {});
|
||||
let result4 = ParserContext::create_with_dialect(sql4, &GreptimeDbDialect {});
|
||||
assert!(result4.is_err());
|
||||
|
||||
let sql = r"
|
||||
@@ -1303,7 +1304,7 @@ CREATE TABLE monitor (
|
||||
)
|
||||
ENGINE=mito";
|
||||
|
||||
let result = ParserContext::create_with_dialect(sql, &GenericDialect {}).unwrap();
|
||||
let result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}).unwrap();
|
||||
|
||||
if let Statement::CreateTable(c) = &result[0] {
|
||||
let tc = c.constraints[0].clone();
|
||||
@@ -1339,7 +1340,7 @@ PARTITION RANGE COLUMNS(b, a) (
|
||||
PARTITION r3 VALUES LESS THAN (MAXVALUE, MAXVALUE),
|
||||
)
|
||||
ENGINE=mito";
|
||||
let result = ParserContext::create_with_dialect(sql, &GenericDialect {});
|
||||
let result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {});
|
||||
assert!(result
|
||||
.unwrap_err()
|
||||
.to_string()
|
||||
@@ -1353,7 +1354,7 @@ PARTITION BY RANGE COLUMNS(b, a) (
|
||||
PARTITION r3 VALUES LESS THAN (MAXVALUE, MAXVALUE),
|
||||
)
|
||||
ENGINE=mito";
|
||||
let result = ParserContext::create_with_dialect(sql, &GenericDialect {});
|
||||
let result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {});
|
||||
assert!(result
|
||||
.unwrap_err()
|
||||
.to_string()
|
||||
@@ -1367,11 +1368,11 @@ PARTITION BY RANGE COLUMNS(b, a) (
|
||||
PARTITION r3 VALUES LESS THAN (MAXVALUE, MAXVALU),
|
||||
)
|
||||
ENGINE=mito";
|
||||
let result = ParserContext::create_with_dialect(sql, &GenericDialect {});
|
||||
let result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {});
|
||||
assert!(result
|
||||
.unwrap_err()
|
||||
.to_string()
|
||||
.contains("Please provide an extra partition that is bounded by 'MAXVALUE'."));
|
||||
.contains("Expected a concrete value, found: MAXVALU"));
|
||||
}
|
||||
|
||||
fn assert_column_def(column: &ColumnDef, name: &str, data_type: &str) {
|
||||
@@ -1390,7 +1391,7 @@ ENGINE=mito";
|
||||
PRIMARY KEY(ts, host)) engine=mito
|
||||
with(regions=1);
|
||||
";
|
||||
let result = ParserContext::create_with_dialect(sql, &GenericDialect {}).unwrap();
|
||||
let result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}).unwrap();
|
||||
assert_eq!(1, result.len());
|
||||
match &result[0] {
|
||||
Statement::CreateTable(c) => {
|
||||
@@ -1438,7 +1439,7 @@ ENGINE=mito";
|
||||
PRIMARY KEY(ts, host)) engine=mito
|
||||
with(regions=1);
|
||||
";
|
||||
let result = ParserContext::create_with_dialect(sql, &GenericDialect {});
|
||||
let result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {});
|
||||
assert!(result.is_err());
|
||||
assert_matches!(result, Err(crate::error::Error::InvalidTimeIndex { .. }));
|
||||
}
|
||||
@@ -1455,7 +1456,7 @@ ENGINE=mito";
|
||||
PRIMARY KEY(ts, host)) engine=mito
|
||||
with(regions=1);
|
||||
";
|
||||
let result = ParserContext::create_with_dialect(sql, &GenericDialect {});
|
||||
let result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {});
|
||||
assert!(result.is_err());
|
||||
assert_matches!(result, Err(crate::error::Error::InvalidColumnOption { .. }));
|
||||
|
||||
@@ -1469,7 +1470,7 @@ ENGINE=mito";
|
||||
PRIMARY KEY(ts, host)) engine=mito
|
||||
with(regions=1);
|
||||
";
|
||||
let result = ParserContext::create_with_dialect(sql, &GenericDialect {});
|
||||
let result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {});
|
||||
assert!(result.is_err());
|
||||
assert_matches!(result, Err(crate::error::Error::InvalidTimeIndex { .. }));
|
||||
}
|
||||
@@ -1477,7 +1478,7 @@ ENGINE=mito";
|
||||
#[test]
|
||||
fn test_invalid_column_name() {
|
||||
let sql = "create table foo(user string, i bigint time index)";
|
||||
let result = ParserContext::create_with_dialect(sql, &GenericDialect {});
|
||||
let result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {});
|
||||
assert!(result
|
||||
.unwrap_err()
|
||||
.to_string()
|
||||
@@ -1487,7 +1488,7 @@ ENGINE=mito";
|
||||
let sql = r#"
|
||||
create table foo("user" string, i bigint time index)
|
||||
"#;
|
||||
let result = ParserContext::create_with_dialect(sql, &GenericDialect {});
|
||||
let result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {});
|
||||
assert!(result.is_ok());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,14 +46,13 @@ impl<'a> ParserContext<'a> {
|
||||
mod tests {
|
||||
use std::assert_matches::assert_matches;
|
||||
|
||||
use sqlparser::dialect::GenericDialect;
|
||||
|
||||
use super::*;
|
||||
use crate::dialect::GreptimeDbDialect;
|
||||
|
||||
#[test]
|
||||
pub fn test_parse_insert() {
|
||||
let sql = r"delete from my_table where k1 = xxx and k2 = xxx and timestamp = xxx;";
|
||||
let result = ParserContext::create_with_dialect(sql, &GenericDialect {}).unwrap();
|
||||
let result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}).unwrap();
|
||||
assert_eq!(1, result.len());
|
||||
assert_matches!(result[0], Statement::Delete { .. })
|
||||
}
|
||||
@@ -61,7 +60,7 @@ mod tests {
|
||||
#[test]
|
||||
pub fn test_parse_invalid_insert() {
|
||||
let sql = r"delete my_table where "; // intentionally a bad sql
|
||||
let result = ParserContext::create_with_dialect(sql, &GenericDialect {});
|
||||
let result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {});
|
||||
assert!(result.is_err(), "result is: {result:?}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,9 +46,8 @@ impl<'a> ParserContext<'a> {
|
||||
mod tests {
|
||||
use std::assert_matches::assert_matches;
|
||||
|
||||
use sqlparser::dialect::GenericDialect;
|
||||
|
||||
use super::*;
|
||||
use crate::dialect::GreptimeDbDialect;
|
||||
|
||||
#[test]
|
||||
pub fn test_parse_insert() {
|
||||
@@ -56,7 +55,7 @@ mod tests {
|
||||
'test1',1,'true',
|
||||
'test2',2,'false')
|
||||
";
|
||||
let result = ParserContext::create_with_dialect(sql, &GenericDialect {}).unwrap();
|
||||
let result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}).unwrap();
|
||||
assert_eq!(1, result.len());
|
||||
assert_matches!(result[0], Statement::Insert { .. })
|
||||
}
|
||||
@@ -64,7 +63,7 @@ mod tests {
|
||||
#[test]
|
||||
pub fn test_parse_invalid_insert() {
|
||||
let sql = r"INSERT INTO table_1 VALUES ("; // intentionally a bad sql
|
||||
let result = ParserContext::create_with_dialect(sql, &GenericDialect {});
|
||||
let result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {});
|
||||
assert!(result.is_err(), "result is: {result:?}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,8 +33,7 @@ impl<'a> ParserContext<'a> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use sqlparser::dialect::GenericDialect;
|
||||
|
||||
use crate::dialect::GreptimeDbDialect;
|
||||
use crate::parser::ParserContext;
|
||||
|
||||
#[test]
|
||||
@@ -44,13 +43,13 @@ mod tests {
|
||||
WHERE a > b AND b < 100 \
|
||||
ORDER BY a DESC, b";
|
||||
|
||||
let _ = ParserContext::create_with_dialect(sql, &GenericDialect {}).unwrap();
|
||||
let _ = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_parse_invalid_query() {
|
||||
let sql = "SELECT * FROM table_1 WHERE";
|
||||
let result = ParserContext::create_with_dialect(sql, &GenericDialect {});
|
||||
let result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {});
|
||||
assert!(result.is_err());
|
||||
assert!(result
|
||||
.unwrap_err()
|
||||
|
||||
@@ -166,14 +166,13 @@ impl<'a> ParserContext<'a> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use sqlparser::dialect::GenericDialect;
|
||||
|
||||
use super::*;
|
||||
use crate::dialect::GreptimeDbDialect;
|
||||
#[test]
|
||||
fn test_parse_tql_eval() {
|
||||
let sql = "TQL EVAL (1676887657, 1676887659, '1m') http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m";
|
||||
|
||||
let mut result = ParserContext::create_with_dialect(sql, &GenericDialect {}).unwrap();
|
||||
let mut result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}).unwrap();
|
||||
assert_eq!(1, result.len());
|
||||
|
||||
let statement = result.remove(0);
|
||||
@@ -189,7 +188,7 @@ mod tests {
|
||||
|
||||
let sql = "TQL EVAL (1676887657.1, 1676887659.5, 30.3) http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m";
|
||||
|
||||
let mut result = ParserContext::create_with_dialect(sql, &GenericDialect {}).unwrap();
|
||||
let mut result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}).unwrap();
|
||||
assert_eq!(1, result.len());
|
||||
|
||||
let statement = result.remove(0);
|
||||
@@ -205,7 +204,7 @@ mod tests {
|
||||
|
||||
let sql = "TQL EVALUATE (1676887657.1, 1676887659.5, 30.3) http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m";
|
||||
|
||||
let mut result = ParserContext::create_with_dialect(sql, &GenericDialect {}).unwrap();
|
||||
let mut result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}).unwrap();
|
||||
assert_eq!(1, result.len());
|
||||
|
||||
let statement2 = result.remove(0);
|
||||
@@ -213,7 +212,7 @@ mod tests {
|
||||
|
||||
let sql = "tql eval ('2015-07-01T20:10:30.781Z', '2015-07-01T20:11:00.781Z', '30s') http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m";
|
||||
|
||||
let mut result = ParserContext::create_with_dialect(sql, &GenericDialect {}).unwrap();
|
||||
let mut result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}).unwrap();
|
||||
assert_eq!(1, result.len());
|
||||
|
||||
let statement = result.remove(0);
|
||||
@@ -232,7 +231,7 @@ mod tests {
|
||||
fn test_parse_tql_explain() {
|
||||
let sql = "TQL EXPLAIN http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m";
|
||||
|
||||
let mut result = ParserContext::create_with_dialect(sql, &GenericDialect {}).unwrap();
|
||||
let mut result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}).unwrap();
|
||||
assert_eq!(1, result.len());
|
||||
|
||||
let statement = result.remove(0);
|
||||
@@ -248,7 +247,7 @@ mod tests {
|
||||
|
||||
let sql = "TQL EXPLAIN (20,100,10) http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m";
|
||||
|
||||
let mut result = ParserContext::create_with_dialect(sql, &GenericDialect {}).unwrap();
|
||||
let mut result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}).unwrap();
|
||||
assert_eq!(1, result.len());
|
||||
|
||||
let statement = result.remove(0);
|
||||
@@ -266,7 +265,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_parse_tql_analyze() {
|
||||
let sql = "TQL ANALYZE (1676887657.1, 1676887659.5, 30.3) http_requests_total{environment=~'staging|testing|development',method!='GET'} @ 1609746000 offset 5m";
|
||||
let mut result = ParserContext::create_with_dialect(sql, &GenericDialect {}).unwrap();
|
||||
let mut result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}).unwrap();
|
||||
assert_eq!(1, result.len());
|
||||
let statement = result.remove(0);
|
||||
match statement {
|
||||
@@ -284,12 +283,12 @@ mod tests {
|
||||
fn test_parse_tql_error() {
|
||||
// Invalid duration
|
||||
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, &GenericDialect {}).unwrap_err();
|
||||
let result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}).unwrap_err();
|
||||
assert!(result.to_string().contains("Expected ), found: m"));
|
||||
|
||||
// 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, &GenericDialect {}).unwrap_err();
|
||||
let result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}).unwrap_err();
|
||||
assert!(result.to_string().contains("Expected ,, found: )"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,8 +206,7 @@ pub struct CreateExternalTable {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use sqlparser::dialect::GenericDialect;
|
||||
|
||||
use crate::dialect::GreptimeDbDialect;
|
||||
use crate::parser::ParserContext;
|
||||
use crate::statements::statement::Statement;
|
||||
|
||||
@@ -229,7 +228,7 @@ mod tests {
|
||||
engine=mito
|
||||
with(regions=1, ttl='7d');
|
||||
";
|
||||
let result = ParserContext::create_with_dialect(sql, &GenericDialect {}).unwrap();
|
||||
let result = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}).unwrap();
|
||||
assert_eq!(1, result.len());
|
||||
|
||||
match &result[0] {
|
||||
@@ -259,7 +258,7 @@ WITH(
|
||||
);
|
||||
|
||||
let new_result =
|
||||
ParserContext::create_with_dialect(&new_sql, &GenericDialect {}).unwrap();
|
||||
ParserContext::create_with_dialect(&new_sql, &GreptimeDbDialect {}).unwrap();
|
||||
assert_eq!(result, new_result);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
|
||||
@@ -35,8 +35,7 @@ impl DescribeTable {
|
||||
mod tests {
|
||||
use std::assert_matches::assert_matches;
|
||||
|
||||
use sqlparser::dialect::GenericDialect;
|
||||
|
||||
use crate::dialect::GreptimeDbDialect;
|
||||
use crate::parser::ParserContext;
|
||||
use crate::statements::statement::Statement;
|
||||
|
||||
@@ -44,7 +43,7 @@ mod tests {
|
||||
pub fn test_describe_table() {
|
||||
let sql = "DESCRIBE TABLE test";
|
||||
let stmts: Vec<Statement> =
|
||||
ParserContext::create_with_dialect(sql, &GenericDialect {}).unwrap();
|
||||
ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}).unwrap();
|
||||
assert_eq!(1, stmts.len());
|
||||
assert_matches!(&stmts[0], Statement::DescribeTable { .. });
|
||||
match &stmts[0] {
|
||||
@@ -61,7 +60,7 @@ mod tests {
|
||||
pub fn test_describe_schema_table() {
|
||||
let sql = "DESCRIBE TABLE test_schema.test";
|
||||
let stmts: Vec<Statement> =
|
||||
ParserContext::create_with_dialect(sql, &GenericDialect {}).unwrap();
|
||||
ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}).unwrap();
|
||||
assert_eq!(1, stmts.len());
|
||||
assert_matches!(&stmts[0], Statement::DescribeTable { .. });
|
||||
match &stmts[0] {
|
||||
@@ -78,7 +77,7 @@ mod tests {
|
||||
pub fn test_describe_catalog_schema_table() {
|
||||
let sql = "DESCRIBE TABLE test_catalog.test_schema.test";
|
||||
let stmts: Vec<Statement> =
|
||||
ParserContext::create_with_dialect(sql, &GenericDialect {}).unwrap();
|
||||
ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}).unwrap();
|
||||
assert_eq!(1, stmts.len());
|
||||
assert_matches!(&stmts[0], Statement::DescribeTable { .. });
|
||||
match &stmts[0] {
|
||||
@@ -94,6 +93,6 @@ mod tests {
|
||||
#[test]
|
||||
pub fn test_describe_missing_table_name() {
|
||||
let sql = "DESCRIBE TABLE";
|
||||
ParserContext::create_with_dialect(sql, &GenericDialect {}).unwrap_err();
|
||||
ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}).unwrap_err();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,9 +136,8 @@ impl TryFrom<Statement> for Insert {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use sqlparser::dialect::GenericDialect;
|
||||
|
||||
use super::*;
|
||||
use crate::dialect::GreptimeDbDialect;
|
||||
use crate::parser::ParserContext;
|
||||
use crate::statements::statement::Statement;
|
||||
|
||||
@@ -146,7 +145,7 @@ mod tests {
|
||||
fn test_insert_value_with_unary_op() {
|
||||
// insert "-1"
|
||||
let sql = "INSERT INTO my_table VALUES(-1)";
|
||||
let stmt = ParserContext::create_with_dialect(sql, &GenericDialect {})
|
||||
let stmt = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {})
|
||||
.unwrap()
|
||||
.remove(0);
|
||||
match stmt {
|
||||
@@ -159,7 +158,7 @@ mod tests {
|
||||
|
||||
// insert "+1"
|
||||
let sql = "INSERT INTO my_table VALUES(+1)";
|
||||
let stmt = ParserContext::create_with_dialect(sql, &GenericDialect {})
|
||||
let stmt = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {})
|
||||
.unwrap()
|
||||
.remove(0);
|
||||
match stmt {
|
||||
@@ -175,7 +174,7 @@ mod tests {
|
||||
fn test_insert_value_with_default() {
|
||||
// insert "default"
|
||||
let sql = "INSERT INTO my_table VALUES(default)";
|
||||
let stmt = ParserContext::create_with_dialect(sql, &GenericDialect {})
|
||||
let stmt = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {})
|
||||
.unwrap()
|
||||
.remove(0);
|
||||
match stmt {
|
||||
@@ -191,7 +190,7 @@ mod tests {
|
||||
fn test_insert_value_with_default_uppercase() {
|
||||
// insert "DEFAULT"
|
||||
let sql = "INSERT INTO my_table VALUES(DEFAULT)";
|
||||
let stmt = ParserContext::create_with_dialect(sql, &GenericDialect {})
|
||||
let stmt = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {})
|
||||
.unwrap()
|
||||
.remove(0);
|
||||
match stmt {
|
||||
@@ -207,7 +206,7 @@ mod tests {
|
||||
fn test_insert_value_with_quoted_string() {
|
||||
// insert "'default'"
|
||||
let sql = "INSERT INTO my_table VALUES('default')";
|
||||
let stmt = ParserContext::create_with_dialect(sql, &GenericDialect {})
|
||||
let stmt = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {})
|
||||
.unwrap()
|
||||
.remove(0);
|
||||
match stmt {
|
||||
@@ -225,7 +224,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_insert_select() {
|
||||
let sql = "INSERT INTO my_table select * from other_table";
|
||||
let stmt = ParserContext::create_with_dialect(sql, &GenericDialect {})
|
||||
let stmt = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {})
|
||||
.unwrap()
|
||||
.remove(0);
|
||||
match stmt {
|
||||
|
||||
@@ -74,14 +74,13 @@ impl fmt::Display for Query {
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
|
||||
use sqlparser::dialect::GenericDialect;
|
||||
|
||||
use super::Query;
|
||||
use crate::dialect::GreptimeDbDialect;
|
||||
use crate::parser::ParserContext;
|
||||
use crate::statements::statement::Statement;
|
||||
|
||||
fn create_query(sql: &str) -> Option<Box<Query>> {
|
||||
match ParserContext::create_with_dialect(sql, &GenericDialect {})
|
||||
match ParserContext::create_with_dialect(sql, &GreptimeDbDialect {})
|
||||
.unwrap()
|
||||
.remove(0)
|
||||
{
|
||||
|
||||
@@ -65,9 +65,9 @@ mod tests {
|
||||
use std::assert_matches::assert_matches;
|
||||
|
||||
use sqlparser::ast::UnaryOperator;
|
||||
use sqlparser::dialect::GenericDialect;
|
||||
|
||||
use super::*;
|
||||
use crate::dialect::GreptimeDbDialect;
|
||||
use crate::parser::ParserContext;
|
||||
use crate::statements::statement::Statement;
|
||||
|
||||
@@ -102,7 +102,7 @@ mod tests {
|
||||
#[test]
|
||||
pub fn test_show_database() {
|
||||
let sql = "SHOW DATABASES";
|
||||
let stmts = ParserContext::create_with_dialect(sql, &GenericDialect {}).unwrap();
|
||||
let stmts = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}).unwrap();
|
||||
assert_eq!(1, stmts.len());
|
||||
assert_matches!(&stmts[0], Statement::ShowDatabases { .. });
|
||||
match &stmts[0] {
|
||||
@@ -119,7 +119,7 @@ mod tests {
|
||||
pub fn test_show_create_table() {
|
||||
let sql = "SHOW CREATE TABLE test";
|
||||
let stmts: Vec<Statement> =
|
||||
ParserContext::create_with_dialect(sql, &GenericDialect {}).unwrap();
|
||||
ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}).unwrap();
|
||||
assert_eq!(1, stmts.len());
|
||||
assert_matches!(&stmts[0], Statement::ShowCreateTable { .. });
|
||||
match &stmts[0] {
|
||||
@@ -135,6 +135,6 @@ mod tests {
|
||||
#[test]
|
||||
pub fn test_show_create_missing_table_name() {
|
||||
let sql = "SHOW CREATE TABLE";
|
||||
ParserContext::create_with_dialect(sql, &GenericDialect {}).unwrap_err();
|
||||
ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}).unwrap_err();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user