Skip to content

Commit

Permalink
Fix parsing of EXTRACT to allow keywords after the FROM (#344)
Browse files Browse the repository at this point in the history
  • Loading branch information
alancai98 authored Apr 19, 2023
1 parent c276b0d commit 380f526
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixes
- Fix parsing of `EXTRACT` datetime parts `YEAR`, `TIMEZONE_HOUR`, and `TIMEZONE_MINUTE`
- Fix logical plan to eval plan conversion for `EvalOrderBySortSpec` with arguments `DESC` and `NULLS LAST`
- Fix parsing of `EXTRACT` to allow keywords after the `FROM`

## [0.3.0] - 2023-04-11
### Changed
Expand Down
58 changes: 57 additions & 1 deletion partiql-parser/src/preprocessor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ mod built_ins {
#[rustfmt::skip]
patterns: vec![
// e.g., extract(day from x) => extract("day":true, "from": x)
vec![Id(re), Syn(Token::True), Kw(Token::From), AnyOne(true), AnyStar(false)]
// Note the `true` passed to Any* as we need to support type-related keywords after `FROM`
// such as `TIME WITH TIME ZONE`
vec![Id(re), Syn(Token::True), Kw(Token::From), AnyOne(true), AnyStar(true)]
],
}
}
Expand Down Expand Up @@ -907,6 +909,60 @@ mod tests {
preprocess(r#"extract(second from a)"#)?,
lex(r#"extract(second:True, "from" : a)"#)?
);
assert_eq!(
preprocess(r#"extract(hour from TIME WITH TIME ZONE '01:23:45.678-06:30')"#)?,
lex(r#"extract(hour:True, "from" : TIME WITH TIME ZONE '01:23:45.678-06:30')"#)?
);
assert_eq!(
preprocess(r#"extract(minute from TIME WITH TIME ZONE '01:23:45.678-06:30')"#)?,
lex(r#"extract(minute:True, "from" : TIME WITH TIME ZONE '01:23:45.678-06:30')"#)?
);
assert_eq!(
preprocess(r#"extract(second from TIME WITH TIME ZONE '01:23:45.678-06:30')"#)?,
lex(r#"extract(second:True, "from" : TIME WITH TIME ZONE '01:23:45.678-06:30')"#)?
);
assert_eq!(
preprocess(r#"extract(timezone_hour from TIME WITH TIME ZONE '01:23:45.678-06:30')"#)?,
lex(
r#"extract(timezone_hour:True, "from" : TIME WITH TIME ZONE '01:23:45.678-06:30')"#
)?
);
assert_eq!(
preprocess(
r#"extract(timezone_minute from TIME WITH TIME ZONE '01:23:45.678-06:30')"#
)?,
lex(
r#"extract(timezone_minute:True, "from" : TIME WITH TIME ZONE '01:23:45.678-06:30')"#
)?
);
assert_eq!(
preprocess(r#"extract(hour from TIME (2) WITH TIME ZONE '01:23:45.678-06:30')"#)?,
lex(r#"extract(hour:True, "from" : TIME (2) WITH TIME ZONE '01:23:45.678-06:30')"#)?
);
assert_eq!(
preprocess(r#"extract(minute from TIME (2) WITH TIME ZONE '01:23:45.678-06:30')"#)?,
lex(r#"extract(minute:True, "from" : TIME (2) WITH TIME ZONE '01:23:45.678-06:30')"#)?
);
assert_eq!(
preprocess(r#"extract(second from TIME (2) WITH TIME ZONE '01:23:45.678-06:30')"#)?,
lex(r#"extract(second:True, "from" : TIME (2) WITH TIME ZONE '01:23:45.678-06:30')"#)?
);
assert_eq!(
preprocess(
r#"extract(timezone_hour from TIME (2) WITH TIME ZONE '01:23:45.678-06:30')"#
)?,
lex(
r#"extract(timezone_hour:True, "from" : TIME (2) WITH TIME ZONE '01:23:45.678-06:30')"#
)?
);
assert_eq!(
preprocess(
r#"extract(timezone_minute from TIME (2) WITH TIME ZONE '01:23:45.678-06:30')"#
)?,
lex(
r#"extract(timezone_minute:True, "from" : TIME (2) WITH TIME ZONE '01:23:45.678-06:30')"#
)?
);

assert_eq!(preprocess(r#"count(a)"#)?, lex(r#"count(a)"#)?);
assert_eq!(
Expand Down

2 comments on commit 380f526

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PartiQL (rust) Benchmark

Benchmark suite Current: 380f526 Previous: c276b0d Ratio
parse-1 6964 ns/iter (± 33) 6120 ns/iter (± 21) 1.14
parse-15 71203 ns/iter (± 144) 62313 ns/iter (± 49) 1.14
parse-30 140899 ns/iter (± 320) 122828 ns/iter (± 276) 1.15
compile-1 5757 ns/iter (± 34) 5219 ns/iter (± 48) 1.10
compile-15 42092 ns/iter (± 204) 36763 ns/iter (± 63) 1.14
compile-30 85191 ns/iter (± 193) 75859 ns/iter (± 81) 1.12
plan-1 23317 ns/iter (± 65) 19600 ns/iter (± 12) 1.19
plan-15 434967 ns/iter (± 4659) 358497 ns/iter (± 810) 1.21
plan-30 872789 ns/iter (± 1855) 729668 ns/iter (± 1517) 1.20
eval-1 26411375 ns/iter (± 721629) 21119571 ns/iter (± 81713) 1.25
eval-15 141055752 ns/iter (± 658685) 121465910 ns/iter (± 543514) 1.16
eval-30 268288230 ns/iter (± 8240336) 238587461 ns/iter (± 478116) 1.12
join 18142 ns/iter (± 850) 14417 ns/iter (± 60) 1.26
simple 8031 ns/iter (± 85) 7176 ns/iter (± 11) 1.12
simple-no 733 ns/iter (± 3) 636 ns/iter (± 0) 1.15
numbers 173 ns/iter (± 0) 107 ns/iter (± 0) 1.62
parse-simple 829 ns/iter (± 2) 732 ns/iter (± 0) 1.13
parse-ion 3079 ns/iter (± 15) 2706 ns/iter (± 1) 1.14
parse-group 10263 ns/iter (± 40) 8937 ns/iter (± 14) 1.15
parse-complex 26473 ns/iter (± 121) 21854 ns/iter (± 89) 1.21
parse-complex-fexpr 41552 ns/iter (± 152) 34450 ns/iter (± 109) 1.21

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'PartiQL (rust) Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.50.

Benchmark suite Current: 380f526 Previous: c276b0d Ratio
numbers 173 ns/iter (± 0) 107 ns/iter (± 0) 1.62

This comment was automatically generated by workflow using github-action-benchmark.

CC: @alancai98 @alancai98 @partiql

Please sign in to comment.