mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-05-25 09:20:40 +00:00
feat: use our forked sqlparser to parse Geometry(POINT) syntax
This commit is contained in:
3
Cargo.lock
generated
3
Cargo.lock
generated
@@ -5156,8 +5156,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "sqlparser"
|
||||
version = "0.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "adbbea2526ad0d02ad9414a07c396078a5b944bbf9ca4fbab8f01bb4cb579081"
|
||||
source = "git+https://github.com/sunng87/sqlparser-rs.git?branch=feature/argument-for-custom-type-for-v015#1933b40f285d1eda49e38885bb2741af525a2ebe"
|
||||
dependencies = [
|
||||
"log",
|
||||
]
|
||||
|
||||
@@ -30,3 +30,6 @@ members = [
|
||||
"src/table-engine",
|
||||
"test-util",
|
||||
]
|
||||
|
||||
[patch.crates-io]
|
||||
sqlparser = { git = "https://github.com/sunng87/sqlparser-rs.git", branch = "feature/argument-for-custom-type-for-v015" }
|
||||
|
||||
@@ -7,8 +7,6 @@ use crate::prelude::LogicalTypeId;
|
||||
use crate::value::GeometryValue;
|
||||
use crate::vectors::geometry::GeometryVectorBuilder;
|
||||
|
||||
const GEOMETRY_TYPE_NAME: &str = "Geometry";
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub enum GeometryType {
|
||||
Point,
|
||||
@@ -22,7 +20,7 @@ impl Default for GeometryType {
|
||||
|
||||
impl DataType for GeometryType {
|
||||
fn name(&self) -> &str {
|
||||
GEOMETRY_TYPE_NAME
|
||||
Self::GEOMETRY_TYPE_NAME
|
||||
}
|
||||
|
||||
fn logical_type_id(&self) -> crate::type_id::LogicalTypeId {
|
||||
@@ -54,7 +52,8 @@ impl DataType for GeometryType {
|
||||
}
|
||||
|
||||
impl GeometryType {
|
||||
pub fn name() -> &'static str {
|
||||
GEOMETRY_TYPE_NAME
|
||||
}
|
||||
pub const GEOMETRY_TYPE_NAME: &'static str = "Geometry";
|
||||
pub const GEOMETRY_SUBTYPE_POINT_NAME: &'static str = "POINT";
|
||||
pub const GEOMETRY_SUBTYPE_LINESTRING_NAME: &'static str = "LINESTRING";
|
||||
pub const GEOMETRY_SUBTYPE_POLYGON_NAME: &'static str = "POLYGON";
|
||||
}
|
||||
|
||||
@@ -46,4 +46,3 @@ streaming-stats = "0.2"
|
||||
test-util = { path = "../../test-util" }
|
||||
tokio = { version = "1.0", features = ["full"] }
|
||||
tokio-stream = "0.1"
|
||||
|
||||
|
||||
@@ -9,5 +9,5 @@ common-error = { path = "../common/error" }
|
||||
common-time = { path = "../common/time" }
|
||||
datatypes = { path = "../datatypes" }
|
||||
snafu = { version = "0.7", features = ["backtraces"] }
|
||||
sqlparser = "0.15.0"
|
||||
sqlparser = { git = "https://github.com/sunng87/sqlparser-rs.git", branch = "feature/argument-for-custom-type-for-v015" }
|
||||
table-engine = { path = "../table-engine" }
|
||||
|
||||
@@ -256,8 +256,6 @@ fn sql_data_type_to_concrete_data_type(data_type: &SqlDataType) -> Result<Concre
|
||||
[type_name] => {
|
||||
if type_name.value.eq_ignore_ascii_case(DateTimeType::name()) {
|
||||
Ok(ConcreteDataType::datetime_datatype())
|
||||
} else if type_name.value.eq_ignore_ascii_case(GeometryType::name()) {
|
||||
Ok(ConcreteDataType::geometry_datatype(GeometryType::Point))
|
||||
} else {
|
||||
error::SqlTypeNotSupportedSnafu {
|
||||
t: data_type.clone(),
|
||||
@@ -270,6 +268,30 @@ fn sql_data_type_to_concrete_data_type(data_type: &SqlDataType) -> Result<Concre
|
||||
}
|
||||
.fail(),
|
||||
},
|
||||
SqlDataType::CustomWithArgs(obj_name, args) => match &obj_name.0[..] {
|
||||
[type_name] => {
|
||||
if type_name
|
||||
.value
|
||||
.eq_ignore_ascii_case(GeometryType::GEOMETRY_TYPE_NAME)
|
||||
{
|
||||
if let Some(subtype) = args.get(0) {
|
||||
let subtype = subtype.to_uppercase();
|
||||
if subtype == GeometryType::GEOMETRY_SUBTYPE_POINT_NAME {
|
||||
return Ok(ConcreteDataType::Geometry(GeometryType::Point));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
error::SqlTypeNotSupportedSnafu {
|
||||
t: data_type.clone(),
|
||||
}
|
||||
.fail()
|
||||
}
|
||||
_ => error::SqlTypeNotSupportedSnafu {
|
||||
t: data_type.clone(),
|
||||
}
|
||||
.fail(),
|
||||
},
|
||||
SqlDataType::Timestamp => Ok(ConcreteDataType::timestamp_millis_datatype()),
|
||||
_ => error::SqlTypeNotSupportedSnafu {
|
||||
t: data_type.clone(),
|
||||
@@ -326,6 +348,25 @@ mod tests {
|
||||
SqlDataType::Timestamp,
|
||||
ConcreteDataType::timestamp_millis_datatype(),
|
||||
);
|
||||
check_type(
|
||||
SqlDataType::CustomWithArgs(ObjectName(vec!["GEOMETRY".into()]), vec!["POINT".into()]),
|
||||
ConcreteDataType::geometry_datatype(GeometryType::Point),
|
||||
);
|
||||
|
||||
assert!(
|
||||
sql_data_type_to_concrete_data_type(&SqlDataType::CustomWithArgs(
|
||||
ObjectName(vec!["GEOMETRY".into()]),
|
||||
vec![]
|
||||
))
|
||||
.is_err()
|
||||
);
|
||||
assert!(
|
||||
sql_data_type_to_concrete_data_type(&SqlDataType::CustomWithArgs(
|
||||
ObjectName(vec!["GEOMETRY".into()]),
|
||||
vec!["DUMMY_TYPE".into()]
|
||||
))
|
||||
.is_err()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user