mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-09-25 15:09:19 +00:00
Remove "SQL" prefix from "SQLDateTimeField" struct
I realized a moment too late that I'd missed a type name in
when removing the "SQL" prefix from types in ac555d7e8
. As far as I can
tell, this was the only oversight.
This commit is contained in:
parent
bafb20746f
commit
106c9f8efb
4 changed files with 30 additions and 30 deletions
|
@ -29,7 +29,7 @@ pub use self::query::{
|
||||||
Cte, Fetch, Join, JoinConstraint, JoinOperator, OrderByExpr, Query, Select, SelectItem,
|
Cte, Fetch, Join, JoinConstraint, JoinOperator, OrderByExpr, Query, Select, SelectItem,
|
||||||
SetExpr, SetOperator, TableAlias, TableFactor, TableWithJoins, Values,
|
SetExpr, SetOperator, TableAlias, TableFactor, TableWithJoins, Values,
|
||||||
};
|
};
|
||||||
pub use self::value::{SQLDateTimeField, Value};
|
pub use self::value::{DateTimeField, Value};
|
||||||
|
|
||||||
/// Like `vec.join(", ")`, but for any types implementing ToString.
|
/// Like `vec.join(", ")`, but for any types implementing ToString.
|
||||||
fn comma_separated_string<I>(iter: I) -> String
|
fn comma_separated_string<I>(iter: I) -> String
|
||||||
|
@ -105,7 +105,7 @@ pub enum Expr {
|
||||||
data_type: DataType,
|
data_type: DataType,
|
||||||
},
|
},
|
||||||
Extract {
|
Extract {
|
||||||
field: SQLDateTimeField,
|
field: DateTimeField,
|
||||||
expr: Box<Expr>,
|
expr: Box<Expr>,
|
||||||
},
|
},
|
||||||
/// `expr COLLATE collation`
|
/// `expr COLLATE collation`
|
||||||
|
|
|
@ -43,9 +43,9 @@ pub enum Value {
|
||||||
/// so the user will have to reject intervals like `HOUR TO YEAR`.
|
/// so the user will have to reject intervals like `HOUR TO YEAR`.
|
||||||
Interval {
|
Interval {
|
||||||
value: String,
|
value: String,
|
||||||
leading_field: SQLDateTimeField,
|
leading_field: DateTimeField,
|
||||||
leading_precision: Option<u64>,
|
leading_precision: Option<u64>,
|
||||||
last_field: Option<SQLDateTimeField>,
|
last_field: Option<DateTimeField>,
|
||||||
/// The seconds precision can be specified in SQL source as
|
/// The seconds precision can be specified in SQL source as
|
||||||
/// `INTERVAL '__' SECOND(_, x)` (in which case the `leading_field`
|
/// `INTERVAL '__' SECOND(_, x)` (in which case the `leading_field`
|
||||||
/// will be `Second` and the `last_field` will be `None`),
|
/// will be `Second` and the `last_field` will be `None`),
|
||||||
|
@ -70,7 +70,7 @@ impl ToString for Value {
|
||||||
Value::Timestamp(v) => format!("TIMESTAMP '{}'", escape_single_quote_string(v)),
|
Value::Timestamp(v) => format!("TIMESTAMP '{}'", escape_single_quote_string(v)),
|
||||||
Value::Interval {
|
Value::Interval {
|
||||||
value,
|
value,
|
||||||
leading_field: SQLDateTimeField::Second,
|
leading_field: DateTimeField::Second,
|
||||||
leading_precision: Some(leading_precision),
|
leading_precision: Some(leading_precision),
|
||||||
last_field,
|
last_field,
|
||||||
fractional_seconds_precision: Some(fractional_seconds_precision),
|
fractional_seconds_precision: Some(fractional_seconds_precision),
|
||||||
|
@ -114,7 +114,7 @@ impl ToString for Value {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Hash)]
|
||||||
pub enum SQLDateTimeField {
|
pub enum DateTimeField {
|
||||||
Year,
|
Year,
|
||||||
Month,
|
Month,
|
||||||
Day,
|
Day,
|
||||||
|
@ -123,15 +123,15 @@ pub enum SQLDateTimeField {
|
||||||
Second,
|
Second,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToString for SQLDateTimeField {
|
impl ToString for DateTimeField {
|
||||||
fn to_string(&self) -> String {
|
fn to_string(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
SQLDateTimeField::Year => "YEAR".to_string(),
|
DateTimeField::Year => "YEAR".to_string(),
|
||||||
SQLDateTimeField::Month => "MONTH".to_string(),
|
DateTimeField::Month => "MONTH".to_string(),
|
||||||
SQLDateTimeField::Day => "DAY".to_string(),
|
DateTimeField::Day => "DAY".to_string(),
|
||||||
SQLDateTimeField::Hour => "HOUR".to_string(),
|
DateTimeField::Hour => "HOUR".to_string(),
|
||||||
SQLDateTimeField::Minute => "MINUTE".to_string(),
|
DateTimeField::Minute => "MINUTE".to_string(),
|
||||||
SQLDateTimeField::Second => "SECOND".to_string(),
|
DateTimeField::Second => "SECOND".to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -431,16 +431,16 @@ impl Parser {
|
||||||
// operator and interval qualifiers. EXTRACT supports a wider set of
|
// operator and interval qualifiers. EXTRACT supports a wider set of
|
||||||
// date/time fields than interval qualifiers, so this function may need to
|
// date/time fields than interval qualifiers, so this function may need to
|
||||||
// be split in two.
|
// be split in two.
|
||||||
pub fn parse_date_time_field(&mut self) -> Result<SQLDateTimeField, ParserError> {
|
pub fn parse_date_time_field(&mut self) -> Result<DateTimeField, ParserError> {
|
||||||
let tok = self.next_token();
|
let tok = self.next_token();
|
||||||
if let Some(Token::Word(ref k)) = tok {
|
if let Some(Token::Word(ref k)) = tok {
|
||||||
match k.keyword.as_ref() {
|
match k.keyword.as_ref() {
|
||||||
"YEAR" => Ok(SQLDateTimeField::Year),
|
"YEAR" => Ok(DateTimeField::Year),
|
||||||
"MONTH" => Ok(SQLDateTimeField::Month),
|
"MONTH" => Ok(DateTimeField::Month),
|
||||||
"DAY" => Ok(SQLDateTimeField::Day),
|
"DAY" => Ok(DateTimeField::Day),
|
||||||
"HOUR" => Ok(SQLDateTimeField::Hour),
|
"HOUR" => Ok(DateTimeField::Hour),
|
||||||
"MINUTE" => Ok(SQLDateTimeField::Minute),
|
"MINUTE" => Ok(DateTimeField::Minute),
|
||||||
"SECOND" => Ok(SQLDateTimeField::Second),
|
"SECOND" => Ok(DateTimeField::Second),
|
||||||
_ => self.expected("date/time field", tok)?,
|
_ => self.expected("date/time field", tok)?,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -478,7 +478,7 @@ impl Parser {
|
||||||
let leading_field = self.parse_date_time_field()?;
|
let leading_field = self.parse_date_time_field()?;
|
||||||
|
|
||||||
let (leading_precision, last_field, fsec_precision) =
|
let (leading_precision, last_field, fsec_precision) =
|
||||||
if leading_field == SQLDateTimeField::Second {
|
if leading_field == DateTimeField::Second {
|
||||||
// SQL mandates special syntax for `SECOND TO SECOND` literals.
|
// SQL mandates special syntax for `SECOND TO SECOND` literals.
|
||||||
// Instead of
|
// Instead of
|
||||||
// `SECOND [(<leading precision>)] TO SECOND[(<fractional seconds precision>)]`
|
// `SECOND [(<leading precision>)] TO SECOND[(<fractional seconds precision>)]`
|
||||||
|
@ -491,7 +491,7 @@ impl Parser {
|
||||||
let leading_precision = self.parse_optional_precision()?;
|
let leading_precision = self.parse_optional_precision()?;
|
||||||
if self.parse_keyword("TO") {
|
if self.parse_keyword("TO") {
|
||||||
let last_field = Some(self.parse_date_time_field()?);
|
let last_field = Some(self.parse_date_time_field()?);
|
||||||
let fsec_precision = if last_field == Some(SQLDateTimeField::Second) {
|
let fsec_precision = if last_field == Some(DateTimeField::Second) {
|
||||||
self.parse_optional_precision()?
|
self.parse_optional_precision()?
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
|
@ -845,7 +845,7 @@ fn parse_extract() {
|
||||||
let select = verified_only_select(sql);
|
let select = verified_only_select(sql);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
&Expr::Extract {
|
&Expr::Extract {
|
||||||
field: SQLDateTimeField::Year,
|
field: DateTimeField::Year,
|
||||||
expr: Box::new(Expr::Identifier("d".to_string())),
|
expr: Box::new(Expr::Identifier("d".to_string())),
|
||||||
},
|
},
|
||||||
expr_from_projection(only(&select.projection)),
|
expr_from_projection(only(&select.projection)),
|
||||||
|
@ -1236,9 +1236,9 @@ fn parse_literal_interval() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
&Expr::Value(Value::Interval {
|
&Expr::Value(Value::Interval {
|
||||||
value: "1-1".into(),
|
value: "1-1".into(),
|
||||||
leading_field: SQLDateTimeField::Year,
|
leading_field: DateTimeField::Year,
|
||||||
leading_precision: None,
|
leading_precision: None,
|
||||||
last_field: Some(SQLDateTimeField::Month),
|
last_field: Some(DateTimeField::Month),
|
||||||
fractional_seconds_precision: None,
|
fractional_seconds_precision: None,
|
||||||
}),
|
}),
|
||||||
expr_from_projection(only(&select.projection)),
|
expr_from_projection(only(&select.projection)),
|
||||||
|
@ -1249,9 +1249,9 @@ fn parse_literal_interval() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
&Expr::Value(Value::Interval {
|
&Expr::Value(Value::Interval {
|
||||||
value: "01:01.01".into(),
|
value: "01:01.01".into(),
|
||||||
leading_field: SQLDateTimeField::Minute,
|
leading_field: DateTimeField::Minute,
|
||||||
leading_precision: Some(5),
|
leading_precision: Some(5),
|
||||||
last_field: Some(SQLDateTimeField::Second),
|
last_field: Some(DateTimeField::Second),
|
||||||
fractional_seconds_precision: Some(5),
|
fractional_seconds_precision: Some(5),
|
||||||
}),
|
}),
|
||||||
expr_from_projection(only(&select.projection)),
|
expr_from_projection(only(&select.projection)),
|
||||||
|
@ -1262,7 +1262,7 @@ fn parse_literal_interval() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
&Expr::Value(Value::Interval {
|
&Expr::Value(Value::Interval {
|
||||||
value: "1".into(),
|
value: "1".into(),
|
||||||
leading_field: SQLDateTimeField::Second,
|
leading_field: DateTimeField::Second,
|
||||||
leading_precision: Some(5),
|
leading_precision: Some(5),
|
||||||
last_field: None,
|
last_field: None,
|
||||||
fractional_seconds_precision: Some(4),
|
fractional_seconds_precision: Some(4),
|
||||||
|
@ -1275,7 +1275,7 @@ fn parse_literal_interval() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
&Expr::Value(Value::Interval {
|
&Expr::Value(Value::Interval {
|
||||||
value: "10".into(),
|
value: "10".into(),
|
||||||
leading_field: SQLDateTimeField::Hour,
|
leading_field: DateTimeField::Hour,
|
||||||
leading_precision: None,
|
leading_precision: None,
|
||||||
last_field: None,
|
last_field: None,
|
||||||
fractional_seconds_precision: None,
|
fractional_seconds_precision: None,
|
||||||
|
@ -1288,7 +1288,7 @@ fn parse_literal_interval() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
&Expr::Value(Value::Interval {
|
&Expr::Value(Value::Interval {
|
||||||
value: "10".into(),
|
value: "10".into(),
|
||||||
leading_field: SQLDateTimeField::Hour,
|
leading_field: DateTimeField::Hour,
|
||||||
leading_precision: Some(1),
|
leading_precision: Some(1),
|
||||||
last_field: None,
|
last_field: None,
|
||||||
fractional_seconds_precision: None,
|
fractional_seconds_precision: None,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue