-
Notifications
You must be signed in to change notification settings - Fork 601
Add support for PostgreSQL/Redshift geometric operators #1723
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -386,6 +386,10 @@ pub enum DataType { | |
/// | ||
/// [bigquery]: https://cloud.google.com/bigquery/docs/user-defined-functions#templated-sql-udf-parameters | ||
AnyType, | ||
/// geometric type | ||
/// | ||
/// [Postgres]: https://www.postgresql.org/docs/9.5/functions-geometry.html | ||
GeometricType(GeometricTypeKind), | ||
} | ||
|
||
impl fmt::Display for DataType { | ||
|
@@ -639,6 +643,7 @@ impl fmt::Display for DataType { | |
DataType::Trigger => write!(f, "TRIGGER"), | ||
DataType::AnyType => write!(f, "ANY TYPE"), | ||
DataType::Table(fields) => write!(f, "TABLE({})", display_comma_separated(fields)), | ||
DataType::GeometricType(kind) => write!(f, "{}", kind), | ||
} | ||
} | ||
} | ||
|
@@ -915,3 +920,34 @@ pub enum ArrayElemTypeDef { | |
/// `Array(Int64)` | ||
Parenthesis(Box<DataType>), | ||
} | ||
|
||
/// Represents different types of geometric shapes which are commonly used in | ||
/// PostgreSQL/Redshift for spatial operations and geometry-related computations. | ||
/// | ||
/// [Postgres]: https://www.postgresql.org/docs/9.5/functions-geometry.html | ||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we add a short description to this struct with a link to the docs? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] | ||
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))] | ||
pub enum GeometricTypeKind { | ||
Point, | ||
Line, | ||
LineSegment, | ||
GeometricBox, | ||
GeometricPath, | ||
Polygon, | ||
Circle, | ||
} | ||
|
||
impl fmt::Display for GeometricTypeKind { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
match self { | ||
GeometricTypeKind::Point => write!(f, "point"), | ||
GeometricTypeKind::Line => write!(f, "line"), | ||
GeometricTypeKind::LineSegment => write!(f, "lseg"), | ||
GeometricTypeKind::GeometricBox => write!(f, "box"), | ||
GeometricTypeKind::GeometricPath => write!(f, "path"), | ||
GeometricTypeKind::Polygon => write!(f, "polygon"), | ||
GeometricTypeKind::Circle => write!(f, "circle"), | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -591,18 +591,34 @@ pub trait Dialect: Debug + Any { | |
| Token::ExclamationMarkDoubleTilde | ||
| Token::ExclamationMarkDoubleTildeAsterisk | ||
| Token::Spaceship => Ok(p!(Eq)), | ||
Token::Pipe => Ok(p!(Pipe)), | ||
Token::Pipe | ||
| Token::QuestionMarkDash | ||
| Token::DoubleSharp | ||
| Token::Overlap | ||
| Token::AmpersandLeftAngleBracket | ||
| Token::AmpersandRightAngleBracket | ||
| Token::QuestionMarkDashVerticalBar | ||
| Token::AmpersandLeftAngleBracketVerticalBar | ||
| Token::VerticalBarAmpersandRightAngleBracket | ||
| Token::TwoWayArrow | ||
| Token::LeftAngleBracketCaret | ||
| Token::RightAngleBracketCaret | ||
| Token::QuestionMarkSharp | ||
| Token::QuestionMarkDoubleVerticalBar | ||
| Token::QuestionPipe | ||
| Token::TildeEqual | ||
| Token::AtSign | ||
| Token::ShiftLeftVerticalBar | ||
| Token::VerticalBarShiftRight => Ok(p!(Pipe)), | ||
Token::Caret | Token::Sharp | Token::ShiftRight | Token::ShiftLeft => Ok(p!(Caret)), | ||
Token::Ampersand => Ok(p!(Ampersand)), | ||
Token::Plus | Token::Minus => Ok(p!(PlusMinus)), | ||
Token::Mul | Token::Div | Token::DuckIntDiv | Token::Mod | Token::StringConcat => { | ||
Ok(p!(MulDivModOp)) | ||
} | ||
Token::DoubleColon | ||
| Token::ExclamationMark | ||
| Token::LBracket | ||
| Token::Overlap | ||
| Token::CaretAt => Ok(p!(DoubleColon)), | ||
Token::DoubleColon | Token::ExclamationMark | Token::LBracket | Token::CaretAt => { | ||
Ok(p!(DoubleColon)) | ||
} | ||
Token::Arrow | ||
| Token::LongArrow | ||
| Token::HashArrow | ||
|
@@ -614,7 +630,6 @@ pub trait Dialect: Debug + Any { | |
| Token::AtAt | ||
| Token::Question | ||
| Token::QuestionAnd | ||
| Token::QuestionPipe | ||
| Token::CustomBinaryOperator(_) => Ok(p!(PgOther)), | ||
_ => Ok(self.prec_unknown()), | ||
} | ||
|
@@ -912,6 +927,13 @@ pub trait Dialect: Debug + Any { | |
fn supports_array_typedef_size(&self) -> bool { | ||
false | ||
} | ||
/// Returns true if the dialect supports geometric types. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we add a link to the postgres docs here (and maybe an example sql)? it would help folks with context on what we mean by geometric types There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
/// | ||
/// Postgres: <https://www.postgresql.org/docs/9.5/functions-geometry.html> | ||
/// e.g. @@ circle '((0,0),10)' | ||
fn supports_geometric_types(&self) -> bool { | ||
false | ||
} | ||
} | ||
|
||
/// This represents the operators for which precedence must be defined | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we include a link to the postgres docs here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done