Skip to content

Commit 8a7e073

Browse files
killme2008paomian
authored andcommitted
fix: parsing time index column option (GreptimeTeam#865)
* fix: parsing time index column option * test: adds more cases for creating table * chore: by CR comments * feat: validate time index constraint in parser * chore: improve error msg
1 parent ca9f716 commit 8a7e073

File tree

5 files changed

+331
-88
lines changed

5 files changed

+331
-88
lines changed

src/datanode/src/sql/create.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -269,24 +269,6 @@ mod tests {
269269
assert_eq!(4, c.schema.column_schemas().len());
270270
}
271271

272-
/// Time index not specified in sql
273-
#[tokio::test]
274-
pub async fn test_time_index_not_specified() {
275-
let handler = create_mock_sql_handler().await;
276-
let parsed_stmt = sql_to_statement(
277-
r#"create table demo_table(
278-
host string,
279-
ts bigint,
280-
cpu double default 0,
281-
memory double,
282-
PRIMARY KEY(host)) engine=mito with(regions=1);"#,
283-
);
284-
let error = handler
285-
.create_to_request(42, parsed_stmt, TableReference::bare("demo_table"))
286-
.unwrap_err();
287-
assert_matches!(error, Error::MissingTimestampColumn { .. });
288-
}
289-
290272
#[tokio::test]
291273
pub async fn test_primary_key_not_specified() {
292274
let handler = create_mock_sql_handler().await;

src/sql/src/error.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,22 @@ pub enum Error {
6464
#[snafu(display("Tokenizer error, sql: {}, source: {}", sql, source))]
6565
Tokenizer { sql: String, source: TokenizerError },
6666

67-
#[snafu(display(
68-
"Invalid time index, it should contains only one column, sql: {}.",
69-
sql
70-
))]
71-
InvalidTimeIndex { sql: String, backtrace: Backtrace },
67+
#[snafu(display("Missing time index constraint"))]
68+
MissingTimeIndex { backtrace: Backtrace },
69+
70+
#[snafu(display("Invalid time index: {}", msg))]
71+
InvalidTimeIndex { msg: String, backtrace: Backtrace },
7272

7373
#[snafu(display("Invalid SQL, error: {}", msg))]
7474
InvalidSql { msg: String, backtrace: Backtrace },
7575

76+
#[snafu(display("Invalid column option, column name: {}, error: {}", name, msg))]
77+
InvalidColumnOption {
78+
name: String,
79+
msg: String,
80+
backtrace: Backtrace,
81+
},
82+
7683
#[snafu(display("SQL data type not supported yet: {:?}", t))]
7784
SqlTypeNotSupported {
7885
t: crate::ast::DataType,
@@ -134,16 +141,18 @@ impl ErrorExt for Error {
134141
UnsupportedDefaultValue { .. } | Unsupported { .. } => StatusCode::Unsupported,
135142
Unexpected { .. }
136143
| Syntax { .. }
144+
| MissingTimeIndex { .. }
137145
| InvalidTimeIndex { .. }
138146
| Tokenizer { .. }
139147
| InvalidSql { .. }
140148
| ParseSqlValue { .. }
141149
| SqlTypeNotSupported { .. }
142150
| InvalidDefault { .. } => StatusCode::InvalidSyntax,
143151

144-
InvalidDatabaseName { .. } | ColumnTypeMismatch { .. } | InvalidTableName { .. } => {
145-
StatusCode::InvalidArguments
146-
}
152+
InvalidColumnOption { .. }
153+
| InvalidDatabaseName { .. }
154+
| ColumnTypeMismatch { .. }
155+
| InvalidTableName { .. } => StatusCode::InvalidArguments,
147156
UnsupportedAlterTableStatement { .. } => StatusCode::InvalidSyntax,
148157
SerializeColumnDefaultConstraint { source, .. } => source.status_code(),
149158
ConvertToGrpcDataType { source, .. } => source.status_code(),

0 commit comments

Comments
 (0)