mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
hbase support
This commit is contained in:
@@ -7,6 +7,11 @@ import java.util.List;
|
||||
import org.apache.hadoop.hbase.client.HTableInterface;
|
||||
import org.apache.hadoop.hbase.client.ResultScanner;
|
||||
import org.apache.hadoop.hbase.client.Scan;
|
||||
import org.apache.hadoop.hbase.filter.BinaryComparator;
|
||||
import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;
|
||||
import org.apache.hadoop.hbase.filter.Filter;
|
||||
import org.apache.hadoop.hbase.filter.FilterList;
|
||||
import org.apache.hadoop.hbase.filter.RowFilter;
|
||||
|
||||
import com.alibaba.druid.hbase.HBaseConnection;
|
||||
import com.alibaba.druid.hbase.HBasePreparedStatement;
|
||||
@@ -54,13 +59,18 @@ public class SingleTableQueryExecutePlan extends SingleTableExecutePlan {
|
||||
|
||||
byte[] bytes = HBaseUtils.toBytes(value);
|
||||
if ("id".equals(fieldName)) {
|
||||
if (condition.getOperator() == SQLBinaryOperator.GreaterThan) {
|
||||
if (condition.getOperator() == SQLBinaryOperator.GreaterThanOrEqual) {
|
||||
scan.setStartRow(bytes);
|
||||
} else if (condition.getOperator() == SQLBinaryOperator.LessThan) {
|
||||
scan.setStopRow(bytes);
|
||||
} else if (condition.getOperator() == SQLBinaryOperator.LessThanOrEqual) {
|
||||
RowFilter filter = new RowFilter(CompareOp.LESS_OR_EQUAL, new BinaryComparator(bytes));
|
||||
setFilter(scan, filter);
|
||||
} else {
|
||||
throw new SQLException("TODO");
|
||||
}
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,5 +83,17 @@ public class SingleTableQueryExecutePlan extends SingleTableExecutePlan {
|
||||
throw new SQLException("executeQuery error", e);
|
||||
}
|
||||
}
|
||||
|
||||
void setFilter(Scan scan, Filter filter) {
|
||||
if (scan.getFilter() == null) {
|
||||
scan.setFilter(filter);
|
||||
} else if (scan.getFilter() instanceof FilterList) {
|
||||
FilterList filterList = (FilterList) scan.getFilter();
|
||||
filterList.addFilter(filter);
|
||||
} else {
|
||||
FilterList filterList = new FilterList(scan.getFilter(), filter);
|
||||
scan.setFilter(filterList);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ public class HBaseDriverTest extends TestCase {
|
||||
HBaseDriver driver = new HBaseDriver();
|
||||
Connection conn = driver.connect("jdbc:druid-hbase:10.20.153.63", new Properties());
|
||||
|
||||
PreparedStatement stmt = conn.prepareStatement("SELECT id, name, gender, salary FROM test_user where id > 3 and id < ?");
|
||||
PreparedStatement stmt = conn.prepareStatement("SELECT id, name, gender, salary FROM test_user where id >= 3 and id <= ?");
|
||||
stmt.setInt(1, 6);
|
||||
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
|
||||
Reference in New Issue
Block a user