Ejemplo n.º 1
0
    def EvaluateScript(self, request, context):
        """
        This plugin provides functionality only for script calls with no parameters and tensor script calls.
        :param request:
        :param context:
        :return:
        """
        # Parse header for script request
        metadata = dict(context.invocation_metadata())
        header = SSE.ScriptRequestHeader()
        header.ParseFromString(metadata['qlik-scriptrequestheader-bin'])

        # Retrieve function type
        func_type = self.ScriptEval.get_func_type(header)

        # Verify function type
        if (func_type == FunctionType.Aggregation) or (func_type
                                                       == FunctionType.Tensor):
            return self.ScriptEval.EvaluateScript(header, request, context,
                                                  func_type)
        else:
            # This plugin does not support other function types than aggregation  and tensor.
            # Make sure the error handling, including logging, works as intended in the client
            msg = 'Function type {} is not supported in this plugin.'.format(
                func_type.name)
            context.set_code(grpc.StatusCode.UNIMPLEMENTED)
            context.set_details(msg)
            # Raise error on the plugin-side
            raise grpc.RpcError(grpc.StatusCode.UNIMPLEMENTED, msg)
    def test_evaluatescript(self):
        """
        Test EvaluateScript ColumnOperations.

        This test calls the EvaluateScript function with the
        script 'num1 + num2' and two numbers as parameters,
        effectively summarizing the two input numbers.
        """
        params = to_numeric_parameters('num1', 'num2')

        header = SSE.ScriptRequestHeader(script='args[0] + args[1]',
                                         functionType=SSE.TENSOR,
                                         returnType=SSE.NUMERIC,
                                         params=params)

        duals = numbers_to_duals(42, 42)
        rows = duals_to_rows(duals)

        # Trailing commas to make iterable sequences of tuples.
        bundled_rows = (SSE.BundledRows(rows=rows)),
        metadata = (('qlik-scriptrequestheader-bin', header.SerializeToString()), )

        result = self.stub.EvaluateScript(request_iterator=iter(bundled_rows), metadata=metadata)

        for bundled_row in result:
            for row in bundled_row.rows:
                for dual in row.duals:
                    assert dual.numData == 84
    def EvaluateScript(self, request, context):
        """
        This plugin provides functionality only for script calls with no parameters and tensor script calls.
        :param request:
        :param context:
        :return:
        """
        # Parse header for script request
        metadata = dict(context.invocation_metadata())
        header = SSE.ScriptRequestHeader()
        header.ParseFromString(metadata['qlik-scriptrequestheader-bin'])

        # Retrieve function type
        func_type = get_func_type(header)

        # Verify function type
        if (func_type == FunctionType.Aggregation) or (func_type
                                                       == FunctionType.Tensor):
            return self.scriptEval.EvaluateScript(header, request, func_type)
        else:
            # This plugin does not support other function types than aggregation  and tensor.
            raise grpc.RpcError(
                grpc.StatusCode.UNIMPLEMENTED,
                'Function type {} is not supported in this plugin.'.format(
                    func_type.name))
    def test_evaluatescript(self):
        """
        Test EvaluateScript HelloWorld.

        This test calls the EvaluateScript function with the
        script 'str1 + str2' and two strings as parameters,
        effectively concatenating the two input strings.
        """
        params = to_string_parameters('str1', 'str2')

        header = SSE.ScriptRequestHeader(script='args[0] + args[1]',
                                         functionType=SSE.TENSOR,
                                         returnType=SSE.STRING,
                                         params=params)

        duals = strings_to_duals('Hello', 'World')
        rows = duals_to_rows(duals)

        # Trailing commas to make iterable sequences of tuples.
        bundled_rows = (SSE.BundledRows(rows=rows)),
        metadata = (('qlik-scriptrequestheader-bin',
                     header.SerializeToString()), )

        result = self.stub.EvaluateScript(request_iterator=iter(bundled_rows),
                                          metadata=metadata)

        for bundled_row in result:
            for row in bundled_row.rows:
                for dual in row.duals:
                    assert dual.strData == 'HelloWorld'
Ejemplo n.º 5
0
    def EvaluateScript(self, request, context):
        """
        This plugin supports full script functionality, that is, all function types and all data types.
        :param request:
        :param context:
        :return:
        """
        # Parse header for script request
        metadata = dict(context.invocation_metadata())
        header = SSE.ScriptRequestHeader()
        header.ParseFromString(metadata['qlik-scriptrequestheader-bin'])

        return self.ScriptEval.EvaluateScript(header, request, context)
Ejemplo n.º 6
0
 def EvaluateScript(self, request, context):
     """
     This plugin supports full script functionality, that is, all function types and all data types.
     :param request:
     :param context:
     :return:
     """
     logging.debug('In EvaluateScript: Main')
     # Parse header for script request
     metadata = dict(context.invocation_metadata())
     logging.debug('Metadata {}', metadata)
     header = SSE.ScriptRequestHeader()
     header.ParseFromString(metadata['qlik-scriptrequestheader-bin'])
     logging.debug('Header is : {}'.format(header))
     logging.debug('Request is : {}'.format(request))
     logging.debug("Context is: {}".format(context))
     return self.ScriptEval.EvaluateScript(header, request, context)