Skip to content

Commit

Permalink
HIVE-23820: add tableId in getTable request
Browse files Browse the repository at this point in the history
  • Loading branch information
ashish-kumar-sharma committed Apr 16, 2021
1 parent 3747f84 commit e2470b3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
17 changes: 9 additions & 8 deletions ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.conf.HiveConf.ConfVars;
import org.apache.hadoop.hive.metastore.api.GetPartitionsByNamesRequest;
import org.apache.hadoop.hive.metastore.api.GetTableRequest;
import org.apache.hadoop.hive.ql.io.HdfsUtils;
import org.apache.hadoop.hive.metastore.HiveMetaException;
import org.apache.hadoop.hive.metastore.HiveMetaHook;
Expand Down Expand Up @@ -1526,19 +1527,19 @@ public Table getTable(final String dbName, final String tableName, boolean throw
org.apache.hadoop.hive.metastore.api.Table tTable = null;
try {
// Note: this is currently called w/true from StatsOptimizer only.
GetTableRequest request = new GetTableRequest(dbName, tableName);
request.setCatName(getDefaultCatalog(conf));
request.setGetColumnStats(getColumnStats);
request.setEngine(Constants.HIVE_ENGINE);
if (checkTransactional) {
ValidWriteIdList validWriteIdList = null;
long txnId = SessionState.get().getTxnMgr() != null ?
SessionState.get().getTxnMgr().getCurrentTxnId() : 0;
long txnId = SessionState.get().getTxnMgr() != null ? SessionState.get().getTxnMgr().getCurrentTxnId() : 0;
if (txnId > 0) {
validWriteIdList = AcidUtils.getTableValidWriteIdListWithTxnList(conf,
dbName, tableName);
validWriteIdList = AcidUtils.getTableValidWriteIdListWithTxnList(conf, dbName, tableName);
}
tTable = getMSC().getTable(getDefaultCatalog(conf), dbName, tableName,
validWriteIdList != null ? validWriteIdList.toString() : null, getColumnStats, Constants.HIVE_ENGINE);
} else {
tTable = getMSC().getTable(dbName, tableName, getColumnStats, Constants.HIVE_ENGINE);
request.setValidWriteIdList(validWriteIdList != null ? validWriteIdList.toString() : null);
}
tTable = getMSC().getTable(request);
} catch (NoSuchObjectException e) {
if (throwException) {
throw new InvalidTableException(tableName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2079,10 +2079,20 @@ protected GetTableResult getTableInternal(GetTableRequest req) throws TException
Map<Object, Object> queryCache = getQueryCache();
if (queryCache != null) {
// Retrieve or populate cache
CacheKey cacheKeyTableId = new CacheKey(KeyType.TABLE_ID,req.getCatName(),req.getDbName(),req.getTblName());
long tableId = -1;

if(queryCache.get(cacheKeyTableId) != null)
tableId = (long)queryCache.get(cacheKeyTableId);

req.setId(tableId);
CacheKey cacheKey = new CacheKey(KeyType.TABLE, req);
GetTableResult v = (GetTableResult) queryCache.get(cacheKey);
if (v == null) {
v = super.getTableInternal(req);
if(tableId == -1) {
queryCache.put(cacheKeyTableId, v.getTable().getId());
}
queryCache.put(cacheKey, v);
} else {
LOG.debug(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ public enum KeyType {
// GetValidWriteIdsResponse <-- getValidWriteIdsInternal(GetValidWriteIdsRequest rqst)
// Stored individually as:
// TableValidWriteIds <-- String fullTableName, String validTxnList, long writeId
VALID_WRITE_IDS(TableValidWriteIds.class, String.class, long.class);
VALID_WRITE_IDS(TableValidWriteIds.class, String.class, long.class),
// TableId <- String fullTableName
TABLE_ID(Long.class, String.class);

private final List<Class<?>> keyClasses;
private final Class<?> valueClass;
Expand Down

0 comments on commit e2470b3

Please sign in to comment.