fix: fix f64 has no sufficient precision during parsing (#3483)

This commit is contained in:
Weny Xu
2024-03-11 17:28:40 +08:00
committed by GitHub
parent da098f5568
commit e767f37241
6 changed files with 84 additions and 1 deletions

View File

@@ -1495,4 +1495,25 @@ ENGINE=mito";
ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}, ParseOptions::default());
let _ = result.unwrap();
}
#[test]
fn test_incorrect_default_value_issue_3479() {
let sql = r#"CREATE TABLE `ExcePTuRi`(
non TIMESTAMP(6) TIME INDEX,
`iUSTO` DOUBLE DEFAULT 0.047318541668048164
)"#;
let result =
ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}, ParseOptions::default())
.unwrap();
assert_eq!(1, result.len());
match &result[0] {
Statement::CreateTable(c) => {
assert_eq!(
"`iUSTO` DOUBLE DEFAULT 0.047318541668048164",
c.columns[1].to_string()
);
}
_ => unreachable!(),
}
}
}

View File

@@ -904,6 +904,29 @@ mod tests {
);
}
#[test]
fn test_incorrect_default_value_issue_3479() {
let opts = vec![ColumnOptionDef {
name: None,
option: ColumnOption::Default(Expr::Value(SqlValue::Number(
"0.047318541668048164".into(),
false,
))),
}];
let constraint = parse_column_default_constraint(
"coll",
&ConcreteDataType::float64_datatype(),
&opts,
None,
)
.unwrap()
.unwrap();
assert_eq!("0.047318541668048164", constraint.to_string());
let encoded: Vec<u8> = constraint.clone().try_into().unwrap();
let decoded = ColumnDefaultConstraint::try_from(encoded.as_ref()).unwrap();
assert_eq!(decoded, constraint);
}
#[test]
pub fn test_sql_column_def_to_grpc_column_def() {
// test basic