@@ -41,6 +41,7 @@ public class HiveUtils {
4141
4242 private static final Logger LOGGER = LoggerFactory .getLogger (HiveUtils .class );
4343 private static final int DEFAULT_QUERY_PROGRESS_INTERVAL = 1000 ;
44+ private static final int MAX_STATEMENT_UNWRAP_DEPTH = 10 ;
4445
4546 private static final Pattern JOBURL_PATTERN =
4647 Pattern .compile (".*Tracking URL = (\\ S*).*" , Pattern .DOTALL );
@@ -59,8 +60,7 @@ public static void startHiveMonitorThread(Statement stmt,
5960 InterpreterContext context ,
6061 boolean displayLog ,
6162 JDBCInterpreter jdbcInterpreter ) {
62- HiveStatement hiveStmt = (HiveStatement )
63- ((DelegatingStatement ) ((DelegatingStatement ) stmt ).getDelegate ()).getDelegate ();
63+ HiveStatement hiveStmt = unwrapHiveStatement (stmt );
6464 String hiveVersion = HiveVersionInfo .getVersion ();
6565 ProgressBar progressBarTemp = null ;
6666 if (isProgressBarSupported (hiveVersion )) {
@@ -120,6 +120,27 @@ public static void startHiveMonitorThread(Statement stmt,
120120 }
121121 }
122122
123+ private static HiveStatement unwrapHiveStatement (Statement stmt ) {
124+
125+ Statement current = stmt ;
126+ int unwrapAttempts = 0 ;
127+
128+ while (current instanceof DelegatingStatement && unwrapAttempts < MAX_STATEMENT_UNWRAP_DEPTH ) {
129+ current = ((DelegatingStatement ) current ).getDelegate ();
130+ unwrapAttempts ++;
131+ if (current instanceof HiveStatement ) {
132+ return (HiveStatement ) current ;
133+ }
134+ }
135+
136+ LOGGER .warn ("Could not find HiveStatement within the Statement object after {} "
137+ + "unwrapping attempts. Final type inspected: {} "
138+ + "Hive query monitoring may not be active" ,
139+ MAX_STATEMENT_UNWRAP_DEPTH , current != null ?
140+ current .getClass ().getName () : "null" );
141+ return null ;
142+ }
143+
123144 /**
124145 * Extract hive job url in the following order:
125146 * 1. Extract job url from hive logs when hive use mr engine
0 commit comments