feat(nebula): add NebulaGraph 3.x browser support

This commit is contained in:
Hand Sonic authored and GitHub committed 2026-09-29 21:03:12 +08:00
1 parent e59a8c1bd4
commit ef05a6a19b
69 files changed
+1737 -41

No files matched your search

+1
View File
@@ -66,6 +66,7 @@ const BRIDGE_REQUIRED_TYPES: &[&str] = &[
"informix",
"iris",
"neo4j",
"nebula",
"cassandra",
"bigquery",
"spanner",
@@ -2123,6 +2123,46 @@
"driverManagement": true
}
},
{
"dbType": "nebula",
"label": "NebulaGraph",
"runtimeMode": "agent",
"mcpMode": "bridge",
"agentKey": "nebula",
"driverProfiles": [
{
"profile": "nebula-v3",
"agentKey": "nebula",
"label": "NebulaGraph 3.x",
"storeVisible": false
}
],
"driverStoreVisible": true,
"driverStoreOrder": 53,
"singleConnectionPool": false,
"metadataConnectionScoped": false,
"skipTcpProbe": true,
"defaultPort": 9669,
"supportLevel": "browse",
"capabilities": {
"queryExecution": true,
"metadataBrowse": true,
"objectBrowser": true,
"objectSource": true,
"schemaSearch": false,
"diagram": false,
"tableDataEdit": false,
"tableStructureEdit": false,
"tableImport": false,
"dataTransfer": false,
"sqlFileExecution": false,
"databaseCreate": false,
"fieldLineage": false,
"sqlExplain": false,
"userAdmin": false,
"driverManagement": true
}
},
{
"dbType": "cassandra",
"label": "Apache Cassandra",
+1
View File
@@ -330,6 +330,7 @@ macro_rules! agent_connection_pool_database_type {
| DatabaseType::Db2
| DatabaseType::Informix
| DatabaseType::Neo4j
| DatabaseType::Nebula
| DatabaseType::Cassandra
| DatabaseType::Bigquery
| DatabaseType::Spanner
@@ -82,6 +82,15 @@ mod tests {
assert!(!driver_store_entries().any(|(key, _)| key.starts_with("transwarp-")));
}
#[test]
fn nebula_v3_profile_reuses_the_legacy_agent_package() {
for profile in [None, Some("nebula"), Some("nebula-v3")] {
assert_eq!(agent_key(&DatabaseType::Nebula, profile), Some("nebula"));
}
assert_eq!(driver_store_entries().filter(|(key, _)| *key == "nebula").count(), 1);
assert!(!driver_store_entries().any(|(key, _)| key == "nebula-v3"));
}
#[test]
fn h2_profiles_share_the_same_agent() {
assert_eq!(agent_key(&DatabaseType::H2, None), Some("h2"));
@@ -268,6 +268,7 @@ pub fn supports_sql_query(database_type: DatabaseType) -> bool {
| DatabaseType::InfluxDb3
| DatabaseType::VictoriaMetrics
| DatabaseType::Neo4j
| DatabaseType::Nebula
| DatabaseType::Etcd
)
}
@@ -559,6 +559,7 @@ fn unsupported_pagination_type(database_type: Option<DatabaseType>) -> bool {
database_type,
Some(
DatabaseType::Neo4j
| DatabaseType::Nebula
| DatabaseType::MongoDb
| DatabaseType::Redis
| DatabaseType::Salesforce
@@ -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
@@ -1185,6 +1185,7 @@ impl ConnectionConfig {
DatabaseType::Db2 => format!("db2://{host}:{port}{db_part}"),
DatabaseType::Informix => format!("informix://{host}:{port}{db_part}"),
DatabaseType::Neo4j => format!("neo4j://{host}:{port}{db_part}"),
DatabaseType::Nebula => format!("nebula://{host}:{port}{db_part}"),
DatabaseType::Cassandra => format!("cassandra://{host}:{port}{db_part}"),
DatabaseType::Bigquery => format!("bigquery://{host}/{db_part}"),
DatabaseType::Spanner => self.spanner_display_url(&host, port),
@@ -1442,6 +1443,9 @@ impl ConnectionConfig {
DatabaseType::Neo4j => {
format!("neo4j://{}:{}@{host}:{port}{db_part}", username, password)
}
DatabaseType::Nebula => {
format!("nebula://{}:{}@{host}:{port}{db_part}", username, password)
}
DatabaseType::Cassandra => {
format!("cassandra://{}:{}@{host}:{port}{db_part}", username, password)
}