|
87 | 87 | import org.apache.hadoop.hive.common.StatsSetupConst.StatDB; |
88 | 88 | import org.apache.hadoop.hive.common.StringInternUtils; |
89 | 89 | import org.apache.hadoop.hive.common.TableName; |
90 | | -import org.apache.hadoop.hive.common.ValidTxnList; |
91 | 90 | import org.apache.hadoop.hive.common.ValidTxnWriteIdList; |
92 | 91 | import org.apache.hadoop.hive.common.metrics.common.MetricsConstant; |
93 | 92 | import org.apache.hadoop.hive.conf.Constants; |
@@ -363,7 +362,6 @@ public class SemanticAnalyzer extends BaseSemanticAnalyzer { |
363 | 362 | private final Map<TableScanOperator, Map<String, ExprNodeDesc>> opToPartToSkewedPruner; |
364 | 363 | private Map<SelectOperator, Table> viewProjectToTableSchema; |
365 | 364 | private Operator<? extends OperatorDesc> sinkOp; |
366 | | - private final CacheTableHelper cacheTableHelper = new CacheTableHelper(); |
367 | 365 |
|
368 | 366 | /** |
369 | 367 | * a map for the split sampling, from alias to an instance of SplitSample |
@@ -2883,8 +2881,7 @@ private void replaceViewReferenceWithDefinition(QB qb, Table tab, |
2883 | 2881 | String viewText = tab.getViewExpandedText(); |
2884 | 2882 | TableMask viewMask = new TableMask(this, conf, false); |
2885 | 2883 | viewTree = ParseUtils.parse(viewText, ctx, tab.getCompleteName()); |
2886 | | - cacheTableHelper.populateCacheForView(ctx.getParsedTables(), conf, |
2887 | | - getTxnMgr(), tab.getDbName(), tab.getTableName()); |
| 2884 | + |
2888 | 2885 | if (viewMask.isEnabled() && analyzeRewrite == null) { |
2889 | 2886 | ParseResult parseResult = rewriteASTWithMaskAndFilter(viewMask, viewTree, |
2890 | 2887 | ctx.getViewTokenRewriteStream(viewFullyQualifiedName), |
@@ -13163,16 +13160,13 @@ void analyzeInternal(ASTNode ast, Supplier<PlannerContext> pcf) throws SemanticE |
13163 | 13160 | perfLogger.perfLogBegin(this.getClass().getName(), PerfLogger.GENERATE_RESOLVED_PARSETREE); |
13164 | 13161 | // 1. Generate Resolved Parse tree from syntax tree |
13165 | 13162 | boolean needsTransform = needsTransform(); |
13166 | | - //change the location of position alias process here |
| 13163 | + // change the location of position alias process here |
13167 | 13164 | processPositionAlias(ast); |
13168 | | - cacheTableHelper.populateCache(ctx.getParsedTables(), conf, getTxnMgr()); |
13169 | 13165 | PlannerContext plannerCtx = pcf.get(); |
13170 | 13166 | if (!genResolvedParseTree(ast, plannerCtx)) { |
13171 | 13167 | return; |
13172 | 13168 | } |
13173 | | - if (tablesFromReadEntities(inputs).stream().anyMatch(AcidUtils::isTransactionalTable)) { |
13174 | | - queryState.getValidTxnList(); |
13175 | | - } |
| 13169 | + openTxnAndSetValidTxnList(); |
13176 | 13170 |
|
13177 | 13171 | if (HiveConf.getBoolVar(conf, ConfVars.HIVE_REMOVE_ORDERBY_IN_SUBQUERY)) { |
13178 | 13172 | for (String alias : qb.getSubqAliases()) { |
@@ -15164,39 +15158,48 @@ private String getQueryStringForCache(ASTNode ast) { |
15164 | 15158 | .toString(RESULTS_CACHE_KEY_TOKEN_REWRITE_PROGRAM, ast.getTokenStartIndex(), ast.getTokenStopIndex()); |
15165 | 15159 | } |
15166 | 15160 |
|
15167 | | - private ValidTxnWriteIdList getQueryValidTxnWriteIdList() throws SemanticException { |
| 15161 | + private void openTxnAndSetValidTxnList() throws SemanticException { |
| 15162 | + if (tablesFromReadEntities(inputs).stream().noneMatch(AcidUtils::isTransactionalTable) |
| 15163 | + || SessionState.get().isCompaction()) { |
| 15164 | + return; |
| 15165 | + } |
| 15166 | + if (queryState.getHMSCache() != null) { |
| 15167 | + // this step primes the cache containing the validTxnWriteIdList. It will fetch |
| 15168 | + // all the tables into the MetaStore Client cache with one HMS call. |
| 15169 | + getValidTxnWriteIdList(); |
| 15170 | + } else { |
| 15171 | + queryState.getValidTxnList(); |
| 15172 | + } |
| 15173 | + } |
| 15174 | + |
| 15175 | + private ValidTxnWriteIdList getValidTxnWriteIdList() throws SemanticException { |
15168 | 15176 | // TODO: Once HIVE-18948 is in, should be able to retrieve writeIdList from the conf. |
15169 | | - //cachedWriteIdList = AcidUtils.getValidTxnWriteIdList(conf); |
| 15177 | + // cachedWriteIdList = AcidUtils.getValidTxnWriteIdList(conf); |
15170 | 15178 | // |
15171 | | - List<String> transactionalTables = tablesFromReadEntities(inputs) |
15172 | | - .stream() |
15173 | | - .filter(AcidUtils::isTransactionalTable) |
15174 | | - .map(Table::getFullyQualifiedName) |
15175 | | - .collect(Collectors.toList()); |
15176 | | - |
15177 | | - if (transactionalTables.size() > 0) { |
15178 | | - String txnString = queryState.getValidTxnList(); |
15179 | | - if (txnString == null) { |
15180 | | - return null; |
15181 | | - } |
15182 | | - try { |
15183 | | - return getTxnMgr().getValidWriteIds(transactionalTables, txnString); |
15184 | | - } catch (Exception err) { |
15185 | | - String msg = "Error while getting the txnWriteIdList for tables " + transactionalTables |
15186 | | - + " and validTxnList " + conf.get(ValidTxnList.VALID_TXNS_KEY); |
15187 | | - throw new SemanticException(msg, err); |
15188 | | - } |
15189 | | - } |
| 15179 | + var transactionalTables = tablesFromReadEntities(inputs) |
| 15180 | + .stream() |
| 15181 | + .filter(AcidUtils::isTransactionalTable) |
| 15182 | + .map(Table::getFullyQualifiedName) |
| 15183 | + .toList(); |
15190 | 15184 |
|
15191 | | - // No transactional tables. |
15192 | | - return null; |
| 15185 | + if (transactionalTables.isEmpty()) { |
| 15186 | + return null; |
| 15187 | + } |
| 15188 | + String txnString = queryState.getValidTxnList(); |
| 15189 | + try { |
| 15190 | + return getTxnMgr().getValidWriteIds(transactionalTables, txnString); |
| 15191 | + } catch (Exception err) { |
| 15192 | + String msg = "Error while getting the txnWriteIdList for tables " + transactionalTables |
| 15193 | + + " and validTxnList " + txnString; |
| 15194 | + throw new SemanticException(msg, err); |
| 15195 | + } |
15193 | 15196 | } |
15194 | 15197 |
|
15195 | 15198 | private QueryResultsCache.LookupInfo createLookupInfoForQuery(ASTNode astNode) throws SemanticException { |
15196 | 15199 | QueryResultsCache.LookupInfo lookupInfo = null; |
15197 | 15200 | String queryString = getQueryStringForCache(astNode); |
15198 | 15201 | if (queryString != null) { |
15199 | | - ValidTxnWriteIdList writeIdList = getQueryValidTxnWriteIdList(); |
| 15202 | + ValidTxnWriteIdList writeIdList = getValidTxnWriteIdList(); |
15200 | 15203 | Set<Long> involvedTables = tablesFromReadEntities(inputs).stream() |
15201 | 15204 | .map(Table::getTTable) |
15202 | 15205 | .map(org.apache.hadoop.hive.metastore.api.Table::getId) |
|
0 commit comments