Пример #1
0
    def fldtype(self):
        """return fldtype (qtype) of a scalar"""

        func_str = q_consts.scalar_func_str.format(fn_name="fldtype")
        func = executor.eval_lua(func_str)
        result = func(self.base_scalar)
        return result
Пример #2
0
    def set_name(self, name):
        """sets the name of a reducer"""

        func_str = vec_func_arg_str.format(fn_name="set_name")
        func = executor.eval_lua(func_str)
        result = func(self.base_reducer, name)
        return self
Пример #3
0
    def persist(self, is_persist):
        """sets the persist flag for vector"""

        func_str = q_consts.vec_func_arg_str.format(fn_name="persist")
        func = executor.eval_lua(func_str)
        result = func(self.base_vec, is_persist)
        return self
Пример #4
0
    def get_name(self):
        """returns the name of a vector"""

        func_str = q_consts.vec_func_str.format(fn_name="get_name")
        func = executor.eval_lua(func_str)
        result = func(self.base_vec)
        return result
Пример #5
0
    def num_elements(self):
        """returns the num_elements of vector"""

        func_str = q_consts.vec_func_str.format(fn_name="num_elements")
        func = executor.eval_lua(func_str)
        result = func(self.base_vec)
        return result
Пример #6
0
    def memo(self, is_memo):
        """sets the memo value for vector"""

        func_str = q_consts.vec_func_arg_str.format(fn_name="memo")
        func = executor.eval_lua(func_str)
        result = func(self.base_vec, is_memo)
        return self
Пример #7
0
    def get_name(self):
        """returns the name of a reducer"""

        func_str = vec_func_str.format(fn_name="get_name")
        func = executor.eval_lua(func_str)
        result = func(self.base_reducer)
        return result
Пример #8
0
    def is_memo(self):
        """returns memo value for vector"""

        func_str = q_consts.vec_func_str.format(fn_name="is_memo")
        func = executor.eval_lua(func_str)
        result = func(self.base_vec)
        return result
Пример #9
0
def call_lua_op(op_name, *args):
    """
    this functions calls the given Q-lua function with specified arguments

    Parameters:
        op_name: operation (Q-lua function) name (is a string)
        args: arguments to be passed to specified function

    Return:
        execution result of a function
    """

    # convert the python objects to lua
    args_table = util.pack_args(args)
    try:
        func = executor.eval_lua(q_consts.lua_op_fn_str)
        result = func(op_name, args_table)
    except Exception as e:
        # TODO: Handle operator level failures properly
        print(str(e))
        result = None
    if result:
        # wrap the lua objects to python
        result = util.wrap_output(op_name, result)
    return result
Пример #10
0
    def __check_and_execute(self, other, operation):
        """
        checks the given value and executes specified scalar operation

        Parameters:
            other: a given value with which a scalar is getting operated
            operation: operation specification (is a string)

        Returns:
            the scalar object
        """

        if not (is_p_scalar(other) or isinstance(other, int) or isinstance(other, float)):
            raise Exception("Second argument type {} is not supported".format(type(other)))
        # converts int and floats to scalar
        if isinstance(other, int):
            other = PScalar(other, q_consts.I8)
        elif isinstance(other, float):
            other = PScalar(other, q_consts.F8)
        else:
            # it's a PScalar, nothing to do
            pass
        other = other.get_base_scalar()
        func_str = q_consts.scalar_arith_func_str.format(op=operation)
        func = executor.eval_lua(func_str)
        result = func(self.base_scalar, other)
        return PScalar(base_scalar=result)
Пример #11
0
    def abs(self):
        """convert scalar to absolute"""

        func_str = q_consts.scalar_func_str.format(fn_name="abs")
        func = executor.eval_lua(func_str)
        result = func(self.base_scalar)
        return result
Пример #12
0
    def conv(self, qtype):
        """convert scalar to other qtype"""

        func_str = q_consts.scalar_func_arg_str.format(fn_name="conv")
        func = executor.eval_lua(func_str)
        result = func(self.base_scalar, qtype)
        return self
