mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
hbase support
This commit is contained in:
@@ -349,7 +349,7 @@ public abstract class ResultSetBase implements ResultSet {
|
||||
|
||||
@Override
|
||||
public BigDecimal getBigDecimal(String columnLabel) throws SQLException {
|
||||
return getBigDecimal(Integer.parseInt(columnLabel));
|
||||
return getBigDecimal(findColumn(columnLabel));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -632,7 +632,7 @@ public abstract class ResultSetBase implements ResultSet {
|
||||
|
||||
@Override
|
||||
public void updateObject(String columnLabel, Object x) throws SQLException {
|
||||
updateObject(Integer.parseInt(columnLabel), x);
|
||||
updateObject(findColumn(columnLabel), x);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -975,82 +975,82 @@ public abstract class ResultSetBase implements ResultSet {
|
||||
|
||||
@Override
|
||||
public String getString(String columnLabel) throws SQLException {
|
||||
return getString(Integer.parseInt(columnLabel));
|
||||
return getString(findColumn(columnLabel));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getBoolean(String columnLabel) throws SQLException {
|
||||
return getBoolean(Integer.parseInt(columnLabel));
|
||||
return getBoolean(findColumn(columnLabel));
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getByte(String columnLabel) throws SQLException {
|
||||
return getByte(Integer.parseInt(columnLabel));
|
||||
return getByte(findColumn(columnLabel));
|
||||
}
|
||||
|
||||
@Override
|
||||
public short getShort(String columnLabel) throws SQLException {
|
||||
return getShort(Integer.parseInt(columnLabel));
|
||||
return getShort(findColumn(columnLabel));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInt(String columnLabel) throws SQLException {
|
||||
return getInt(Integer.parseInt(columnLabel));
|
||||
return getInt(findColumn(columnLabel));
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLong(String columnLabel) throws SQLException {
|
||||
return getLong(Integer.parseInt(columnLabel));
|
||||
return getLong(findColumn(columnLabel));
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getFloat(String columnLabel) throws SQLException {
|
||||
return getFloat(Integer.parseInt(columnLabel));
|
||||
return getFloat(findColumn(columnLabel));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDouble(String columnLabel) throws SQLException {
|
||||
return getDouble(Integer.parseInt(columnLabel));
|
||||
return getDouble(findColumn(columnLabel));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getBigDecimal(String columnLabel, int scale) throws SQLException {
|
||||
return getBigDecimal(Integer.parseInt(columnLabel), scale);
|
||||
return getBigDecimal(findColumn(columnLabel), scale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getBytes(String columnLabel) throws SQLException {
|
||||
return getBytes(Integer.parseInt(columnLabel));
|
||||
return getBytes(findColumn(columnLabel));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getDate(String columnLabel) throws SQLException {
|
||||
return getDate(Integer.parseInt(columnLabel));
|
||||
return getDate(findColumn(columnLabel));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Time getTime(String columnLabel) throws SQLException {
|
||||
return getTime(Integer.parseInt(columnLabel));
|
||||
return getTime(findColumn(columnLabel));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Timestamp getTimestamp(String columnLabel) throws SQLException {
|
||||
return getTimestamp(Integer.parseInt(columnLabel));
|
||||
return getTimestamp(findColumn(columnLabel));
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getAsciiStream(String columnLabel) throws SQLException {
|
||||
return getAsciiStream(Integer.parseInt(columnLabel));
|
||||
return getAsciiStream(findColumn(columnLabel));
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getUnicodeStream(String columnLabel) throws SQLException {
|
||||
return getUnicodeStream(Integer.parseInt(columnLabel));
|
||||
return getUnicodeStream(findColumn(columnLabel));
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getBinaryStream(String columnLabel) throws SQLException {
|
||||
return getBinaryStream(Integer.parseInt(columnLabel));
|
||||
return getBinaryStream(findColumn(columnLabel));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -31,6 +31,17 @@ public class ResultSetMetaDataBase implements ResultSetMetaData {
|
||||
public List<ColumnMetaData> getColumns() {
|
||||
return columns;
|
||||
}
|
||||
|
||||
public int findColumn(String columnName) throws SQLException {
|
||||
for (int i = 0; i < columns.size(); ++i) {
|
||||
ColumnMetaData column = columns.get(i);
|
||||
if (column.getColumnName().equals(columnName)) {
|
||||
return i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
throw new SQLException("column '" + columnName + "' not found.");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.alibaba.druid.common.jdbc.PreparedStatementBase;
|
||||
import com.alibaba.druid.common.jdbc.ResultSetMetaDataBase.ColumnMetaData;
|
||||
import com.alibaba.druid.hbase.exec.ExecutePlan;
|
||||
import com.alibaba.druid.hbase.exec.InsertExecutePlan;
|
||||
import com.alibaba.druid.hbase.exec.ShowTablesPlan;
|
||||
import com.alibaba.druid.hbase.exec.SingleTableQueryExecutePlan;
|
||||
import com.alibaba.druid.hbase.hbql.ast.HBQLShowStatement;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
@@ -115,7 +116,8 @@ public class HPreparedStatement extends PreparedStatementBase implements Prepare
|
||||
|
||||
this.executePlan = insertExecutePlan;
|
||||
} else if (sqlStmt instanceof HBQLShowStatement) {
|
||||
|
||||
ShowTablesPlan showTablePlan = new ShowTablesPlan();
|
||||
this.executePlan = showTablePlan;
|
||||
} else {
|
||||
throw new SQLException("TODO");
|
||||
}
|
||||
|
||||
@@ -2,14 +2,17 @@ package com.alibaba.druid.hbase.exec;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.sql.Types;
|
||||
|
||||
import org.apache.hadoop.hbase.HColumnDescriptor;
|
||||
import org.apache.hadoop.hbase.HTableDescriptor;
|
||||
import org.apache.hadoop.hbase.client.HBaseAdmin;
|
||||
|
||||
import com.alibaba.druid.common.jdbc.ResultSetBase;
|
||||
import com.alibaba.druid.common.jdbc.ResultSetMetaDataBase.ColumnMetaData;
|
||||
import com.alibaba.druid.hbase.HPreparedStatement;
|
||||
import com.alibaba.druid.hbase.HResultSet;
|
||||
import com.alibaba.druid.hbase.HResultSetMetaData;
|
||||
|
||||
public class ShowTablesPlan implements ExecutePlan {
|
||||
|
||||
@@ -43,6 +46,51 @@ public class ShowTablesPlan implements ExecutePlan {
|
||||
public ShowTableResultSet(Statement statement, HTableDescriptor[] tables){
|
||||
super(statement);
|
||||
this.tables = tables;
|
||||
|
||||
HResultSetMetaData metaData = new HResultSetMetaData();
|
||||
{
|
||||
ColumnMetaData column = new ColumnMetaData();
|
||||
column.setColumnName("name");
|
||||
column.setColumnType(Types.VARCHAR);
|
||||
column.setColumnTypeName("VARCHAR");
|
||||
metaData.getColumns().add(column);
|
||||
}
|
||||
{
|
||||
ColumnMetaData column = new ColumnMetaData();
|
||||
column.setColumnName("owner");
|
||||
column.setColumnType(Types.VARCHAR);
|
||||
column.setColumnTypeName("VARCHAR");
|
||||
metaData.getColumns().add(column);
|
||||
}
|
||||
{
|
||||
ColumnMetaData column = new ColumnMetaData();
|
||||
column.setColumnName("familys");
|
||||
column.setColumnType(Types.VARCHAR);
|
||||
column.setColumnTypeName("VARCHAR");
|
||||
metaData.getColumns().add(column);
|
||||
}
|
||||
{
|
||||
ColumnMetaData column = new ColumnMetaData();
|
||||
column.setColumnName("maxFileSize");
|
||||
column.setColumnType(Types.BIGINT);
|
||||
column.setColumnTypeName("long");
|
||||
metaData.getColumns().add(column);
|
||||
}
|
||||
{
|
||||
ColumnMetaData column = new ColumnMetaData();
|
||||
column.setColumnName("memStoreFlushSize");
|
||||
column.setColumnType(Types.BIGINT);
|
||||
column.setColumnTypeName("long");
|
||||
metaData.getColumns().add(column);
|
||||
}
|
||||
{
|
||||
ColumnMetaData column = new ColumnMetaData();
|
||||
column.setColumnName("regionSplitPolicyClassName");
|
||||
column.setColumnType(Types.VARCHAR);
|
||||
column.setColumnTypeName("VARCHAR");
|
||||
metaData.getColumns().add(column);
|
||||
}
|
||||
this.metaData = metaData;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -71,13 +119,17 @@ public class ShowTablesPlan implements ExecutePlan {
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getString(String columnName) {
|
||||
return (String) getObject(columnName);
|
||||
}
|
||||
|
||||
public Object getObject(String columnName) {
|
||||
HTableDescriptor table = tables[rowIndex];
|
||||
|
||||
|
||||
if ("name".equals(columnName)) {
|
||||
return table.getNameAsString();
|
||||
}
|
||||
|
||||
|
||||
if ("owner".equals(columnName)) {
|
||||
return table.getOwnerString();
|
||||
}
|
||||
@@ -92,10 +144,28 @@ public class ShowTablesPlan implements ExecutePlan {
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
if ("maxFileSize".equals(columnName)) {
|
||||
return table.getMaxFileSize();
|
||||
}
|
||||
|
||||
if ("memStoreFlushSize".equals(columnName)) {
|
||||
return table.getMemStoreFlushSize();
|
||||
}
|
||||
|
||||
if ("regionSplitPolicyClassName".equals(columnName)) {
|
||||
return table.getRegionSplitPolicyClassName();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int findColumn(String columnName) throws SQLException {
|
||||
HResultSetMetaData meta = (HResultSetMetaData) this.metaData;
|
||||
return meta.findColumn(columnName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateObject(int columnIndex, Object x) throws SQLException {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user