|
3 | 3 | import com.alipay.oceanbase.rpc.ObTableClient;
|
4 | 4 | import com.alipay.oceanbase.rpc.bolt.transport.TransportCodes;
|
5 | 5 | import com.alipay.oceanbase.hbase.exception.FeatureNotSupportedException;
|
| 6 | +import com.alipay.oceanbase.rpc.exception.ObTableException; |
6 | 7 | import com.alipay.oceanbase.rpc.exception.ObTableTransportException;
|
7 | 8 | import com.alipay.oceanbase.rpc.meta.ObTableRpcMetaType;
|
| 9 | +import com.alipay.oceanbase.rpc.protocol.payload.ResultCodes; |
8 | 10 | import org.apache.hadoop.conf.Configuration;
|
9 | 11 | import org.apache.hadoop.hbase.*;
|
10 | 12 | import org.apache.hadoop.hbase.client.*;
|
@@ -63,10 +65,27 @@ public Connection getConnection() {
|
63 | 65 |
|
64 | 66 | @Override
|
65 | 67 | public boolean tableExists(TableName tableName) throws IOException {
|
66 |
| - OHConnectionConfiguration connectionConf = new OHConnectionConfiguration(conf); |
67 |
| - ObTableClient tableClient = ObTableClientManager.getOrCreateObTableClientByTableName(tableName, connectionConf); |
68 |
| - OHTableExistsExecutor executor = new OHTableExistsExecutor(tableClient); |
69 |
| - return executor.tableExists(tableName.getNameAsString()); |
| 68 | + try { |
| 69 | + OHConnectionConfiguration connectionConf = new OHConnectionConfiguration(conf); |
| 70 | + ObTableClient tableClient = ObTableClientManager.getOrCreateObTableClientByTableName(tableName, connectionConf); |
| 71 | + OHTableExistsExecutor executor = new OHTableExistsExecutor(tableClient); |
| 72 | + return executor.tableExists(tableName.getNameAsString()); |
| 73 | + } catch (Exception e) { |
| 74 | + // try to get the original cause |
| 75 | + Throwable cause = e.getCause(); |
| 76 | + while(cause != null && cause.getCause() != null) { |
| 77 | + cause = cause.getCause(); |
| 78 | + } |
| 79 | + if (cause instanceof ObTableException) { |
| 80 | + int errCode = ((ObTableException) cause).getErrorCode(); |
| 81 | + // if the original cause is database_not_exist, means namespace in tableName does not exist |
| 82 | + // for HBase, namespace not exist will not throw exceptions but will return false |
| 83 | + if (errCode == ResultCodes.OB_ERR_BAD_DATABASE.errorCode) { |
| 84 | + return false; |
| 85 | + } |
| 86 | + } |
| 87 | + throw e; |
| 88 | + } |
70 | 89 | }
|
71 | 90 |
|
72 | 91 | @Override
|
|
0 commit comments