mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
remove hdriver
This commit is contained in:
@@ -1,14 +0,0 @@
|
||||
package com.alibaba.druid.hdriver;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import com.alibaba.druid.hdriver.impl.mapping.HMapping;
|
||||
|
||||
public interface HConnection extends Connection {
|
||||
HPreparedStatement prepareStatement(String sql) throws SQLException;
|
||||
|
||||
HPreparedStatement prepareStatement(String sql, HMapping mapping) throws SQLException;
|
||||
|
||||
HStatement createStatement() throws SQLException;;
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
package com.alibaba.druid.hdriver;
|
||||
|
||||
import java.sql.Driver;
|
||||
import java.sql.DriverPropertyInfo;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.SQLFeatureNotSupportedException;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.alibaba.druid.hdriver.impl.HBaseConnectionImpl;
|
||||
import com.alibaba.druid.hdriver.impl.HEngine;
|
||||
|
||||
public class HDriver implements Driver {
|
||||
|
||||
public static String PREFIX = "jdbc:druid-hbase:";
|
||||
|
||||
@Override
|
||||
public HConnection connect(String url, Properties info) throws SQLException {
|
||||
if (!acceptsURL(url)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String rest = url.substring(PREFIX.length());
|
||||
|
||||
HEngine engine = HEngine.getHEngine(url, info);
|
||||
|
||||
info.put("hbase.zookeeper.quorum", rest);
|
||||
|
||||
return new HBaseConnectionImpl(engine, info);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsURL(String url) throws SQLException {
|
||||
if (url == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return url.startsWith(PREFIX);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMajorVersion() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinorVersion() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean jdbcCompliant() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
|
||||
throw new SQLFeatureNotSupportedException();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package com.alibaba.druid.hdriver;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
|
||||
|
||||
public interface HPreparedStatement extends PreparedStatement, HStatement {
|
||||
public HResultSet executeQuery() throws SQLException;
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package com.alibaba.druid.hdriver;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
|
||||
public interface HResultSet extends ResultSet {
|
||||
HStatement getStatement() throws SQLException;
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package com.alibaba.druid.hdriver;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
public interface HStatement extends Statement {
|
||||
HConnection getConnection() throws SQLException;
|
||||
|
||||
HResultSet getResultSet() throws SQLException;
|
||||
}
|
||||
@@ -1,280 +0,0 @@
|
||||
package com.alibaba.druid.hdriver.impl;
|
||||
|
||||
import java.sql.Array;
|
||||
import java.sql.Blob;
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.Clob;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
import java.sql.NClob;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLClientInfoException;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.SQLFeatureNotSupportedException;
|
||||
import java.sql.SQLXML;
|
||||
import java.sql.Savepoint;
|
||||
import java.sql.Struct;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.hbase.client.HTableInterface;
|
||||
|
||||
import com.alibaba.druid.hdriver.HConnection;
|
||||
import com.alibaba.druid.hdriver.HStatement;
|
||||
import com.alibaba.druid.hdriver.impl.mapping.HMapping;
|
||||
import com.alibaba.druid.util.jdbc.ConnectionBase;
|
||||
|
||||
public class HBaseConnectionImpl extends ConnectionBase implements HConnection {
|
||||
|
||||
|
||||
private final HEngine engine;
|
||||
|
||||
public HBaseConnectionImpl(HEngine engine, Properties info){
|
||||
super(engine.getUrl(), info);
|
||||
this.engine = engine;
|
||||
|
||||
this.setClientInfo(info);
|
||||
}
|
||||
|
||||
public HEngine getEngine() {
|
||||
return engine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws SQLException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void commit() throws SQLException {
|
||||
throw new SQLFeatureNotSupportedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Array createArrayOf(String typeName, Object[] elements) throws SQLException {
|
||||
throw new SQLFeatureNotSupportedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Blob createBlob() throws SQLException {
|
||||
throw new SQLFeatureNotSupportedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Clob createClob() throws SQLException {
|
||||
throw new SQLFeatureNotSupportedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NClob createNClob() throws SQLException {
|
||||
throw new SQLFeatureNotSupportedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLXML createSQLXML() throws SQLException {
|
||||
throw new SQLFeatureNotSupportedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public HStatement createStatement() throws SQLException {
|
||||
throw new SQLFeatureNotSupportedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public HStatement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
|
||||
throw new SQLFeatureNotSupportedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public HStatement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)
|
||||
throws SQLException {
|
||||
throw new SQLFeatureNotSupportedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Struct createStruct(String typeName, Object[] attributes) throws SQLException {
|
||||
throw new SQLFeatureNotSupportedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Properties getClientInfo() throws SQLException {
|
||||
throw new SQLFeatureNotSupportedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClientInfo(String name) throws SQLException {
|
||||
return engine.getConfig().get(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DatabaseMetaData getMetaData() throws SQLException {
|
||||
throw new SQLFeatureNotSupportedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClosed() throws SQLException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(int timeout) throws SQLException {
|
||||
throw new SQLFeatureNotSupportedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWrapperFor(Class<?> iface) throws SQLException {
|
||||
if (iface == Configuration.class) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (iface == Connection.class || iface == HBaseConnectionImpl.class) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String nativeSQL(String sql) throws SQLException {
|
||||
throw new SQLFeatureNotSupportedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CallableStatement prepareCall(String sql) throws SQLException {
|
||||
throw new SQLFeatureNotSupportedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
|
||||
throw new SQLFeatureNotSupportedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency,
|
||||
int resultSetHoldability) throws SQLException {
|
||||
throw new SQLFeatureNotSupportedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public HPreparedStatementImpl prepareStatement(String sql) throws SQLException {
|
||||
return prepareStatement(sql, (HMapping) null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HPreparedStatementImpl prepareStatement(String sql, HMapping mapping) throws SQLException {
|
||||
return new HPreparedStatementImpl(this, sql, mapping);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException {
|
||||
return prepareStatement(sql);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency)
|
||||
throws SQLException {
|
||||
return prepareStatement(sql);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency,
|
||||
int resultSetHoldability) throws SQLException {
|
||||
return prepareStatement(sql);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException {
|
||||
return prepareStatement(sql);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException {
|
||||
HPreparedStatementImpl stmt = prepareStatement(sql);
|
||||
stmt.setColumnNames(columnNames);
|
||||
return stmt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void releaseSavepoint(Savepoint savepoint) throws SQLException {
|
||||
throw new SQLFeatureNotSupportedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rollback() throws SQLException {
|
||||
throw new SQLFeatureNotSupportedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rollback(Savepoint savepoint) throws SQLException {
|
||||
throw new SQLFeatureNotSupportedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setClientInfo(Properties properties) {
|
||||
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
|
||||
if (entry.getKey() != null && entry.getValue() != null) {
|
||||
engine.getConfig().set(entry.getKey().toString(), entry.getValue().toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setClientInfo(String name, String value) throws SQLClientInfoException {
|
||||
this.engine.getConfig().set(name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Savepoint setSavepoint() throws SQLException {
|
||||
throw new SQLFeatureNotSupportedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Savepoint setSavepoint(String name) throws SQLException {
|
||||
throw new SQLFeatureNotSupportedException();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> T unwrap(Class<T> iface) throws SQLException {
|
||||
if (iface == Configuration.class) {
|
||||
return (T) engine.getConfig();
|
||||
}
|
||||
|
||||
if (iface == HEngine.class) {
|
||||
return (T) engine;
|
||||
}
|
||||
|
||||
if (iface == Connection.class || iface == HBaseConnectionImpl.class) {
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public HTableInterface getHTable(String tableName) {
|
||||
return engine.getHTable(tableName);
|
||||
}
|
||||
|
||||
public void setSchema(String schema) throws SQLException {
|
||||
throw new SQLFeatureNotSupportedException();
|
||||
}
|
||||
|
||||
public String getSchema() throws SQLException {
|
||||
throw new SQLFeatureNotSupportedException();
|
||||
}
|
||||
|
||||
public void abort(Executor executor) throws SQLException {
|
||||
throw new SQLFeatureNotSupportedException();
|
||||
}
|
||||
|
||||
public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException {
|
||||
throw new SQLFeatureNotSupportedException();
|
||||
}
|
||||
|
||||
public int getNetworkTimeout() throws SQLException {
|
||||
throw new SQLFeatureNotSupportedException();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
package com.alibaba.druid.hdriver.impl;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.hbase.client.HBaseAdmin;
|
||||
import org.apache.hadoop.hbase.client.HTableInterface;
|
||||
import org.apache.hadoop.hbase.client.HTablePool;
|
||||
|
||||
import com.alibaba.druid.hdriver.impl.mapping.HMappingTable;
|
||||
import com.alibaba.druid.support.logging.Log;
|
||||
import com.alibaba.druid.support.logging.LogFactory;
|
||||
|
||||
public class HEngine {
|
||||
|
||||
private final static Log LOG = LogFactory.getLog(HEngine.class);
|
||||
|
||||
private static ConcurrentMap<String, HEngine> engines = new ConcurrentHashMap<String, HEngine>();
|
||||
|
||||
public static HEngine getHEngine(String url, Properties connectProperties) {
|
||||
HEngine engine = engines.get(url);
|
||||
if (engine == null) {
|
||||
engine = new HEngine(url, connectProperties);
|
||||
engines.putIfAbsent(url, engine);
|
||||
engine = engines.get(url);
|
||||
}
|
||||
return engine;
|
||||
}
|
||||
|
||||
// =============================
|
||||
|
||||
private final String url;
|
||||
|
||||
private HTablePool tablePool;
|
||||
private int htablePoolMaxSize = 256;
|
||||
private Configuration config;
|
||||
private ConcurrentMap<String, HMappingTable> mappings = new ConcurrentHashMap<String, HMappingTable>();
|
||||
|
||||
public HEngine(String url, Properties connectProperties){
|
||||
super();
|
||||
this.url = url;
|
||||
|
||||
config = new Configuration(false);
|
||||
|
||||
if (connectProperties != null) {
|
||||
String propValue = connectProperties.getProperty("htable.pool.size");
|
||||
if (propValue != null) {
|
||||
try {
|
||||
htablePoolMaxSize = Integer.parseInt(propValue);
|
||||
} catch (NumberFormatException ex) {
|
||||
LOG.error("parse property 'htable.pool.size' error", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public HTablePool getTablePool() {
|
||||
return tablePool;
|
||||
}
|
||||
|
||||
public Configuration getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public ConcurrentMap<String, HMappingTable> getMappings() {
|
||||
return mappings;
|
||||
}
|
||||
|
||||
public synchronized HTableInterface getHTable(String tableName) {
|
||||
if (tablePool == null) {
|
||||
tablePool = new HTablePool(config, htablePoolMaxSize);
|
||||
}
|
||||
return tablePool.getTable(tableName);
|
||||
}
|
||||
|
||||
public HBaseAdmin getHBaseAdmin() throws IOException {
|
||||
return new HBaseAdmin(this.config);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,177 +0,0 @@
|
||||
package com.alibaba.druid.hdriver.impl;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.hdriver.HPreparedStatement;
|
||||
import com.alibaba.druid.hdriver.HResultSet;
|
||||
import com.alibaba.druid.hdriver.impl.execute.ExecutePlan;
|
||||
import com.alibaba.druid.hdriver.impl.execute.InsertExecutePlan;
|
||||
import com.alibaba.druid.hdriver.impl.execute.ShowTablesPlan;
|
||||
import com.alibaba.druid.hdriver.impl.execute.SingleTableQueryExecutePlan;
|
||||
import com.alibaba.druid.hdriver.impl.hbql.ast.HBQLShowStatement;
|
||||
import com.alibaba.druid.hdriver.impl.mapping.HMapping;
|
||||
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;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectItem;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectStatement;
|
||||
import com.alibaba.druid.sql.visitor.SQLEvalVisitor;
|
||||
import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
|
||||
import com.alibaba.druid.util.jdbc.PreparedStatementBase;
|
||||
import com.alibaba.druid.util.jdbc.ResultSetMetaDataBase.ColumnMetaData;
|
||||
|
||||
public class HPreparedStatementImpl extends PreparedStatementBase implements HPreparedStatement {
|
||||
|
||||
private final String sql;
|
||||
private String[] columnNames;
|
||||
|
||||
private HBaseConnectionImpl hbaseConnection;
|
||||
|
||||
private ExecutePlan executePlan;
|
||||
|
||||
private String dbType = "hbase";
|
||||
|
||||
private HMapping mapping;
|
||||
|
||||
public HPreparedStatementImpl(HBaseConnectionImpl conn, String sql, HMapping mapping) throws SQLException{
|
||||
super(conn);
|
||||
this.sql = sql;
|
||||
this.hbaseConnection = conn;
|
||||
this.mapping = mapping;
|
||||
|
||||
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 HMapping getMapping() {
|
||||
return mapping;
|
||||
}
|
||||
|
||||
public void init() throws SQLException {
|
||||
List<SQLStatement> stmtList = SQLUtils.parseStatements(sql, dbType);
|
||||
|
||||
if (stmtList.size() != 1) {
|
||||
throw new SQLException("not support multi-statement");
|
||||
}
|
||||
|
||||
SQLStatement sqlStmt = stmtList.get(0);
|
||||
if (sqlStmt instanceof SQLSelectStatement) {
|
||||
SQLSelectStatement selectStmt = (SQLSelectStatement) sqlStmt;
|
||||
|
||||
SQLEvalVisitor evalVisitor = SQLEvalVisitorUtils.createEvalVisitor(dbType);
|
||||
selectStmt.accept(evalVisitor);
|
||||
|
||||
SQLSelectQueryBlock selectQueryBlock = (SQLSelectQueryBlock) selectStmt.getSelect().getQuery();
|
||||
|
||||
SQLExprTableSource tableSource = (SQLExprTableSource) selectQueryBlock.getFrom();
|
||||
String tableName = ((SQLIdentifierExpr) tableSource.getExpr()).getName();
|
||||
|
||||
SingleTableQueryExecutePlan singleTableQueryExecuetePlan = new SingleTableQueryExecutePlan();
|
||||
singleTableQueryExecuetePlan.setMapping(mapping);
|
||||
singleTableQueryExecuetePlan.setTableName(tableName);
|
||||
|
||||
splitCondition(singleTableQueryExecuetePlan.getConditions(), selectQueryBlock.getWhere());
|
||||
|
||||
HResultSetMetaDataImpl resultMetaData = new HResultSetMetaDataImpl();
|
||||
for (SQLSelectItem selectItem : selectQueryBlock.getSelectList()) {
|
||||
ColumnMetaData columnMetaData = new ColumnMetaData();
|
||||
if (selectItem.getAlias() != null) {
|
||||
columnMetaData.setColumnLabel(selectItem.getAlias());
|
||||
}
|
||||
columnMetaData.setColumnName(SQLUtils.toSQLString(selectItem.getExpr(), dbType));
|
||||
columnMetaData.setColumnType(Types.BINARY);
|
||||
resultMetaData.getColumns().add(columnMetaData);
|
||||
}
|
||||
singleTableQueryExecuetePlan.setResultMetaData(resultMetaData);
|
||||
|
||||
this.executePlan = singleTableQueryExecuetePlan;
|
||||
} else if (sqlStmt instanceof SQLInsertStatement) {
|
||||
SQLInsertStatement insertStmt = (SQLInsertStatement) sqlStmt;
|
||||
|
||||
SQLEvalVisitor evalVisitor = SQLEvalVisitorUtils.createEvalVisitor(dbType);
|
||||
insertStmt.accept(evalVisitor);
|
||||
|
||||
String tableName = ((SQLIdentifierExpr) insertStmt.getTableSource().getExpr()).getName();
|
||||
|
||||
InsertExecutePlan insertExecutePlan = new InsertExecutePlan();
|
||||
insertExecutePlan.setTableName(tableName);
|
||||
|
||||
for (int i = 0; i < insertStmt.getColumns().size(); ++i) {
|
||||
SQLExpr columnExpr = insertStmt.getColumns().get(i);
|
||||
SQLExpr valueExpr = insertStmt.getValues().getValues().get(i);
|
||||
|
||||
String columnName = ((SQLIdentifierExpr) columnExpr).getName();
|
||||
insertExecutePlan.getColumns().put(columnName, valueExpr);
|
||||
}
|
||||
|
||||
this.executePlan = insertExecutePlan;
|
||||
} else if (sqlStmt instanceof HBQLShowStatement) {
|
||||
ShowTablesPlan showTablePlan = new ShowTablesPlan();
|
||||
this.executePlan = showTablePlan;
|
||||
} else {
|
||||
throw new SQLException("TODO");
|
||||
}
|
||||
}
|
||||
|
||||
public ExecutePlan getExecutePlan() {
|
||||
return executePlan;
|
||||
}
|
||||
|
||||
public String[] getColumnNames() {
|
||||
return columnNames;
|
||||
}
|
||||
|
||||
public void setColumnNames(String[] columnNames) {
|
||||
this.columnNames = columnNames;
|
||||
}
|
||||
|
||||
public String getSql() {
|
||||
return sql;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HBaseConnectionImpl getConnection() throws SQLException {
|
||||
return hbaseConnection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HResultSet executeQuery() throws SQLException {
|
||||
return this.executePlan.executeQuery(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int executeUpdate() throws SQLException {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute() throws SQLException {
|
||||
this.executePlan.execute(this);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public HResultSet getResultSet() throws SQLException {
|
||||
return (HResultSet) super.getResultSet();
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package com.alibaba.druid.hdriver.impl;
|
||||
|
||||
import com.alibaba.druid.util.jdbc.ResultSetMetaDataBase;
|
||||
|
||||
|
||||
public class HResultSetMetaDataImpl extends ResultSetMetaDataBase {
|
||||
|
||||
}
|
||||
@@ -1,207 +0,0 @@
|
||||
package com.alibaba.druid.hdriver.impl;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
|
||||
import org.apache.hadoop.hbase.client.HTableInterface;
|
||||
import org.apache.hadoop.hbase.client.Result;
|
||||
import org.apache.hadoop.hbase.client.ResultScanner;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
|
||||
import com.alibaba.druid.hdriver.HResultSet;
|
||||
import com.alibaba.druid.hdriver.HStatement;
|
||||
import com.alibaba.druid.hdriver.impl.mapping.HMapping;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
import com.alibaba.druid.util.jdbc.ResultSetBase;
|
||||
import com.alibaba.druid.util.jdbc.ResultSetMetaDataBase.ColumnMetaData;
|
||||
|
||||
public class HScannerResultSetImpl extends ResultSetBase implements HResultSet {
|
||||
|
||||
private HStatement statement;
|
||||
private ResultScanner scanner;
|
||||
private HTableInterface htable;
|
||||
private Result result;
|
||||
private byte[] family = Bytes.toBytes("d");
|
||||
|
||||
private HMapping mapping;
|
||||
|
||||
public HScannerResultSetImpl(HStatement statement, HTableInterface htable, ResultScanner scanner){
|
||||
super(statement);
|
||||
this.statement = statement;
|
||||
this.htable = htable;
|
||||
this.scanner = scanner;
|
||||
}
|
||||
|
||||
public HMapping getMapping() {
|
||||
return mapping;
|
||||
}
|
||||
|
||||
public void setMapping(HMapping mapping) {
|
||||
this.mapping = mapping;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HStatement getStatement() throws SQLException {
|
||||
return statement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean next() throws SQLException {
|
||||
try {
|
||||
result = scanner.next();
|
||||
return result != null && !result.isEmpty();
|
||||
} catch (IOException ex) {
|
||||
throw new SQLException("read next error", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public HResultSetMetaDataImpl getMetaData() throws SQLException {
|
||||
return (HResultSetMetaDataImpl) metaData;
|
||||
}
|
||||
|
||||
public void setMetaData(HResultSetMetaDataImpl metaData) {
|
||||
this.metaData = metaData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean previous() throws SQLException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateObject(int columnIndex, Object x) throws SQLException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getObjectInternal(int columnIndex) throws SQLException {
|
||||
ColumnMetaData column = this.getMetaData().getColumn(columnIndex);
|
||||
return getObjectInternal(column.getColumnName(), column.getColumnType());
|
||||
}
|
||||
|
||||
public Object getObjectInternal(String columnName, int type) throws SQLException {
|
||||
byte[] bytes = getBytes(columnName);
|
||||
switch (type) {
|
||||
case Types.TINYINT:
|
||||
return bytes[0];
|
||||
case Types.SMALLINT:
|
||||
return Bytes.toShort(bytes);
|
||||
case Types.INTEGER:
|
||||
return Bytes.toInt(bytes);
|
||||
case Types.BIGINT:
|
||||
return Bytes.toLong(bytes);
|
||||
case Types.DECIMAL:
|
||||
return Bytes.toBigDecimal(bytes);
|
||||
case Types.BOOLEAN:
|
||||
return Bytes.toBoolean(bytes);
|
||||
case Types.VARCHAR:
|
||||
case Types.CHAR:
|
||||
case Types.NCHAR:
|
||||
case Types.NVARCHAR:
|
||||
return Bytes.toString(bytes);
|
||||
case Types.DATE:
|
||||
return new java.sql.Date(Bytes.toLong(bytes));
|
||||
case Types.TIMESTAMP:
|
||||
return new java.sql.Timestamp(Bytes.toLong(bytes));
|
||||
case Types.NULL:
|
||||
case Types.VARBINARY:
|
||||
case Types.BINARY:
|
||||
case Types.ROWID:
|
||||
default:
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getString(int columnIndex) throws SQLException {
|
||||
byte[] bytes = getBytes(columnIndex);
|
||||
return Bytes.toString(bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getString(String columnName) throws SQLException {
|
||||
byte[] bytes = getBytes(columnName);
|
||||
return Bytes.toString(bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getBytes(int columnIndex) throws SQLException {
|
||||
ColumnMetaData column = this.getMetaData().getColumn(columnIndex);
|
||||
return getBytes(column.getColumnName());
|
||||
}
|
||||
|
||||
public byte[] getBytes(String columnName) throws SQLException {
|
||||
if ("@ROW".equals(columnName)) {
|
||||
return result.getRow();
|
||||
}
|
||||
|
||||
if ("id".equals(columnName)) { // TODO
|
||||
return result.getRow();
|
||||
}
|
||||
|
||||
byte[] qualifier = Bytes.toBytes(columnName);
|
||||
byte[] value = result.getValue(family, qualifier);
|
||||
|
||||
this.wasNull = value == null;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInt(String columnName) throws SQLException {
|
||||
byte[] bytes = getBytes(columnName);
|
||||
|
||||
if (bytes == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return Bytes.toInt(bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInt(int columnIndex) throws SQLException {
|
||||
byte[] bytes = getBytes(columnIndex);
|
||||
|
||||
if (bytes == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return Bytes.toInt(bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getBigDecimal(String columnName) throws SQLException {
|
||||
byte[] bytes = getBytes(columnName);
|
||||
|
||||
if (bytes == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Bytes.toBigDecimal(bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
|
||||
byte[] bytes = getBytes(columnIndex);
|
||||
|
||||
if (bytes == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Bytes.toBigDecimal(bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws SQLException {
|
||||
JdbcUtils.close(scanner);
|
||||
try {
|
||||
htable.close();
|
||||
} catch (Exception ex) {
|
||||
throw new SQLException("close error", ex);
|
||||
}
|
||||
super.close();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package com.alibaba.druid.hdriver.impl;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
import com.alibaba.druid.hdriver.HResultSet;
|
||||
import com.alibaba.druid.hdriver.HStatement;
|
||||
import com.alibaba.druid.util.jdbc.StatementBase;
|
||||
|
||||
public class HStatementImpl extends StatementBase implements Statement, HStatement {
|
||||
|
||||
private HBaseConnectionImpl conn;
|
||||
|
||||
public HStatementImpl(HBaseConnectionImpl conn){
|
||||
super(conn);
|
||||
this.conn = conn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HBaseConnectionImpl getConnection() throws SQLException {
|
||||
return conn;
|
||||
}
|
||||
|
||||
public void checkOpen() {
|
||||
|
||||
}
|
||||
|
||||
public HResultSet getResultSet() throws SQLException {
|
||||
return (HResultSet) super.getResultSet();
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package com.alibaba.druid.hdriver.impl.execute;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import com.alibaba.druid.hdriver.HResultSet;
|
||||
import com.alibaba.druid.hdriver.impl.HPreparedStatementImpl;
|
||||
|
||||
public interface ExecutePlan {
|
||||
|
||||
HResultSet executeQuery(HPreparedStatementImpl statement) throws SQLException;
|
||||
|
||||
boolean execute(HPreparedStatementImpl statement) throws SQLException;
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.alibaba.druid.hdriver.impl.execute;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import com.alibaba.druid.hdriver.HResultSet;
|
||||
import com.alibaba.druid.hdriver.impl.HPreparedStatementImpl;
|
||||
|
||||
public class ExecutePlanAdapter implements ExecutePlan {
|
||||
|
||||
@Override
|
||||
public HResultSet executeQuery(HPreparedStatementImpl statement) throws SQLException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(HPreparedStatementImpl statement) throws SQLException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
package com.alibaba.druid.hdriver.impl.execute;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.hadoop.hbase.client.HTableInterface;
|
||||
import org.apache.hadoop.hbase.client.Put;
|
||||
|
||||
import com.alibaba.druid.hdriver.impl.HBaseConnectionImpl;
|
||||
import com.alibaba.druid.hdriver.impl.HPreparedStatementImpl;
|
||||
import com.alibaba.druid.hdriver.impl.mapping.HMapping;
|
||||
import com.alibaba.druid.hdriver.impl.mapping.HMappingDefaultImpl;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
|
||||
|
||||
public class InsertExecutePlan extends SingleTableExecutePlan {
|
||||
|
||||
private Map<String, SQLExpr> columns = new LinkedHashMap<String, SQLExpr>();
|
||||
|
||||
@Override
|
||||
public boolean execute(HPreparedStatementImpl statement) throws SQLException {
|
||||
try {
|
||||
HMapping mapping = this.getMapping();
|
||||
if (mapping == null) {
|
||||
mapping = new HMappingDefaultImpl();
|
||||
}
|
||||
|
||||
HBaseConnectionImpl connection = statement.getConnection();
|
||||
String dbType = connection.getConnectProperties().getProperty("dbType");
|
||||
|
||||
Put put = null;
|
||||
for (Map.Entry<String, SQLExpr> entry : columns.entrySet()) {
|
||||
String column = entry.getKey();
|
||||
SQLExpr valueExpr = entry.getValue();
|
||||
|
||||
Object value = SQLEvalVisitorUtils.eval(dbType, valueExpr, statement.getParameters());
|
||||
|
||||
if (value == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
byte[] bytes = mapping.toBytes(column, value);
|
||||
|
||||
if (mapping.isRow(column)) {
|
||||
put = new Put(bytes);
|
||||
} else {
|
||||
byte[] family = mapping.getFamily(column);
|
||||
byte[] qualifier = mapping.getQualifier(column);
|
||||
put.add(family, qualifier, bytes);
|
||||
}
|
||||
}
|
||||
|
||||
HTableInterface htable = connection.getHTable(getTableName());
|
||||
htable.put(put);
|
||||
|
||||
return false;
|
||||
} catch (SQLException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw new SQLException("executeQuery error", e);
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, SQLExpr> getColumns() {
|
||||
return columns;
|
||||
}
|
||||
|
||||
public void setColumns(Map<String, SQLExpr> columns) {
|
||||
this.columns = columns;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,179 +0,0 @@
|
||||
package com.alibaba.druid.hdriver.impl.execute;
|
||||
|
||||
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.hdriver.HResultSet;
|
||||
import com.alibaba.druid.hdriver.HStatement;
|
||||
import com.alibaba.druid.hdriver.impl.HPreparedStatementImpl;
|
||||
import com.alibaba.druid.hdriver.impl.HResultSetMetaDataImpl;
|
||||
import com.alibaba.druid.util.jdbc.ResultSetBase;
|
||||
import com.alibaba.druid.util.jdbc.ResultSetMetaDataBase.ColumnMetaData;
|
||||
|
||||
public class ShowTablesPlan implements ExecutePlan {
|
||||
|
||||
@Override
|
||||
public HResultSet executeQuery(HPreparedStatementImpl statement) throws SQLException {
|
||||
try {
|
||||
HBaseAdmin admin = statement.getConnection().getEngine().getHBaseAdmin();
|
||||
|
||||
HTableDescriptor[] tables = admin.listTables();
|
||||
|
||||
return new ShowTableResultSet(statement, tables);
|
||||
} catch (SQLException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw new SQLException("executeQuery error", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(HPreparedStatementImpl statement) throws SQLException {
|
||||
HResultSet resultSet = executeQuery(statement);
|
||||
statement.setResultSet(resultSet);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static class ShowTableResultSet extends ResultSetBase implements HResultSet {
|
||||
|
||||
private final HTableDescriptor[] tables;
|
||||
private int rowIndex = -1;
|
||||
|
||||
public ShowTableResultSet(Statement statement, HTableDescriptor[] tables){
|
||||
super(statement);
|
||||
this.tables = tables;
|
||||
|
||||
HResultSetMetaDataImpl metaData = new HResultSetMetaDataImpl();
|
||||
{
|
||||
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
|
||||
public synchronized boolean next() throws SQLException {
|
||||
if (closed) {
|
||||
throw new SQLException();
|
||||
}
|
||||
|
||||
if (rowIndex < tables.length - 1) {
|
||||
rowIndex++;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean previous() throws SQLException {
|
||||
if (closed) {
|
||||
throw new SQLException();
|
||||
}
|
||||
|
||||
if (rowIndex > 0) {
|
||||
rowIndex--;
|
||||
return true;
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
if ("familys".equals(columnName)) {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
for (HColumnDescriptor column : table.getFamilies()) {
|
||||
if (buf.length() != 0) {
|
||||
buf.append(',');
|
||||
}
|
||||
buf.append(column.getNameAsString());
|
||||
}
|
||||
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 {
|
||||
HResultSetMetaDataImpl meta = (HResultSetMetaDataImpl) this.metaData;
|
||||
return meta.findColumn(columnName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateObject(int columnIndex, Object x) throws SQLException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public HStatement getStatement() throws SQLException {
|
||||
return (HStatement) statement;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package com.alibaba.druid.hdriver.impl.execute;
|
||||
|
||||
import com.alibaba.druid.hdriver.impl.mapping.HMapping;
|
||||
import com.alibaba.druid.hdriver.impl.mapping.HMappingDefaultImpl;
|
||||
|
||||
public class SingleTableExecutePlan extends ExecutePlanAdapter {
|
||||
|
||||
private String tableName;
|
||||
|
||||
private HMapping mapping;
|
||||
|
||||
public String getTableName() {
|
||||
return tableName;
|
||||
}
|
||||
|
||||
public void setTableName(String tableName) {
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
public HMapping getMapping() {
|
||||
HMapping mapping = this.mapping;
|
||||
if (mapping == null) {
|
||||
mapping = new HMappingDefaultImpl();
|
||||
}
|
||||
return mapping;
|
||||
}
|
||||
|
||||
public void setMapping(HMapping mapping) {
|
||||
this.mapping = mapping;
|
||||
}
|
||||
|
||||
}
|
||||
-196
@@ -1,196 +0,0 @@
|
||||
package com.alibaba.druid.hdriver.impl.execute;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
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 org.apache.hadoop.hbase.filter.SingleColumnValueFilter;
|
||||
|
||||
import com.alibaba.druid.hdriver.impl.HBaseConnectionImpl;
|
||||
import com.alibaba.druid.hdriver.impl.HPreparedStatementImpl;
|
||||
import com.alibaba.druid.hdriver.impl.HResultSetMetaDataImpl;
|
||||
import com.alibaba.druid.hdriver.impl.HScannerResultSetImpl;
|
||||
import com.alibaba.druid.hdriver.impl.mapping.HMapping;
|
||||
import com.alibaba.druid.hdriver.impl.mapping.HMappingDefaultImpl;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
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.visitor.SQLEvalVisitorUtils;
|
||||
|
||||
public class SingleTableQueryExecutePlan extends SingleTableExecutePlan {
|
||||
|
||||
private List<String> columeNames = new ArrayList<String>();
|
||||
private List<SQLExpr> conditions = new ArrayList<SQLExpr>();
|
||||
|
||||
private HResultSetMetaDataImpl resultMetaData;
|
||||
|
||||
private String dbType = "hbase";
|
||||
|
||||
private Scan scan;
|
||||
private HPreparedStatementImpl statement;
|
||||
|
||||
public SingleTableQueryExecutePlan(){
|
||||
|
||||
}
|
||||
|
||||
public List<SQLExpr> getConditions() {
|
||||
return conditions;
|
||||
}
|
||||
|
||||
public void setConditions(List<SQLExpr> conditions) {
|
||||
this.conditions = conditions;
|
||||
}
|
||||
|
||||
public List<String> getColumeNames() {
|
||||
return columeNames;
|
||||
}
|
||||
|
||||
public HResultSetMetaDataImpl getResultMetaData() {
|
||||
return resultMetaData;
|
||||
}
|
||||
|
||||
public void setResultMetaData(HResultSetMetaDataImpl resultMetaData) {
|
||||
this.resultMetaData = resultMetaData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HScannerResultSetImpl executeQuery(HPreparedStatementImpl statement) throws SQLException {
|
||||
try {
|
||||
HMapping mapping = this.getMapping();
|
||||
if (mapping == null) {
|
||||
mapping = new HMappingDefaultImpl();
|
||||
}
|
||||
|
||||
HBaseConnectionImpl connection = statement.getConnection();
|
||||
|
||||
scan = new Scan();
|
||||
this.statement = statement;
|
||||
|
||||
Filter filter = null;
|
||||
for (SQLExpr item : conditions) {
|
||||
SQLBinaryOpExpr condition = (SQLBinaryOpExpr) item;
|
||||
filter = setFilter(condition, filter, true);
|
||||
}
|
||||
if (filter != null) {
|
||||
scan.setFilter(filter);
|
||||
}
|
||||
|
||||
HTableInterface htable = connection.getHTable(getTableName());
|
||||
ResultScanner scanner = htable.getScanner(scan);
|
||||
|
||||
HScannerResultSetImpl resultSet = new HScannerResultSetImpl(statement, htable, scanner);
|
||||
resultSet.setMetaData(resultMetaData);
|
||||
|
||||
return resultSet;
|
||||
} catch (SQLException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw new SQLException("executeQuery error", e);
|
||||
} finally {
|
||||
scan = null;
|
||||
this.statement = null;
|
||||
}
|
||||
}
|
||||
|
||||
private Filter setFilter(SQLBinaryOpExpr condition, Filter filter, boolean and) throws IOException, SQLException {
|
||||
HMapping mapping = this.getMapping();
|
||||
|
||||
if (condition.getOperator() == SQLBinaryOperator.BooleanAnd) {
|
||||
filter = setFilter((SQLBinaryOpExpr) condition.getLeft(), filter, true);
|
||||
filter = setFilter((SQLBinaryOpExpr) condition.getRight(), filter, true);
|
||||
return filter;
|
||||
} else if (condition.getOperator() == SQLBinaryOperator.BooleanOr) {
|
||||
filter = setFilter((SQLBinaryOpExpr) condition.getLeft(), filter, false);
|
||||
filter = setFilter((SQLBinaryOpExpr) condition.getRight(), filter, false);
|
||||
return filter;
|
||||
}
|
||||
|
||||
String fieldName = ((SQLIdentifierExpr) condition.getLeft()).getName();
|
||||
Object value = SQLEvalVisitorUtils.eval(dbType, condition.getRight(), statement.getParameters());
|
||||
|
||||
byte[] bytes = mapping.toBytes(fieldName, value);
|
||||
if (mapping.isRow(fieldName)) {
|
||||
if (filter == null && condition.getOperator() == SQLBinaryOperator.GreaterThanOrEqual) {
|
||||
scan.setStartRow(bytes);
|
||||
return null;
|
||||
} else if (filter == null && condition.getOperator() == SQLBinaryOperator.LessThan) {
|
||||
scan.setStopRow(bytes);
|
||||
return null;
|
||||
} else {
|
||||
CompareOp compareOp = toCompareOp(condition.getOperator());
|
||||
RowFilter rowFilter = new RowFilter(compareOp, new BinaryComparator(bytes));
|
||||
|
||||
return setFilter(filter, rowFilter, and);
|
||||
}
|
||||
} else {
|
||||
byte[] qualifier = mapping.getQualifier(fieldName);
|
||||
byte[] family = mapping.getFamily(fieldName);
|
||||
|
||||
CompareOp compareOp = toCompareOp(condition.getOperator());
|
||||
|
||||
SingleColumnValueFilter columnFilter = new SingleColumnValueFilter(family, qualifier, compareOp, bytes);
|
||||
return setFilter(filter, columnFilter, and);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
CompareOp toCompareOp(SQLBinaryOperator operator) {
|
||||
switch (operator) {
|
||||
case Equality:
|
||||
return CompareOp.EQUAL;
|
||||
case NotEqual:
|
||||
return CompareOp.NOT_EQUAL;
|
||||
case GreaterThan:
|
||||
return CompareOp.GREATER;
|
||||
case GreaterThanOrEqual:
|
||||
return CompareOp.GREATER_OR_EQUAL;
|
||||
case LessThan:
|
||||
return CompareOp.LESS;
|
||||
case LessThanOrEqual:
|
||||
return CompareOp.LESS_OR_EQUAL;
|
||||
default:
|
||||
throw new UnsupportedOperationException("TODO");
|
||||
}
|
||||
}
|
||||
|
||||
Filter setFilter(Filter parentFilter, Filter filter, boolean and) {
|
||||
if (parentFilter == null) {
|
||||
return filter;
|
||||
} else if (parentFilter instanceof FilterList) {
|
||||
FilterList filterList = (FilterList) parentFilter;
|
||||
if (and) {
|
||||
if (filterList.getOperator() == FilterList.Operator.MUST_PASS_ALL) {
|
||||
filterList.addFilter(filter);
|
||||
return filterList;
|
||||
} else {
|
||||
return new FilterList(FilterList.Operator.MUST_PASS_ALL, parentFilter, filter);
|
||||
}
|
||||
} else {
|
||||
if (filterList.getOperator() == FilterList.Operator.MUST_PASS_ONE) {
|
||||
filterList.addFilter(filter);
|
||||
return filterList;
|
||||
} else {
|
||||
return new FilterList(FilterList.Operator.MUST_PASS_ONE, parentFilter, filter);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
List<Filter> filters = new ArrayList<Filter>();
|
||||
filters.add(parentFilter);
|
||||
filters.add(filter);
|
||||
|
||||
FilterList.Operator filterOp = and ? FilterList.Operator.MUST_PASS_ALL : FilterList.Operator.MUST_PASS_ONE;
|
||||
return new FilterList(filterOp, filters);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.alibaba.druid.hdriver.impl.hbql.ast;
|
||||
|
||||
import com.alibaba.druid.hdriver.impl.mapping.HMappingTable;
|
||||
import com.alibaba.druid.sql.ast.SQLStatementImpl;
|
||||
|
||||
public class HBQLCreateMappingStatement extends SQLStatementImpl implements HBQLStatement {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private HMappingTable mapping = new HMappingTable();
|
||||
|
||||
public HMappingTable getMapping() {
|
||||
return mapping;
|
||||
}
|
||||
|
||||
public void setMapping(HMappingTable mapping) {
|
||||
this.mapping = mapping;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package com.alibaba.druid.hdriver.impl.hbql.ast;
|
||||
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement;
|
||||
|
||||
public class HBQLCreateTableStatement extends SQLCreateTableStatement {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
}
|
||||
@@ -1,108 +0,0 @@
|
||||
package com.alibaba.druid.hdriver.impl.hbql.ast;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLObjectImpl;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLTableElement;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class HBQLFamilyDefinition extends SQLObjectImpl implements SQLTableElement {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String columnName;
|
||||
|
||||
private Integer blockSize;
|
||||
private Integer minVersions;
|
||||
private Integer maxVersions;
|
||||
private String compressionType;
|
||||
private String compactionCompressionType;
|
||||
private Boolean inMemory;
|
||||
private Integer timeToLive;
|
||||
private Boolean blockCacheEnabled;
|
||||
private String bloomFilterType;
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
|
||||
}
|
||||
|
||||
public String getColumnName() {
|
||||
return columnName;
|
||||
}
|
||||
|
||||
public void setColumnName(String columnName) {
|
||||
this.columnName = columnName;
|
||||
}
|
||||
|
||||
public Integer getBlockSize() {
|
||||
return blockSize;
|
||||
}
|
||||
|
||||
public void setBlockSize(Integer blockSize) {
|
||||
this.blockSize = blockSize;
|
||||
}
|
||||
|
||||
public Integer getMinVersions() {
|
||||
return minVersions;
|
||||
}
|
||||
|
||||
public void setMinVersions(Integer minVersions) {
|
||||
this.minVersions = minVersions;
|
||||
}
|
||||
|
||||
public Integer getMaxVersions() {
|
||||
return maxVersions;
|
||||
}
|
||||
|
||||
public void setMaxVersions(Integer maxVersions) {
|
||||
this.maxVersions = maxVersions;
|
||||
}
|
||||
|
||||
public String getCompressionType() {
|
||||
return compressionType;
|
||||
}
|
||||
|
||||
public void setCompressionType(String compressionType) {
|
||||
this.compressionType = compressionType;
|
||||
}
|
||||
|
||||
public String getCompactionCompressionType() {
|
||||
return compactionCompressionType;
|
||||
}
|
||||
|
||||
public void setCompactionCompressionType(String compactionCompressionType) {
|
||||
this.compactionCompressionType = compactionCompressionType;
|
||||
}
|
||||
|
||||
public Boolean getInMemory() {
|
||||
return inMemory;
|
||||
}
|
||||
|
||||
public void setInMemory(Boolean inMemory) {
|
||||
this.inMemory = inMemory;
|
||||
}
|
||||
|
||||
public Integer getTimeToLive() {
|
||||
return timeToLive;
|
||||
}
|
||||
|
||||
public void setTimeToLive(Integer timeToLive) {
|
||||
this.timeToLive = timeToLive;
|
||||
}
|
||||
|
||||
public Boolean getBlockCacheEnabled() {
|
||||
return blockCacheEnabled;
|
||||
}
|
||||
|
||||
public void setBlockCacheEnabled(Boolean blockCacheEnabled) {
|
||||
this.blockCacheEnabled = blockCacheEnabled;
|
||||
}
|
||||
|
||||
public String getBloomFilterType() {
|
||||
return bloomFilterType;
|
||||
}
|
||||
|
||||
public void setBloomFilterType(String bloomFilterType) {
|
||||
this.bloomFilterType = bloomFilterType;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package com.alibaba.druid.hdriver.impl.hbql.ast;
|
||||
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock;
|
||||
|
||||
public class HBQLSelectQueryBlock extends SQLSelectQueryBlock {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.alibaba.druid.hdriver.impl.hbql.ast;
|
||||
|
||||
import com.alibaba.druid.hdriver.impl.hbql.visitor.HBQLVisitor;
|
||||
|
||||
public class HBQLShowStatement extends HBQLStatementImpl {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public void accept0(HBQLVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package com.alibaba.druid.hdriver.impl.hbql.ast;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
|
||||
|
||||
public interface HBQLStatement extends SQLStatement {
|
||||
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package com.alibaba.druid.hdriver.impl.hbql.ast;
|
||||
|
||||
import com.alibaba.druid.hdriver.impl.hbql.visitor.HBQLVisitor;
|
||||
import com.alibaba.druid.sql.ast.SQLStatementImpl;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class HBQLStatementImpl extends SQLStatementImpl {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor instanceof HBQLVisitor) {
|
||||
accept0((HBQLVisitor) visitor);
|
||||
} else {
|
||||
throw new IllegalArgumentException("not support visitor type : " + visitor.getClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
public void accept0(HBQLVisitor visitor) {
|
||||
throw new UnsupportedOperationException(this.getClass().getName());
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package com.alibaba.druid.hdriver.impl.hbql.parser;
|
||||
|
||||
import com.alibaba.druid.sql.parser.Lexer;
|
||||
import com.alibaba.druid.sql.parser.ParserException;
|
||||
import com.alibaba.druid.sql.parser.SQLExprParser;
|
||||
|
||||
public class HBQLExprParser extends SQLExprParser {
|
||||
|
||||
public HBQLExprParser(String sql) throws ParserException{
|
||||
super(new HBQLLexer(sql));
|
||||
this.lexer.nextToken();
|
||||
}
|
||||
|
||||
public HBQLExprParser(Lexer lexer){
|
||||
super(lexer);
|
||||
}
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
package com.alibaba.druid.hdriver.impl.hbql.parser;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.druid.sql.parser.Keywords;
|
||||
import com.alibaba.druid.sql.parser.Lexer;
|
||||
import com.alibaba.druid.sql.parser.Token;
|
||||
|
||||
public class HBQLLexer extends Lexer {
|
||||
|
||||
public final static Keywords DEFAULT_HBQL_KEYWORDS;
|
||||
|
||||
static {
|
||||
Map<String, Token> map = new HashMap<String, Token>();
|
||||
map.put("EXISTS", Token.EXISTS);
|
||||
map.put("THEN", Token.THEN);
|
||||
map.put("AS", Token.AS);
|
||||
map.put("GROUP", Token.GROUP);
|
||||
map.put("BY", Token.BY);
|
||||
map.put("HAVING", Token.HAVING);
|
||||
map.put("DELETE", Token.DELETE);
|
||||
map.put("ORDER", Token.ORDER);
|
||||
map.put("INDEX", Token.INDEX);
|
||||
map.put("FOR", Token.FOR);
|
||||
map.put("SCHEMA", Token.SCHEMA);
|
||||
map.put("FOREIGN", Token.FOREIGN);
|
||||
map.put("REFERENCES", Token.REFERENCES);
|
||||
map.put("CHECK", Token.CHECK);
|
||||
map.put("PRIMARY", Token.PRIMARY);
|
||||
map.put("KEY", Token.KEY);
|
||||
map.put("CONSTRAINT", Token.CONSTRAINT);
|
||||
map.put("DEFAULT", Token.DEFAULT);
|
||||
map.put("VIEW", Token.VIEW);
|
||||
map.put("CREATE", Token.CREATE);
|
||||
map.put("VALUES", Token.VALUES);
|
||||
map.put("ALTER", Token.ALTER);
|
||||
map.put("TABLE", Token.TABLE);
|
||||
map.put("DROP", Token.DROP);
|
||||
map.put("SET", Token.SET);
|
||||
map.put("INTO", Token.INTO);
|
||||
map.put("UPDATE", Token.UPDATE);
|
||||
map.put("NULL", Token.NULL);
|
||||
map.put("IS", Token.IS);
|
||||
map.put("NOT", Token.NOT);
|
||||
map.put("SELECT", Token.SELECT);
|
||||
map.put("INSERT", Token.INSERT);
|
||||
map.put("FROM", Token.FROM);
|
||||
map.put("WHERE", Token.WHERE);
|
||||
map.put("AND", Token.AND);
|
||||
map.put("OR", Token.OR);
|
||||
map.put("XOR", Token.XOR);
|
||||
map.put("DISTINCT", Token.DISTINCT);
|
||||
map.put("UNIQUE", Token.UNIQUE);
|
||||
map.put("ALL", Token.ALL);
|
||||
map.put("UNION", Token.UNION);
|
||||
map.put("INTERSECT", Token.INTERSECT);
|
||||
map.put("MINUS", Token.MINUS);
|
||||
map.put("INNER", Token.INNER);
|
||||
map.put("LEFT", Token.LEFT);
|
||||
map.put("RIGHT", Token.RIGHT);
|
||||
map.put("FULL", Token.FULL);
|
||||
map.put("ON", Token.ON);
|
||||
map.put("OUTER", Token.OUTER);
|
||||
map.put("JOIN", Token.JOIN);
|
||||
map.put("NEW", Token.NEW);
|
||||
map.put("CASE", Token.CASE);
|
||||
map.put("WHEN", Token.WHEN);
|
||||
map.put("END", Token.END);
|
||||
map.put("WHEN", Token.WHEN);
|
||||
map.put("ELSE", Token.ELSE);
|
||||
map.put("EXISTS", Token.EXISTS);
|
||||
map.put("CAST", Token.CAST);
|
||||
map.put("IN", Token.IN);
|
||||
map.put("ASC", Token.ASC);
|
||||
map.put("DESC", Token.DESC);
|
||||
map.put("LIKE", Token.LIKE);
|
||||
map.put("ESCAPE", Token.ESCAPE);
|
||||
map.put("BETWEEN", Token.BETWEEN);
|
||||
map.put("INTERVAL", Token.INTERVAL);
|
||||
map.put("LOCK", Token.LOCK);
|
||||
map.put("SOME", Token.SOME);
|
||||
map.put("ANY", Token.ANY);
|
||||
map.put("TRUNCATE", Token.TRUNCATE);
|
||||
map.put("IF", Token.IF);
|
||||
|
||||
map.put("TRUE", Token.TRUE);
|
||||
map.put("FALSE", Token.FALSE);
|
||||
map.put("LIMIT", Token.LIMIT);
|
||||
|
||||
DEFAULT_HBQL_KEYWORDS = new Keywords(map);
|
||||
}
|
||||
|
||||
public HBQLLexer(String input){
|
||||
super(input);
|
||||
super.keywods = DEFAULT_HBQL_KEYWORDS;
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package com.alibaba.druid.hdriver.impl.hbql.parser;
|
||||
|
||||
import com.alibaba.druid.hdriver.impl.hbql.ast.HBQLShowStatement;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.parser.SQLExprParser;
|
||||
import com.alibaba.druid.sql.parser.SQLStatementParser;
|
||||
|
||||
|
||||
public class HBQLStatementParser extends SQLStatementParser {
|
||||
protected SQLExprParser exprParser;
|
||||
|
||||
public HBQLStatementParser(String sql){
|
||||
super(new HBQLExprParser(sql));
|
||||
}
|
||||
|
||||
public HBQLStatementParser(SQLExprParser exprParser){
|
||||
super(exprParser);
|
||||
}
|
||||
|
||||
public SQLStatement parseShow() {
|
||||
acceptIdentifier("SHOW");
|
||||
acceptIdentifier("TABLES");
|
||||
return new HBQLShowStatement();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package com.alibaba.druid.hdriver.impl.hbql.visitor;
|
||||
|
||||
import com.alibaba.druid.hdriver.impl.hbql.ast.HBQLShowStatement;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTOutputVisitor;
|
||||
|
||||
|
||||
public class HBQLOutputVisitor extends SQLASTOutputVisitor implements HBQLVisitor {
|
||||
|
||||
public HBQLOutputVisitor(Appendable appender){
|
||||
super(appender);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(HBQLShowStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(HBQLShowStatement x) {
|
||||
print("SHOW TABLES");
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package com.alibaba.druid.hdriver.impl.hbql.visitor;
|
||||
|
||||
import com.alibaba.druid.hdriver.impl.hbql.ast.HBQLShowStatement;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public interface HBQLVisitor extends SQLASTVisitor {
|
||||
|
||||
void endVisit(HBQLShowStatement x);
|
||||
|
||||
boolean visit(HBQLShowStatement x);
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.alibaba.druid.hdriver.impl.mapping;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.hadoop.hbase.client.Result;
|
||||
|
||||
public interface HMapping {
|
||||
|
||||
byte[] getFamily(String columnName);
|
||||
|
||||
byte[] getQualifier(String columnName);
|
||||
|
||||
byte[] getRow(Result result, String columnName);
|
||||
|
||||
boolean isRow(String columnName);
|
||||
|
||||
Object getObject(Result result, String columnName);
|
||||
|
||||
byte[] toBytes(String columnName, Object value) throws IOException;
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
package com.alibaba.druid.hdriver.impl.mapping;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import org.apache.hadoop.hbase.client.Result;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
|
||||
public abstract class HMappingAdapter implements HMapping {
|
||||
|
||||
@Override
|
||||
public byte[] getQualifier(String columnName) {
|
||||
return Bytes.toBytes(columnName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getRow(Result result, String columnName) {
|
||||
return result.getRow();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getObject(Result result, String columnName) {
|
||||
byte[] family = this.getFamily(columnName);
|
||||
|
||||
byte[] bytes;
|
||||
if (isRow(columnName)) {
|
||||
bytes = getRow(result, columnName);
|
||||
} else {
|
||||
byte[] qualifier = Bytes.toBytes(columnName);
|
||||
bytes = result.getValue(family, qualifier);
|
||||
}
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] toBytes(String columnName, Object value) throws IOException {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
byte[] bytes;
|
||||
if (value instanceof String) {
|
||||
String strValue = (String) value;
|
||||
bytes = Bytes.toBytes(strValue);
|
||||
} else if (value instanceof Integer) {
|
||||
int intValue = ((Integer) value).intValue();
|
||||
bytes = Bytes.toBytes(intValue);
|
||||
} else if (value instanceof Long) {
|
||||
long longValue = ((Long) value).longValue();
|
||||
bytes = Bytes.toBytes(longValue);
|
||||
} else if (value instanceof Boolean) {
|
||||
boolean booleanValue = ((Boolean) value).booleanValue();
|
||||
bytes = Bytes.toBytes(booleanValue);
|
||||
} else if (value instanceof BigDecimal) {
|
||||
BigDecimal decimalValue = (BigDecimal) value;
|
||||
bytes = Bytes.toBytes(decimalValue);
|
||||
} else {
|
||||
throw new IOException("TODO"); // TODO
|
||||
}
|
||||
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package com.alibaba.druid.hdriver.impl.mapping;
|
||||
|
||||
public class HMappingColumn {
|
||||
|
||||
private String name;
|
||||
private Class<?> type;
|
||||
private transient boolean key = false;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Class<?> getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(Class<?> type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public boolean isKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setKey(boolean key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
package com.alibaba.druid.hdriver.impl.mapping;
|
||||
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
|
||||
public class HMappingDefaultImpl extends HMappingAdapter implements HMapping {
|
||||
|
||||
private byte[] family = Bytes.toBytes("d");
|
||||
private String rowColumn = "id";
|
||||
|
||||
public byte[] getFamily() {
|
||||
return family;
|
||||
}
|
||||
|
||||
public void setFamily(byte[] family) {
|
||||
this.family = family;
|
||||
}
|
||||
|
||||
public String getRowColumn() {
|
||||
return rowColumn;
|
||||
}
|
||||
|
||||
public void setRowColumn(String rowColumn) {
|
||||
this.rowColumn = rowColumn;
|
||||
}
|
||||
|
||||
public byte[] getFamily(String columnName) {
|
||||
return family;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRow(String columnName) {
|
||||
if (rowColumn.equals(columnName)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
package com.alibaba.druid.hdriver.impl.mapping;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class HMappingTable {
|
||||
|
||||
private String tableName;
|
||||
|
||||
private Map<String, HMappingColumn> columns = new LinkedHashMap<String, HMappingColumn>();
|
||||
private HMappingColumn keyColumn;
|
||||
|
||||
public String getTableName() {
|
||||
return tableName;
|
||||
}
|
||||
|
||||
public void setTableName(String tableName) {
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
public Collection<HMappingColumn> getColumns() {
|
||||
return Collections.unmodifiableCollection(columns.values());
|
||||
}
|
||||
|
||||
public void addColumn(HMappingColumn column) {
|
||||
this.columns.put(column.getName(), column);
|
||||
}
|
||||
|
||||
public HMappingColumn getColumn(String columnName) {
|
||||
return columns.get(columnName);
|
||||
}
|
||||
|
||||
public HMappingColumn getKeyColumn() {
|
||||
return keyColumn;
|
||||
}
|
||||
|
||||
public void setKeyColumn(HMappingColumn keyColumn) {
|
||||
keyColumn.setKey(true);
|
||||
this.keyColumn = keyColumn;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.alibaba.druid.sql.parser;
|
||||
|
||||
import com.alibaba.druid.hdriver.impl.hbql.parser.HBQLExprParser;
|
||||
import com.alibaba.druid.hdriver.impl.hbql.parser.HBQLStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlExprParser;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.oracle.parser.OracleExprParser;
|
||||
@@ -31,10 +29,6 @@ public class SQLParserUtils {
|
||||
return new SQLServerStatementParser(sql);
|
||||
}
|
||||
|
||||
if (JdbcUtils.HBASE.equals(dbType)) {
|
||||
return new HBQLStatementParser(sql);
|
||||
}
|
||||
|
||||
return new SQLStatementParser(sql);
|
||||
}
|
||||
|
||||
@@ -55,10 +49,6 @@ public class SQLParserUtils {
|
||||
return new SQLServerExprParser(sql);
|
||||
}
|
||||
|
||||
if (JdbcUtils.HBASE.equals(dbType)) {
|
||||
return new HBQLExprParser(sql);
|
||||
}
|
||||
|
||||
return new SQLExprParser(sql);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user