Nesting functions in bean-query

31 views
Skip to first unread message

shreedha...@gmail.com

unread,
Nov 18, 2018, 5:01:56 PM11/18/18
to Beancount
Hi, 

This issue showed up when I was writing tests for SUB() function for bean-query. The function/query dispatch mechanism doesn't like nested functions if the function arguments are declared as typed.

The error:
beancount>  select meta(meta('t'))
ERROR
: Invalid type for argument 0 of Meta: found <class 'object'> expected <class 'str'>.

The error comes from EvalFunctions.__init__():


        # Check each of the types.
        for index, (operand, intype) in enumerate(zip(operands, self.__intypes__)):
            if not issubclass(operand.dtype, intype):
                raise CompilationError(
                    "Invalid type for argument {} of {}: found {} expected {}".format(
                        index, type(self).__name__, operand.dtype, intype))



Perhaps this can be extended to include other EvalFunctions ? I took a shot at that and it seems to work for the given query. It's not extensively tested, but the tests under query passed.


PR: https://bitbucket.org/blais/beancount/pull-requests/88.


Let me know what you think. I can then add more tests - the only thing is that I'm not sure exactly where to add them.


Thanks!

- Shreedhar





shreedha...@gmail.com

unread,
Nov 18, 2018, 7:26:16 PM11/18/18
to Beancount
So playing around with this, I realized that this is a problem specific to functions that return "object" types. So it applies only for META, ANY_META & ENTRY_META, and, with my changes, COALESCE(). The return values can be casted with STR() where required and I can make COALESCE() a bit smarter. If the arguments of COALESCE() are the same, then that is obviously the return type!

Anyway, sorry for the spam on the mailing list about this. This might not really be an issue at all!

- Shreedhar
Reply all
Reply to author
Forward
0 new messages