hbas support

This commit is contained in:
温少
2012-05-18 23:04:32 +08:00
3 changed files with 17 additions and 5 deletions
@@ -15,7 +15,7 @@ public class HBaseDriver implements Driver {
return null;
}
String rest = url.substring(PREFIX.length() + 1);
String rest = url.substring(PREFIX.length());
info.put("hbase.zookeeper.quorum", rest);
@@ -16,6 +16,7 @@ public class HBaseResultSet extends ResultSetBase {
private HBaseStatementInterface statement;
private ResultScanner scanner;
private Result result;
private byte[] family = Bytes.toBytes("d");
public HBaseResultSet(HBaseStatementInterface statement, ResultScanner scanner){
super(statement);
@@ -60,13 +61,21 @@ public class HBaseResultSet extends ResultSetBase {
public Object getObjectInternal(int columnIndex) {
return null;
}
@Override
public String getString(String columnName) throws SQLException {
byte[] bytes = getBytes(columnName);
return Bytes.toString(bytes);
}
public byte[] getBytes(String columnName) throws SQLException {
if ("@ROW".equals(columnName)) {
return result.getRow();
}
byte[] qualifier = Bytes.toBytes(columnName);
byte[] family = Bytes.toBytes("d");
byte[] value = result.getValue(family, qualifier);
return Bytes.toString(value);
return value;
}
@Override
@@ -11,12 +11,15 @@ import junit.framework.TestCase;
public class HBaseDriverTest extends TestCase {
public void test_0 () throws Exception {
HBaseDriver driver = new HBaseDriver();
Connection conn = driver.connect("jdbc:druid-hbase::10.20.153.63", new Properties());
Connection conn = driver.connect("jdbc:druid-hbase:10.20.153.63", new Properties());
PreparedStatement stmt = conn.prepareStatement("SELECT * FROM test");
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
System.out.print(rs.getString("@ROW"));
System.out.print(' ');
System.out.print(rs.getString("id"));
System.out.println();
}
rs.close();
stmt.close();