feat(nebula): add NebulaGraph 3.x browser support
This commit is contained in:
1 parent
e59a8c1bd4
commit
ef05a6a19b
69 files changed
+1737
-41
No files matched your search
@@ -905,7 +905,7 @@ pub fn profile_for(db_type: DatabaseType) -> DdlDialectProfile {
|
||||
|
||||
// Non-tabular / not applicable for relational CREATE TABLE
|
||||
Redis | MongoDb | DynamoDb | Elasticsearch | Easysearch | Solr | Meilisearch | Qdrant | Milvus | Weaviate
|
||||
| ChromaDb | Neo4j | Cassandra | Etcd | ZooKeeper | Nacos | Consul | InfluxDb3 | VictoriaMetrics
|
||||
| ChromaDb | Neo4j | Nebula | Cassandra | Etcd | ZooKeeper | Nacos | Consul | InfluxDb3 | VictoriaMetrics
|
||||
| MessageQueue | Mqtt | Hbase | Salesforce => conservative_ansi(db_type),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,6 +170,7 @@ pub fn quote_table_identifier(database_type: Option<DatabaseType>, name: &str) -
|
||||
}
|
||||
Some(DatabaseType::Informix) if is_simple_informix_identifier(name) => name.to_string(),
|
||||
Some(DatabaseType::Neo4j) => format!("`{}`", name.replace('`', "``")),
|
||||
Some(DatabaseType::Nebula) => format!("`{}`", name.replace('\\', "\\\\").replace('`', "\\`")),
|
||||
Some(DatabaseType::SqlServer) => format!("[{}]", name.replace(']', "]]")),
|
||||
_ => format!("\"{}\"", name.replace('"', "\"\"")),
|
||||
}
|
||||
|
||||
@@ -200,6 +200,9 @@ pub fn build_table_data_select_sql_with_database(
|
||||
if database_type == Some(DatabaseType::Neo4j) {
|
||||
return build_neo4j_table_select_sql(&options, limit);
|
||||
}
|
||||
if database_type == Some(DatabaseType::Nebula) {
|
||||
return build_nebula_table_select_sql(&options, limit);
|
||||
}
|
||||
if database_type == Some(DatabaseType::Salesforce) {
|
||||
return build_salesforce_table_select_sql(&options, limit);
|
||||
}
|
||||
@@ -939,6 +942,47 @@ pub(super) fn build_neo4j_table_select_sql(options: &TableDataSelectSqlOptions,
|
||||
format!("MATCH (n:{label}){where_clause} RETURN {returns}{order}{skip} LIMIT {limit};")
|
||||
}
|
||||
|
||||
fn build_nebula_table_select_sql(options: &TableDataSelectSqlOptions, limit: usize) -> String {
|
||||
let quote = |name: &str| quote_table_identifier(Some(DatabaseType::Nebula), name);
|
||||
let kind = quote(&options.table_name);
|
||||
let is_edge = options.table_type.as_deref().is_some_and(|kind| kind.eq_ignore_ascii_case("VIEW"));
|
||||
let (pattern, identity, projection) = if is_edge {
|
||||
let projection = if options.columns.is_empty() {
|
||||
"e AS `edge`".to_string()
|
||||
} else {
|
||||
options
|
||||
.columns
|
||||
.iter()
|
||||
.map(|column| format!("e.{} AS {}", quote(column), quote(column)))
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ")
|
||||
};
|
||||
(format!("MATCH ()-[e:{kind}]->()"), "src(e) AS `_src`, dst(e) AS `_dst`, rank(e) AS `_rank`", projection)
|
||||
} else {
|
||||
let projection = if options.columns.is_empty() {
|
||||
"v AS `vertex`".to_string()
|
||||
} else {
|
||||
options
|
||||
.columns
|
||||
.iter()
|
||||
.map(|column| format!("v.{kind}.{} AS {}", quote(column), quote(column)))
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ")
|
||||
};
|
||||
(format!("MATCH (v:{kind})"), "id(v) AS `_vid`", projection)
|
||||
};
|
||||
let predicate = normalize_where_input(options.where_input.as_deref());
|
||||
let where_clause = if predicate.is_empty() { String::new() } else { format!(" WHERE {predicate}") };
|
||||
let order = options
|
||||
.order_by
|
||||
.as_deref()
|
||||
.filter(|order| !order.trim().is_empty())
|
||||
.map(|order| format!(" ORDER BY {order}"))
|
||||
.unwrap_or_default();
|
||||
let skip = options.offset.filter(|offset| *offset > 0).map(|offset| format!(" SKIP {offset}")).unwrap_or_default();
|
||||
format!("{pattern}{where_clause} RETURN {identity}, {projection}{order}{skip} LIMIT {limit};")
|
||||
}
|
||||
|
||||
/// Salesforce's `FIELDS(ALL)` selector is only legal with a LIMIT of 200 or less.
|
||||
const SALESFORCE_FIELDS_ALL_MAX_LIMIT: usize = 200;
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ fn transfer_identifier_policy_preserves_legacy_output() {
|
||||
|
||||
#[test]
|
||||
fn quotes_identifiers_by_database_type() {
|
||||
assert_eq!(quote_table_identifier(Some(DatabaseType::Nebula), "tag`name"), "`tag\\`name`");
|
||||
assert_eq!(quote_table_identifier(Some(DatabaseType::Mysql), "user`name"), "`user``name`");
|
||||
assert_eq!(quote_table_identifier(Some(DatabaseType::ClickHouse), "user`name"), "`user``name`");
|
||||
assert_eq!(quote_table_identifier(Some(DatabaseType::Doris), "user`name"), "`user``name`");
|
||||
@@ -50,6 +51,29 @@ fn quotes_identifiers_by_database_type() {
|
||||
assert!(is_schema_aware(DatabaseType::Argo));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn builds_nebula_tag_and_edge_queries() {
|
||||
let tag = build_table_data_select_sql(TableDataSelectSqlOptions {
|
||||
database_type: Some(DatabaseType::Nebula),
|
||||
table_name: "player".into(),
|
||||
table_type: Some("TABLE".into()),
|
||||
columns: vec!["name".into()],
|
||||
limit: Some(20),
|
||||
..Default::default()
|
||||
});
|
||||
assert_eq!(tag, "MATCH (v:`player`) RETURN id(v) AS `_vid`, v.`player`.`name` AS `name` LIMIT 20;");
|
||||
|
||||
let edge = build_table_data_select_sql(TableDataSelectSqlOptions {
|
||||
database_type: Some(DatabaseType::Nebula),
|
||||
table_name: "serve".into(),
|
||||
table_type: Some("VIEW".into()),
|
||||
columns: vec!["start_year".into()],
|
||||
limit: Some(10),
|
||||
..Default::default()
|
||||
});
|
||||
assert_eq!(edge, "MATCH ()-[e:`serve`]->() RETURN src(e) AS `_src`, dst(e) AS `_dst`, rank(e) AS `_rank`, e.`start_year` AS `start_year` LIMIT 10;");
|
||||
}
|
||||
|
||||
/// Spanner databases are created in one of two immutable dialects. The connected
|
||||
/// agent reports the correct identifier quote; when it is missing the static mapping
|
||||
/// must fall back to GoogleSQL (backticks), because GoogleSQL treats double quotes as
|
||||
|
||||
Reference in new issue
Block a user