kasakrisz commented on code in PR #5613: URL: https://github.com/apache/hive/pull/5613#discussion_r1939151452
########## ql/src/java/org/apache/hadoop/hive/ql/parse/BaseSemanticAnalyzer.java: ########## @@ -2094,4 +2117,79 @@ protected String getFullTableNameForSQL(ASTNode n) throws SemanticException { } } + public QB getQB(){ + return null; + } + + /** + * Resolves the query type from the SemanticAnalyzer and the query AST, which might look magic. + * Magic is needed because a query can fail due to semantic exceptions, and at that time, from syntax point of view, + * it's already clear what's the query type, even if the SemanticAnalyzer bailed out, typical problems: + * 1. general semantic exception + * 2. transaction manager validation (throwin exception) + * What a user expects here is something like "QUERY", "DDL", "DML", so this magic will do its best to tell. + * any kind of "analyze": STATS + * DML operations (INSERT, UPDATE, DELETE, MERGE): DML + * MAPRED: QUERY, DML (depending on QueryProperties achieved in compile time) + * FETCH: QUERY, as a simple fetch task is a QUERY + * empty string if we can't determine the type of the query, + * e.g. when ParseException happens, we won't do further magic, + * even if it's obvious by reading the sql statement that user wanted to run e.g. a select query + * @param tree the root ASTNode of the query + */ + public void setQueryType(ASTNode tree) { + List<Task<? extends Serializable>> rootTasks = getAllRootTasks(); + if (queryProperties == null) { + return; + } + queryProperties.setQueryType(queryProperties.isAnalyze() ? QueryType.STATS : Review Comment: IMHO this should be a utility method only if it is also used outside of SAs. BTW can we override it in subclasses of SA? IIUC the type of SA has an impact on the query type. * Lots of query types are handled by `SemanticAnalyzer` like queries (DQL) and inserts. * but others like Update/Delete/Merge are handled by `RewriteSemanticAnalyzer` So `RewriteSemanticAnalyzer. setQueryType` always sets `QueryType.DML` * Stats goes to `ColumnStatsSemanticAnalyzer` * DDL: everything created by `DDLSemanticAnalyzerFactory` always sets `QueryType.DDL`. Create MV is still in `SemanticAnalyzer` so that must be handled there. * etc -- 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: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org For additional commands, e-mail: gitbox-h...@hive.apache.org