mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-12-23 11:12:51 +00:00
Support pluralized time units (#1630)
This commit is contained in:
parent
0cd49fb699
commit
62bcaa1c98
4 changed files with 122 additions and 18 deletions
|
|
@ -155,7 +155,9 @@ impl fmt::Display for DollarQuotedString {
|
|||
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
|
||||
pub enum DateTimeField {
|
||||
Year,
|
||||
Years,
|
||||
Month,
|
||||
Months,
|
||||
/// Week optionally followed by a WEEKDAY.
|
||||
///
|
||||
/// ```sql
|
||||
|
|
@ -164,14 +166,19 @@ pub enum DateTimeField {
|
|||
///
|
||||
/// [BigQuery](https://cloud.google.com/bigquery/docs/reference/standard-sql/date_functions#extract)
|
||||
Week(Option<Ident>),
|
||||
Weeks,
|
||||
Day,
|
||||
DayOfWeek,
|
||||
DayOfYear,
|
||||
Days,
|
||||
Date,
|
||||
Datetime,
|
||||
Hour,
|
||||
Hours,
|
||||
Minute,
|
||||
Minutes,
|
||||
Second,
|
||||
Seconds,
|
||||
Century,
|
||||
Decade,
|
||||
Dow,
|
||||
|
|
@ -210,7 +217,9 @@ impl fmt::Display for DateTimeField {
|
|||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
DateTimeField::Year => write!(f, "YEAR"),
|
||||
DateTimeField::Years => write!(f, "YEARS"),
|
||||
DateTimeField::Month => write!(f, "MONTH"),
|
||||
DateTimeField::Months => write!(f, "MONTHS"),
|
||||
DateTimeField::Week(week_day) => {
|
||||
write!(f, "WEEK")?;
|
||||
if let Some(week_day) = week_day {
|
||||
|
|
@ -218,14 +227,19 @@ impl fmt::Display for DateTimeField {
|
|||
}
|
||||
Ok(())
|
||||
}
|
||||
DateTimeField::Weeks => write!(f, "WEEKS"),
|
||||
DateTimeField::Day => write!(f, "DAY"),
|
||||
DateTimeField::DayOfWeek => write!(f, "DAYOFWEEK"),
|
||||
DateTimeField::DayOfYear => write!(f, "DAYOFYEAR"),
|
||||
DateTimeField::Days => write!(f, "DAYS"),
|
||||
DateTimeField::Date => write!(f, "DATE"),
|
||||
DateTimeField::Datetime => write!(f, "DATETIME"),
|
||||
DateTimeField::Hour => write!(f, "HOUR"),
|
||||
DateTimeField::Hours => write!(f, "HOURS"),
|
||||
DateTimeField::Minute => write!(f, "MINUTE"),
|
||||
DateTimeField::Minutes => write!(f, "MINUTES"),
|
||||
DateTimeField::Second => write!(f, "SECOND"),
|
||||
DateTimeField::Seconds => write!(f, "SECONDS"),
|
||||
DateTimeField::Century => write!(f, "CENTURY"),
|
||||
DateTimeField::Decade => write!(f, "DECADE"),
|
||||
DateTimeField::Dow => write!(f, "DOW"),
|
||||
|
|
|
|||
|
|
@ -234,6 +234,7 @@ define_keywords!(
|
|||
DAY,
|
||||
DAYOFWEEK,
|
||||
DAYOFYEAR,
|
||||
DAYS,
|
||||
DEALLOCATE,
|
||||
DEC,
|
||||
DECADE,
|
||||
|
|
@ -499,6 +500,7 @@ define_keywords!(
|
|||
MILLISECONDS,
|
||||
MIN,
|
||||
MINUTE,
|
||||
MINUTES,
|
||||
MINVALUE,
|
||||
MOD,
|
||||
MODE,
|
||||
|
|
@ -506,6 +508,7 @@ define_keywords!(
|
|||
MODIFY,
|
||||
MODULE,
|
||||
MONTH,
|
||||
MONTHS,
|
||||
MSCK,
|
||||
MULTISET,
|
||||
MUTATION,
|
||||
|
|
@ -698,6 +701,7 @@ define_keywords!(
|
|||
SEARCH,
|
||||
SECOND,
|
||||
SECONDARY,
|
||||
SECONDS,
|
||||
SECRET,
|
||||
SECURITY,
|
||||
SEED,
|
||||
|
|
@ -866,6 +870,7 @@ define_keywords!(
|
|||
VOLATILE,
|
||||
WAREHOUSE,
|
||||
WEEK,
|
||||
WEEKS,
|
||||
WHEN,
|
||||
WHENEVER,
|
||||
WHERE,
|
||||
|
|
@ -880,6 +885,7 @@ define_keywords!(
|
|||
XML,
|
||||
XOR,
|
||||
YEAR,
|
||||
YEARS,
|
||||
ZONE,
|
||||
ZORDER
|
||||
);
|
||||
|
|
|
|||
|
|
@ -2358,7 +2358,9 @@ impl<'a> Parser<'a> {
|
|||
match &next_token.token {
|
||||
Token::Word(w) => match w.keyword {
|
||||
Keyword::YEAR => Ok(DateTimeField::Year),
|
||||
Keyword::YEARS => Ok(DateTimeField::Years),
|
||||
Keyword::MONTH => Ok(DateTimeField::Month),
|
||||
Keyword::MONTHS => Ok(DateTimeField::Months),
|
||||
Keyword::WEEK => {
|
||||
let week_day = if dialect_of!(self is BigQueryDialect | GenericDialect)
|
||||
&& self.consume_token(&Token::LParen)
|
||||
|
|
@ -2371,14 +2373,19 @@ impl<'a> Parser<'a> {
|
|||
};
|
||||
Ok(DateTimeField::Week(week_day))
|
||||
}
|
||||
Keyword::WEEKS => Ok(DateTimeField::Weeks),
|
||||
Keyword::DAY => Ok(DateTimeField::Day),
|
||||
Keyword::DAYOFWEEK => Ok(DateTimeField::DayOfWeek),
|
||||
Keyword::DAYOFYEAR => Ok(DateTimeField::DayOfYear),
|
||||
Keyword::DAYS => Ok(DateTimeField::Days),
|
||||
Keyword::DATE => Ok(DateTimeField::Date),
|
||||
Keyword::DATETIME => Ok(DateTimeField::Datetime),
|
||||
Keyword::HOUR => Ok(DateTimeField::Hour),
|
||||
Keyword::HOURS => Ok(DateTimeField::Hours),
|
||||
Keyword::MINUTE => Ok(DateTimeField::Minute),
|
||||
Keyword::MINUTES => Ok(DateTimeField::Minutes),
|
||||
Keyword::SECOND => Ok(DateTimeField::Second),
|
||||
Keyword::SECONDS => Ok(DateTimeField::Seconds),
|
||||
Keyword::CENTURY => Ok(DateTimeField::Century),
|
||||
Keyword::DECADE => Ok(DateTimeField::Decade),
|
||||
Keyword::DOY => Ok(DateTimeField::Doy),
|
||||
|
|
@ -2605,12 +2612,19 @@ impl<'a> Parser<'a> {
|
|||
matches!(
|
||||
word.keyword,
|
||||
Keyword::YEAR
|
||||
| Keyword::YEARS
|
||||
| Keyword::MONTH
|
||||
| Keyword::MONTHS
|
||||
| Keyword::WEEK
|
||||
| Keyword::WEEKS
|
||||
| Keyword::DAY
|
||||
| Keyword::DAYS
|
||||
| Keyword::HOUR
|
||||
| Keyword::HOURS
|
||||
| Keyword::MINUTE
|
||||
| Keyword::MINUTES
|
||||
| Keyword::SECOND
|
||||
| Keyword::SECONDS
|
||||
| Keyword::CENTURY
|
||||
| Keyword::DECADE
|
||||
| Keyword::DOW
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue