Skip to content

Commit 7441d33

Browse files
authored
fix(parser): allow timestamp as a function name (#17455)
* allow timestamp as a function name * fix
1 parent 054d5df commit 7441d33

File tree

6 files changed

+77
-38
lines changed

6 files changed

+77
-38
lines changed

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

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -957,39 +957,6 @@ pub fn expr_element(i: Input) -> IResult<WithSpan<ExprElement>> {
957957
value(TrimWhere::Leading, rule! { LEADING }),
958958
value(TrimWhere::Trailing, rule! { TRAILING }),
959959
));
960-
let trim = map(
961-
rule! {
962-
TRIM
963-
~ "("
964-
~ #subexpr(0) ~ ("," ~ #subexpr(0))?
965-
~ ^")"
966-
},
967-
|(name, _, expr, trim_str, _)| {
968-
if let Some(trim_str) = trim_str {
969-
let trim_str = trim_str.1;
970-
ExprElement::FunctionCall {
971-
func: FunctionCall {
972-
distinct: false,
973-
name: Identifier {
974-
span: Some(name.span),
975-
name: name.text().to_owned(),
976-
quote: None,
977-
ident_type: IdentifierType::None,
978-
},
979-
args: vec![expr, trim_str],
980-
params: vec![],
981-
window: None,
982-
lambda: None,
983-
},
984-
}
985-
} else {
986-
ExprElement::Trim {
987-
expr: Box::new(expr),
988-
trim_where: None,
989-
}
990-
}
991-
},
992-
);
993960
let trim_from = map(
994961
rule! {
995962
TRIM
@@ -1391,7 +1358,6 @@ pub fn expr_element(i: Input) -> IResult<WithSpan<ExprElement>> {
13911358
),
13921359
rule!(
13931360
#substring : "`SUBSTRING(... [FROM ...] [FOR ...])`"
1394-
| #trim : "`TRIM(...)`"
13951361
| #trim_from : "`TRIM([(BOTH | LEADEING | TRAILING) ... FROM ...)`"
13961362
| #is_distinct_from: "`... IS [NOT] DISTINCT FROM ...`"
13971363
| #chain_function_call : "x.function(...)"

src/query/ast/src/parser/token.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,10 +1573,10 @@ impl TokenKind {
15731573
| TokenKind::TABLE
15741574
| TokenKind::THEN
15751575
// | TokenKind::TIME
1576-
| TokenKind::TIMESTAMP
1576+
// | TokenKind::TIMESTAMP
15771577
| TokenKind::TRAILING
15781578
// | TokenKind::TREAT
1579-
| TokenKind::TRIM
1579+
// | TokenKind::TRIM
15801580
| TokenKind::TRUE
15811581
| TokenKind::TRY_CAST
15821582
// | TokenKind::UNIQUE

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,6 +1214,8 @@ fn test_expr() {
12141214
r#"TRY_CAST(col1 AS BIGINT UNSIGNED)"#,
12151215
r#"TRY_CAST(col1 AS TUPLE(BIGINT UNSIGNED NULL, BOOLEAN))"#,
12161216
r#"trim(leading 'abc' from 'def')"#,
1217+
r#"trim('aa','bb')"#,
1218+
r#"timestamp()"#, // issue #16628
12171219
r#"extract(year from d)"#,
12181220
r#"date_part(year, d)"#,
12191221
r#"position('a' in str)"#,

src/query/ast/tests/it/testdata/expr.txt

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,6 +1655,77 @@ Trim {
16551655
}
16561656

16571657

1658+
---------- Input ----------
1659+
trim('aa','bb')
1660+
---------- Output ---------
1661+
trim('aa', 'bb')
1662+
---------- AST ------------
1663+
FunctionCall {
1664+
span: Some(
1665+
0..15,
1666+
),
1667+
func: FunctionCall {
1668+
distinct: false,
1669+
name: Identifier {
1670+
span: Some(
1671+
0..4,
1672+
),
1673+
name: "trim",
1674+
quote: None,
1675+
ident_type: None,
1676+
},
1677+
args: [
1678+
Literal {
1679+
span: Some(
1680+
5..9,
1681+
),
1682+
value: String(
1683+
"aa",
1684+
),
1685+
},
1686+
Literal {
1687+
span: Some(
1688+
10..14,
1689+
),
1690+
value: String(
1691+
"bb",
1692+
),
1693+
},
1694+
],
1695+
params: [],
1696+
window: None,
1697+
lambda: None,
1698+
},
1699+
}
1700+
1701+
1702+
---------- Input ----------
1703+
timestamp()
1704+
---------- Output ---------
1705+
timestamp()
1706+
---------- AST ------------
1707+
FunctionCall {
1708+
span: Some(
1709+
0..11,
1710+
),
1711+
func: FunctionCall {
1712+
distinct: false,
1713+
name: Identifier {
1714+
span: Some(
1715+
0..9,
1716+
),
1717+
name: "timestamp",
1718+
quote: None,
1719+
ident_type: None,
1720+
},
1721+
args: [],
1722+
params: [],
1723+
window: None,
1724+
lambda: None,
1725+
},
1726+
}
1727+
1728+
16581729
---------- Input ----------
16591730
extract(year from d)
16601731
---------- Output ---------

tests/sqllogictests/suites/mode/standalone/explain/aggregate.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ explain select count(3), type, name, trim(name) as a from system.columns group b
9595
----
9696
EvalScalar
9797
├── output columns: [count(3) (#13), columns.name (#0), columns.type (#3), a (#14)]
98-
├── expressions: [trim_both(columns.name (#0), ' ')]
98+
├── expressions: [trim(columns.name (#0))]
9999
├── estimated rows: 0.00
100100
└── AggregateFinal
101101
├── output columns: [count(3) (#13), columns.name (#0), columns.type (#3)]

tests/sqllogictests/suites/mode/standalone/explain_native/aggregate.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ explain select count(3), type, name, trim(name) as a from system.columns group b
9595
----
9696
EvalScalar
9797
├── output columns: [count(3) (#13), columns.name (#0), columns.type (#3), a (#14)]
98-
├── expressions: [trim_both(columns.name (#0), ' ')]
98+
├── expressions: [trim(columns.name (#0))]
9999
├── estimated rows: 0.00
100100
└── AggregateFinal
101101
├── output columns: [count(3) (#13), columns.name (#0), columns.type (#3)]

0 commit comments

Comments
 (0)