Ejemplo n.º 1
0
        public RServeEvaluator(RserveParameter para)
        {
            connPool   = new RserveConnectionPool();
            rservePara = para;
            RserveConnection rserveConnInitial = connPool.GetConnection(rservePara);

            logger.Trace($"Rserve connection initiated: {rserveConnInitial!=null}");
        }
Ejemplo n.º 2
0
        public override async global::System.Threading.Tasks.Task EvaluateScript(IAsyncStreamReader <global::Qlik.Sse.BundledRows> requestStream, IServerStreamWriter <global::Qlik.Sse.BundledRows> responseStream, ServerCallContext context)
        {
            ScriptRequestHeader scriptHeader;
            RserveConnection    rserveConn;

            try
            {
                rserveConn = connPool.GetConnection(rservePara);

                var header = GetHeader(context.RequestHeaders, "qlik-scriptrequestheader-bin");
                scriptHeader = ScriptRequestHeader.Parser.ParseFrom(header);
            }
            catch (Exception e)
            {
                logger.Error($"EvaluateScript failed: {e.Message}");
                throw new RpcException(new Status(StatusCode.DataLoss, e.Message));
            }

            try
            {
                var stopwatch = new Stopwatch();
                stopwatch.Start();

                logger.Info($"Evaluating {scriptHeader.Script}");
                var paramnames = "Param names: ";
                foreach (var param in scriptHeader.Params)
                {
                    paramnames += $" {param.Name}";
                }
                logger.Info("{0}", paramnames);
                if (scriptHeader.Params != null && scriptHeader.Params.Count > 0)
                {
                    await AddInputData(scriptHeader.Params.ToArray(), requestStream, rserveConn);
                }
                var res = rserveConn.Connection.Eval(scriptHeader.Script);
                logger.Info($"Rserve result: {res.Count} rows");

                // Disable caching (uncomment line below if you do not want the results sent to Qlik to be cached in Qlik)
                // await context.WriteResponseHeadersAsync(new Metadata { { "qlik-cache", "no-store" } });

                await GenerateResult(res, responseStream, rserveConn);

                stopwatch.Stop();
                logger.Debug($"Took {stopwatch.ElapsedMilliseconds} ms");
            }
            catch (Exception e)
            {
                HandleError(e, rserveConn);
            }
            finally
            {
                //
            }
        }
Ejemplo n.º 3
0
        public RServeEvaluator(RserveParameter para, bool enableScript, string functionDefinitionsFile)
        {
            allowScript = enableScript;
            if (!String.IsNullOrEmpty(functionDefinitionsFile))
            {
                definedFunctions = new DefinedFunctions(functionDefinitionsFile);
            }
            CreateCapabilities();
            connPool   = new RserveConnectionPool();
            rservePara = para;

            RserveConnection rserveConnInitial = connPool.GetConnection(rservePara);

            logger.Trace($"Rserve connection initiated: {rserveConnInitial != null}");
        }
Ejemplo n.º 4
0
        public override async Task ExecuteFunction(IAsyncStreamReader <BundledRows> requestStream, IServerStreamWriter <BundledRows> responseStream, ServerCallContext context)
        {
            FunctionRequestHeader functionHeader;
            CommonRequestHeader   commonHeader;
            RserveConnection      rserveConn;
            int reqHash = requestStream.GetHashCode();

            Qlik.Sse.FunctionDefinition sseFunction;
            DefinedFunctions.Function   internalFunction;

            if (nrOfDefinedFunctions == 0)
            {
                throw new RpcException(new Status(StatusCode.Unimplemented, $"No functions defined"));
            }

            try
            {
                rserveConn = connPool.GetConnection(rservePara);

                var header = GetHeader(context.RequestHeaders, "qlik-functionrequestheader-bin");
                functionHeader = FunctionRequestHeader.Parser.ParseFrom(header);

                var commonRequestHeader = GetHeader(context.RequestHeaders, "qlik-commonrequestheader-bin");
                commonHeader = CommonRequestHeader.Parser.ParseFrom(commonRequestHeader);

                logger.Info($"ExecuteFunction: FunctionId ({functionHeader.FunctionId}), from client ({context.Peer}), hashid ({reqHash})");
                logger.Debug($"ExecuteFunction header info: AppId ({commonHeader.AppId}), UserId ({commonHeader.UserId}), Cardinality ({commonHeader.Cardinality} rows)");

                int funcIndex = definedFunctions.GetIndexOfFuncId(functionHeader.FunctionId);

                if (funcIndex < 0)
                {
                    throw new Exception($"FunctionId ({functionHeader.FunctionId}) is not a defined function");
                }
                sseFunction      = definedFunctions.sseFunctions[funcIndex];
                internalFunction = definedFunctions.funcDefs.functions[funcIndex];
            }
            catch (Exception e)
            {
                logger.Error($"ExecuteFunction with hashid ({reqHash}) failed: {e.Message}");
                throw new RpcException(new Status(StatusCode.DataLoss, e.Message));
            }

            try
            {
                var stopwatch = new Stopwatch();
                stopwatch.Start();

                SexpList inputDataFrame = null;

                if (sseFunction.Params.Count > 0)
                {
                    inputDataFrame = await AddInputData(sseFunction.Params.ToArray(), requestStream);
                }

                var rResult = await EvaluateScriptInRserve(inputDataFrame, reqHash, internalFunction.FunctionRScript.Replace("\r", " "), rserveConn);

                await GenerateResult(rResult, responseStream, context, true, sseFunction.ReturnType, internalFunction.CacheResultInQlik);

                stopwatch.Stop();
                logger.Debug($"Took {stopwatch.ElapsedMilliseconds} ms, hashid ({reqHash})");
            }
            catch (Exception e)
            {
                throw new RpcException(new Status(StatusCode.InvalidArgument, $"{e.Message}"));
            }
            finally
            {
                //
            }
        }