Skip to content

Commit 36236d0

Browse files
authored
fix(query): fix clone_expr_with_replacement (#18088)
* fix(query): fix clone_expr_with_replacement * fix(query): fix clone_expr_with_replacement
1 parent e5743a1 commit 36236d0

File tree

5 files changed

+46
-320
lines changed

5 files changed

+46
-320
lines changed

src/query/ast/src/parser/expr.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,19 +1626,22 @@ pub fn type_name(i: Input) -> IResult<TypeName> {
16261626
rule! { (FLOAT64 | DOUBLE) ~ PRECISION? },
16271627
);
16281628
let ty_decimal = map_res(
1629-
rule! { DECIMAL ~ "(" ~ #literal_u64 ~ ( "," ~ ^#literal_u64 )? ~ ")" },
1630-
|(_, _, precision, opt_scale, _)| {
1629+
rule! { DECIMAL ~ ( "(" ~ #literal_u64 ~ ( "," ~ ^#literal_u64 )? ~ ")" )? },
1630+
|(_, opt_precision)| {
1631+
let (precision, scale) = match opt_precision {
1632+
Some((_, precision, scale, _)) => {
1633+
(precision, scale.map(|(_, scale)| scale).unwrap_or(0))
1634+
}
1635+
None => (18, 3),
1636+
};
1637+
16311638
Ok(TypeName::Decimal {
16321639
precision: precision
16331640
.try_into()
16341641
.map_err(|_| nom::Err::Failure(ErrorKind::Other("precision is too large")))?,
1635-
scale: if let Some((_, scale)) = opt_scale {
1636-
scale
1637-
.try_into()
1638-
.map_err(|_| nom::Err::Failure(ErrorKind::Other("scale is too large")))?
1639-
} else {
1640-
0
1641-
},
1642+
scale: scale
1643+
.try_into()
1644+
.map_err(|_| nom::Err::Failure(ErrorKind::Other("scale is too large")))?,
16421645
})
16431646
},
16441647
);

src/query/ast/tests/it/parser.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,6 @@ fn test_statement_error() {
958958
r#"create table a (c float(10))"#,
959959
r#"create table a (c varch)"#,
960960
r#"create table a (c tuple())"#,
961-
r#"create table a (c decimal)"#,
962961
r#"create table a (b tuple(c int, uint64));"#,
963962
r#"CREATE TABLE t(c1 NULLABLE(int) NOT NULL);"#,
964963
r#"create table a (c1 decimal(38), c2 int) partition by ();"#,

src/query/ast/tests/it/testdata/stmt-error.txt

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,6 @@ error:
4949
| while parsing `CREATE [OR REPLACE] TABLE [IF NOT EXISTS] [<database>.]<table> [<source>] [<table_options>]`
5050

5151

52-
---------- Input ----------
53-
create table a (c decimal)
54-
---------- Output ---------
55-
error:
56-
--> SQL:1:26
57-
|
58-
1 | create table a (c decimal)
59-
| ------ - -------^ unexpected `)`, expecting `(`
60-
| | | |
61-
| | | while parsing type name
62-
| | while parsing `<column name> <type> [DEFAULT <expr>] [AS (<expr>) VIRTUAL] [AS (<expr>) STORED] [COMMENT '<comment>']`
63-
| while parsing `CREATE [OR REPLACE] TABLE [IF NOT EXISTS] [<database>.]<table> [<source>] [<table_options>]`
64-
65-
6652
---------- Input ----------
6753
create table a (b tuple(c int, uint64));
6854
---------- Output ---------

0 commit comments

Comments
 (0)