Skip to content

Commit 314873f

Browse files
authored
Merge pull request apache#2 from datafuse-extras/tinyint
Tinyint
2 parents c5de122 + 0db7cfa commit 314873f

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

src/ast/data_type.rs

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ pub enum DataType {
3737
Decimal(Option<u64>, Option<u64>),
3838
/// Floating point with optional precision e.g. FLOAT(8)
3939
Float(Option<u64>),
40+
/// Tiny integer
41+
TinyInt,
4042
/// Small integer
4143
SmallInt,
4244
/// Integer
@@ -91,6 +93,7 @@ impl fmt::Display for DataType {
9193
}
9294
}
9395
DataType::Float(size) => format_type_with_optional_length(f, "FLOAT", size),
96+
DataType::TinyInt => write!(f, "TINYINT"),
9497
DataType::SmallInt => write!(f, "SMALLINT"),
9598
DataType::Int => write!(f, "INT"),
9699
DataType::BigInt => write!(f, "BIGINT"),

src/dialect/keywords.rs

+1
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ define_keywords!(
444444
TIMESTAMP,
445445
TIMEZONE_HOUR,
446446
TIMEZONE_MINUTE,
447+
TINYINT,
447448
TO,
448449
TOP,
449450
TRAILING,

src/parser.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1938,6 +1938,7 @@ impl<'a> Parser<'a> {
19381938
let _ = self.parse_keyword(Keyword::PRECISION);
19391939
Ok(DataType::Double)
19401940
}
1941+
Keyword::TINYINT => Ok(DataType::TinyInt),
19411942
Keyword::SMALLINT => Ok(DataType::SmallInt),
19421943
Keyword::INT | Keyword::INTEGER => Ok(DataType::Int),
19431944
Keyword::BIGINT => Ok(DataType::BigInt),

tests/sqlparser_common.rs

+11
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,17 @@ fn parse_cast() {
10171017
},
10181018
expr_from_projection(only(&select.projection))
10191019
);
1020+
1021+
let sql = "SELECT CAST(id AS TINYINT) FROM customer";
1022+
let select = verified_only_select(sql);
1023+
assert_eq!(
1024+
&Expr::Cast {
1025+
expr: Box::new(Expr::Identifier(Ident::new("id"))),
1026+
data_type: DataType::TinyInt
1027+
},
1028+
expr_from_projection(only(&select.projection))
1029+
);
1030+
10201031
one_statement_parses_to(
10211032
"SELECT CAST(id AS BIGINT) FROM customer",
10221033
"SELECT CAST(id AS BIGINT) FROM customer",

0 commit comments

Comments
 (0)