kasakrisz commented on code in PR #4672:
URL: https://github.com/apache/hive/pull/4672#discussion_r1336797000
##########
ql/src/java/org/apache/hadoop/hive/ql/ddl/table/misc/truncate/TruncateTableAnalyzer.java:
##########
@@ -80,8 +86,25 @@ public void analyzeInternal(ASTNode root) throws
SemanticException {
checkTruncateEligibility(root, tableNode, tableNameString, table);
Map<String, String> partitionSpec = getPartSpec((ASTNode)
tableNode.getChild(1));
+
addTruncateTableOutputs(tableNode, table, partitionSpec);
+ if (table.getStorageHandler() != null &&
!table.getStorageHandler().shouldTruncate(table, partitionSpec)) {
+ // Transform the truncate query to delete query.
+ StringBuilder rewrittenQuery = constructDeleteQuery(table,
partitionSpec);
+ ReparseResult rr = ParseUtils.parseRewrittenQuery(conf, ctx,
rewrittenQuery);
+ Context rewrittenCtx = rr.rewrittenCtx;
+ ASTNode rewrittenTree = rr.rewrittenTree;
+
+ BaseSemanticAnalyzer deleteAnalyzer =
SemanticAnalyzerFactory.get(queryState, rewrittenTree);
Review Comment:
Actually extending `RewriteSemanticAnalyzer` means implementing two methods
only:
* `protected ASTNode getTargetTableNode(ASTNode tree)`
* `protected void analyze(ASTNode tree, Table table, ASTNode tableName)
throws SemanticException`
but the more problematic part is that currently `TruncateTableAnalyzer`
extends `AbstractBaseAlterTableAnalyzer` and we can not extend from both
classes.
Ideally the common parts of the rewrite logic should be implemented by a
class which is not part of the `SemanticAnalyzer` class hierarchy hence that
could be wrapped by SAs which needs rewrite. The use cases which needs rewrite
seems to be increasing so sooner or later we should do such refactor.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]