mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-05-28 19:00:39 +00:00
fix: Normalize default constrain fn name (#2737)
* fix: normalize current_timestamp to current_timestamp() Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * add sqlness case Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * fix clippy lints Signed-off-by: Ruihang Xia <waynestxia@gmail.com> --------- Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
mod column_schema;
|
||||
mod constraint;
|
||||
pub mod constraint;
|
||||
mod raw;
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
@@ -24,9 +24,9 @@ use crate::value::Value;
|
||||
use crate::vectors::operations::VectorOp;
|
||||
use crate::vectors::{TimestampMillisecondVector, VectorRef};
|
||||
|
||||
const CURRENT_TIMESTAMP: &str = "current_timestamp";
|
||||
const CURRENT_TIMESTAMP_FN: &str = "current_timestamp()";
|
||||
const NOW_FN: &str = "now()";
|
||||
pub const CURRENT_TIMESTAMP: &str = "current_timestamp";
|
||||
pub const CURRENT_TIMESTAMP_FN: &str = "current_timestamp()";
|
||||
pub const NOW_FN: &str = "now()";
|
||||
|
||||
/// Column's default constraint.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
|
||||
@@ -63,6 +63,7 @@ pub enum Error {
|
||||
Syntax {
|
||||
#[snafu(source)]
|
||||
error: ParserError,
|
||||
location: Location,
|
||||
},
|
||||
|
||||
#[snafu(display("Missing time index constraint"))]
|
||||
|
||||
@@ -37,6 +37,7 @@ use common_base::bytes::Bytes;
|
||||
use common_query::AddColumnLocation;
|
||||
use common_time::Timestamp;
|
||||
use datatypes::prelude::ConcreteDataType;
|
||||
use datatypes::schema::constraint::{CURRENT_TIMESTAMP, CURRENT_TIMESTAMP_FN};
|
||||
use datatypes::schema::{ColumnDefaultConstraint, ColumnSchema, COMMENT_KEY};
|
||||
use datatypes::types::cast::CastOption;
|
||||
use datatypes::types::{cast, TimestampType};
|
||||
@@ -270,8 +271,13 @@ fn parse_column_default_constraint(
|
||||
ColumnDefaultConstraint::Value(sql_value_to_value(column_name, data_type, v)?)
|
||||
}
|
||||
ColumnOption::Default(Expr::Function(func)) => {
|
||||
let mut func = format!("{func}").to_lowercase();
|
||||
// normalize CURRENT_TIMESTAMP to CURRENT_TIMESTAMP()
|
||||
if func == CURRENT_TIMESTAMP {
|
||||
func = CURRENT_TIMESTAMP_FN.to_string();
|
||||
}
|
||||
// Always use lowercase for function expression
|
||||
ColumnDefaultConstraint::Function(format!("{func}").to_lowercase())
|
||||
ColumnDefaultConstraint::Function(func.to_lowercase())
|
||||
}
|
||||
ColumnOption::Default(expr) => {
|
||||
return UnsupportedDefaultValueSnafu {
|
||||
|
||||
Reference in New Issue
Block a user