Пример #13
0
    def qtype(self):
        """returns the qtype (field type) of vector"""

        func_str = q_consts.vec_func_str.format(fn_name="qtype")
        func = executor.eval_lua(func_str)
        result = func(self.base_vec)
        return result
Пример #14
0
    def value(self):
        """returns value of a reducer"""

        func_str = vec_func_str.format(fn_name="value")
        func = executor.eval_lua(func_str)
        result = func(self.base_reducer)
        return PScalar(base_scalar=result)
Пример #15
0
 def __init__(self, val=None, qtype=None, base_scalar=None):
     if base_scalar:
         self.base_scalar = base_scalar
     else:
         if not val or not qtype:
             raise Exception("Provide appropriate argument to PScalar constructor")
         # create a base scalar object
         func = executor.eval_lua(q_consts.create_scalar_str)
         self.base_scalar = func(val, qtype)
Пример #16
0
    def length(self):
        """
        returns the vector length
        this method is applicable only for eval'ed vectors
        """

        func_str = q_consts.vec_func_str.format(fn_name="length")
        func = executor.eval_lua(func_str)
        result = func(self.base_vec)
        return result
Пример #17
0
def to_table(in_val):
    """
    converts input list or dict to table

    Parameters:
        in_val: a list or dict

    Returns:
        returns a lua table
    """

    func = None
    if type(in_val) == list:
        func = executor.eval_lua(list_to_table_str)
    elif type(in_val) == dict:
        func = executor.eval_lua(dict_to_table_str)
        in_val = lupa.as_attrgetter(in_val)
    else:
        print("Error")
    return func(in_val)
Пример #18
0
    def to_str(self):
        """
        convert scalar to string

        Returns:
            returns a string representation of scalar
        """

        func_str = q_consts.scalar_func_str.format(fn_name="to_str")
        func = executor.eval_lua(func_str)
        result = func(self.base_scalar)
        return result
Пример #19
0
    def set_name(self, name):
        """
        sets the name of a vector

        Parameters:
            name: name to be assigned to vector
        """

        func_str = q_consts.vec_func_arg_str.format(fn_name="set_name")
        func = executor.eval_lua(func_str)
        result = func(self.base_vec, name)
        return self
Пример #20
0
    def to_cmem(self):
        """
        convert scalar to cmem

        Returns:
            returns cmem object associated with scalar
        """

        func_str = q_consts.scalar_func_str.format(fn_name="to_cmem")
        func = executor.eval_lua(func_str)
        result = func(self.base_scalar)
        return result
Пример #21
0
    def eval(self):
        """
        evaluate the vector

        Returns:
            Returns the PVector object
        """

        func_str = q_consts.vec_func_str.format(fn_name="eval")
        func = executor.eval_lua(func_str)
        result = func(self.base_vec)
        return self
Пример #22
0
    def to_num(self):
        """
        converts a scalar to number

        Returns:
            returns a numeric value associated with scalar
        """

        func_str = q_consts.scalar_func_str.format(fn_name="to_num")
        try:
            func = executor.eval_lua(func_str)
            result = func(self.base_scalar)
        except Exception as e:
            raise Exception("Failed to convert scalar to number")
        return result
Пример #23
0
    def eval(self):
        """
        evaluates the reducer

        Returns:
            returns a tuple of scalars (what we get from Q-lau)
        """

        func_str = vec_func_str.format(fn_name="eval")
        func = executor.eval_lua(func_str)
        result = func(self.base_reducer)
        new_result = []
        if type(result) == tuple:
            for val in result:
                new_result.append(PScalar(base_scalar=val))
        result = tuple(new_result)
        return result
Пример #24
0
    return t
    """
q_operators = [str(x) for x in dict(lua_executor.execute_lua(q_op_str)).keys()]

# for i in q_operators:
#     print(i)


func_str = \
    """
    function(a, b)
        return a + b
    end
    """

func = lua_executor.eval_lua(func_str)
try:
    print(func(5, 9))
    print(func(None, 9))
except Exception as e:
    print(str(e))
print("Done")

print("=======================")

in_val = [1, 2, 3, 4]
res = utils.to_table(in_val)
print(type(res))
print(list(res))
print(dict(res))