[feature](graph)Support querying data from the Nebula graph database (#19209)
Support querying data from the Nebula graph database This feature comes from the needs of commercial customers who have used Doris and Nebula, hoping to connect these two databases changes mainly include: * add New Graph Database JDBC Type * Adapt the type and map the graph to the Doris type
This commit is contained in:
@ -61,6 +61,7 @@ import java.util.Map;
|
||||
public class JdbcResource extends Resource {
|
||||
private static final Logger LOG = LogManager.getLogger(JdbcResource.class);
|
||||
|
||||
public static final String JDBC_NEBULA = "jdbc:nebula";
|
||||
public static final String JDBC_MYSQL = "jdbc:mysql";
|
||||
public static final String JDBC_MARIADB = "jdbc:mariadb";
|
||||
public static final String JDBC_POSTGRESQL = "jdbc:postgresql";
|
||||
@ -72,6 +73,7 @@ public class JdbcResource extends Resource {
|
||||
public static final String JDBC_PRESTO = "jdbc:presto";
|
||||
public static final String JDBC_OCEANBASE = "jdbc:oceanbase";
|
||||
|
||||
public static final String NEBULA = "NEBULA";
|
||||
public static final String MYSQL = "MYSQL";
|
||||
public static final String POSTGRESQL = "POSTGRESQL";
|
||||
public static final String ORACLE = "ORACLE";
|
||||
@ -296,6 +298,8 @@ public class JdbcResource extends Resource {
|
||||
} else {
|
||||
throw new DdlException("Invalid OceanBase mode: " + oceanbaseMode + ". Must be 'mysql' or 'oracle'");
|
||||
}
|
||||
} else if (url.startsWith(JDBC_NEBULA)) {
|
||||
return NEBULA;
|
||||
}
|
||||
throw new DdlException("Unsupported jdbc database type, please check jdbcUrl: " + url);
|
||||
}
|
||||
|
||||
@ -70,6 +70,7 @@ public class JdbcTable extends Table {
|
||||
|
||||
static {
|
||||
Map<String, TOdbcTableType> tempMap = new CaseInsensitiveMap();
|
||||
tempMap.put("nebula", TOdbcTableType.NEBULA);
|
||||
tempMap.put("mysql", TOdbcTableType.MYSQL);
|
||||
tempMap.put("postgresql", TOdbcTableType.POSTGRESQL);
|
||||
tempMap.put("sqlserver", TOdbcTableType.SQLSERVER);
|
||||
|
||||
@ -20,6 +20,7 @@ package org.apache.doris.planner;
|
||||
import org.apache.doris.analysis.Analyzer;
|
||||
import org.apache.doris.analysis.Expr;
|
||||
import org.apache.doris.analysis.ExprSubstitutionMap;
|
||||
import org.apache.doris.analysis.FunctionCallExpr;
|
||||
import org.apache.doris.analysis.SlotDescriptor;
|
||||
import org.apache.doris.analysis.SlotRef;
|
||||
import org.apache.doris.analysis.TupleDescriptor;
|
||||
@ -53,6 +54,7 @@ public class JdbcScanNode extends ScanNode {
|
||||
private final List<String> filters = new ArrayList<String>();
|
||||
private String tableName;
|
||||
private TOdbcTableType jdbcType;
|
||||
private String graphQueryString = "";
|
||||
|
||||
public JdbcScanNode(PlanNodeId id, TupleDescriptor desc, boolean isJdbcExternalTable) {
|
||||
super(id, desc, "JdbcScanNode", StatisticalType.JDBC_SCAN_NODE);
|
||||
@ -71,6 +73,26 @@ public class JdbcScanNode extends ScanNode {
|
||||
public void init(Analyzer analyzer) throws UserException {
|
||||
super.init(analyzer);
|
||||
computeStats(analyzer);
|
||||
getGraphQueryString();
|
||||
}
|
||||
|
||||
private boolean isNebula() {
|
||||
return jdbcType == TOdbcTableType.NEBULA;
|
||||
}
|
||||
|
||||
private void getGraphQueryString() {
|
||||
if (!isNebula()) {
|
||||
return;
|
||||
}
|
||||
for (Expr expr : conjuncts) {
|
||||
FunctionCallExpr functionCallExpr = (FunctionCallExpr) expr;
|
||||
if ("g".equals(functionCallExpr.getFnName().getFunction())) {
|
||||
graphQueryString = functionCallExpr.getChild(0).getStringValue();
|
||||
break;
|
||||
}
|
||||
}
|
||||
//clean conjusts cause graph sannnode no need conjuncts
|
||||
conjuncts = Lists.newArrayList();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -130,6 +152,9 @@ public class JdbcScanNode extends ScanNode {
|
||||
}
|
||||
|
||||
private String getJdbcQueryStr() {
|
||||
if (isNebula()) {
|
||||
return graphQueryString;
|
||||
}
|
||||
StringBuilder sql = new StringBuilder("SELECT ");
|
||||
|
||||
// Oracle use the where clause to do top n
|
||||
|
||||
Reference in New Issue
Block a user