mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
hbase support
This commit is contained in:
@@ -12,6 +12,8 @@ import com.alibaba.druid.hbase.exec.SingleTableQueryExecutePlan;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBinaryOperator;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLInsertStatement;
|
||||
@@ -36,6 +38,18 @@ public class HBasePreparedStatement extends PreparedStatementBase implements Pre
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
private void splitCondition(List<SQLExpr> conditions, SQLExpr expr) {
|
||||
if (expr instanceof SQLBinaryOpExpr) {
|
||||
SQLBinaryOpExpr binaryExpr = (SQLBinaryOpExpr) expr;
|
||||
if (binaryExpr.getOperator() == SQLBinaryOperator.BooleanAnd) {
|
||||
splitCondition(conditions, binaryExpr.getLeft());
|
||||
splitCondition(conditions, binaryExpr.getRight());
|
||||
return;
|
||||
}
|
||||
}
|
||||
conditions.add(expr);
|
||||
}
|
||||
|
||||
public void init() throws SQLException {
|
||||
String dbType = this.hbaseConnection.getConnectProperties().getProperty("dbType");
|
||||
@@ -59,6 +73,8 @@ public class HBasePreparedStatement extends PreparedStatementBase implements Pre
|
||||
|
||||
SingleTableQueryExecutePlan singleTableQueryExecuetePlan = new SingleTableQueryExecutePlan();
|
||||
singleTableQueryExecuetePlan.setTableName(tableName);
|
||||
|
||||
splitCondition(singleTableQueryExecuetePlan.getConditions(), selectQueryBlock.getWhere());
|
||||
|
||||
this.executePlan = singleTableQueryExecuetePlan;
|
||||
} else if (sqlStmt instanceof SQLInsertStatement) {
|
||||
|
||||
@@ -11,10 +11,20 @@ import org.apache.hadoop.hbase.client.Scan;
|
||||
import com.alibaba.druid.hbase.HBaseConnection;
|
||||
import com.alibaba.druid.hbase.HBasePreparedStatement;
|
||||
import com.alibaba.druid.hbase.HBaseResultSet;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
|
||||
public class SingleTableQueryExecutePlan extends SingleTableExecutePlan {
|
||||
|
||||
private List<String> columeNames = new ArrayList<String>();
|
||||
private List<String> columeNames = new ArrayList<String>();
|
||||
private List<SQLExpr> conditions = new ArrayList<SQLExpr>();
|
||||
|
||||
public List<SQLExpr> getConditions() {
|
||||
return conditions;
|
||||
}
|
||||
|
||||
public void setConditions(List<SQLExpr> conditions) {
|
||||
this.conditions = conditions;
|
||||
}
|
||||
|
||||
public SingleTableQueryExecutePlan(){
|
||||
|
||||
|
||||
Reference in New Issue
Block a user