Example #1
0
        /// <summary>
        /// Wait until query state became FINISHED.
        ///
        /// If the state became EXCEPTION throw exception.
        /// </summary>
        /// <param name="qh">QueryHandle to wait</param>
        /// <param name="sw">StopWatch to get elapsed time since the query starts.</param>
        private void WaitQueryStateFinished(QueryHandleWrapper qh, Stopwatch sw)
        {
            for (; ;)
            {
                var state = this.service.get_state(qh);
                if (state == QueryState.FINISHED)
                {
                    return;
                }
                else if (state == QueryState.EXCEPTION)
                {
                    var log = this.service.get_log(qh.Handle.Log_context);
                    throw new ImpalaException("Query aborted: " + log);
                }

                var msec    = 1000;
                var elapsed = sw.ElapsedMilliseconds;
                if (elapsed < 10 * 1000)
                {
                    msec = 100;
                }
                else if (elapsed < 60 * 1000)
                {
                    msec = 500;
                }

                Thread.Sleep(msec);
            }
        }
Example #2
0
        /// <summary>
        /// Cast query and get results.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="q"></param>
        /// <param name="conf"></param>
        /// <param name="createResult"></param>
        /// <param name="handleResults"></param>
        /// <returns></returns>
        private QueryResult <T> QueryInternal <T>(string q, Dictionary <string, string> conf, Func <ResultsMetadata, T> createResult, Action <ResultsMetadata, Results, T> handleResults)
        {
            var sw = Stopwatch.StartNew();

            using (var qh = this.CreateQueryHandle(q, conf))
                using (var cleaning = new DisposableAction(() => { this.currentQuery = null; }))
                {
                    this.currentQuery = qh;

                    this.WaitQueryStateFinished(qh, sw);

                    var metadata = this.service.get_results_metadata(qh);

                    var result = new QueryResult <T>();
                    result.Result = createResult(metadata);
                    var firstResponse = true;
                    for (; ;)
                    {
                        var results = this.service.fetch(qh, false, this.FetchSize);
                        if (firstResponse)
                        {
                            result.QueryTime = sw.Elapsed;
                            firstResponse    = false;
                        }

                        handleResults(metadata, results, result.Result);

                        if (!results.Has_more)
                        {
                            break;
                        }
                    }

                    var profile = this.service.GetRuntimeProfile(qh);
                    result.RuntimeProfile = profile;

                    result.ElapsedTime = sw.Elapsed;

                    return(result);
                }
        }