Thread

  1. PL/Python result object str handler

    Peter Eisentraut <peter_e@gmx.net> — 2013-01-08T02:58:45Z

    For debugging PL/Python functions, I'm often tempted to write something
    like
    
    rv = plpy.execute(...)
    plpy.info(rv)
    
    which prints something unhelpful like
    
    <PLyResult object at 0xb461d8d8>
    
    By implementing a "str" handler for the result object, it now prints
    something like
    
    <PLyResult status=5 nrows=2 rows=[{'foo': 1, 'bar': '11'}, {'foo': 2, 'bar': '22'}]>
    
    Patch attached for review.
    
    
  2. Re: PL/Python result object str handler

    Magnus Hagander <magnus@hagander.net> — 2013-01-08T09:32:40Z

    On Tue, Jan 8, 2013 at 3:58 AM, Peter Eisentraut <peter_e@gmx.net> wrote:
    > For debugging PL/Python functions, I'm often tempted to write something
    > like
    >
    > rv = plpy.execute(...)
    > plpy.info(rv)
    >
    > which prints something unhelpful like
    >
    > <PLyResult object at 0xb461d8d8>
    >
    > By implementing a "str" handler for the result object, it now prints
    > something like
    >
    > <PLyResult status=5 nrows=2 rows=[{'foo': 1, 'bar': '11'}, {'foo': 2, 'bar': '22'}]>
    >
    > Patch attached for review.
    
    How does it work if there are many rows in there? Say the result
    contains 10,000 rows - will the string contain all of them? If so,
    might it be worthwhile to cap the number of rows shown and then follow
    with a "..." or something?
    
    --
     Magnus Hagander
     Me: http://www.hagander.net/
     Work: http://www.redpill-linpro.com/
    
    
    
  3. Re: PL/Python result object str handler

    Daniele Varrazzo <daniele.varrazzo@gmail.com> — 2013-01-08T16:55:58Z

    On Tue, Jan 8, 2013 at 9:32 AM, Magnus Hagander <magnus@hagander.net> wrote:
    > On Tue, Jan 8, 2013 at 3:58 AM, Peter Eisentraut <peter_e@gmx.net> wrote:
    >> For debugging PL/Python functions, I'm often tempted to write something
    >> like
    >>
    >> rv = plpy.execute(...)
    >> plpy.info(rv)
    >>
    >> which prints something unhelpful like
    >>
    >> <PLyResult object at 0xb461d8d8>
    >>
    >> By implementing a "str" handler for the result object, it now prints
    >> something like
    >>
    >> <PLyResult status=5 nrows=2 rows=[{'foo': 1, 'bar': '11'}, {'foo': 2, 'bar': '22'}]>
    
    This looks more a repr-style format to me (if you implement repr but
    not str, the latter will default to the former).
    
    
    >> Patch attached for review.
    >
    > How does it work if there are many rows in there? Say the result
    > contains 10,000 rows - will the string contain all of them? If so,
    > might it be worthwhile to cap the number of rows shown and then follow
    > with a "..." or something?
    
    I think it would: old django versions were a pain in the neck because
    when a page broke an entire dump of gigantic queries was often dumped
    as debug info.
    
    -- Daniele
    
    
    
  4. Re: PL/Python result object str handler

    Peter Eisentraut <peter_e@gmx.net> — 2013-01-08T21:23:26Z

    On 1/8/13 4:32 AM, Magnus Hagander wrote:
    > How does it work if there are many rows in there? Say the result
    > contains 10,000 rows - will the string contain all of them? If so,
    > might it be worthwhile to cap the number of rows shown and then follow
    > with a "..." or something?
    
    I don't think so.  Any number you pick will be too low for someone.
    Since this would only be executed when explicitly asked for, it's up to
    the user to manage this.  It's analogous to print(long_list) -- you
    wouldn't truncate that.
    
    
    
  5. Re: PL/Python result object str handler

    Magnus Hagander <magnus@hagander.net> — 2013-01-08T21:24:28Z

    On Tue, Jan 8, 2013 at 10:23 PM, Peter Eisentraut <peter_e@gmx.net> wrote:
    > On 1/8/13 4:32 AM, Magnus Hagander wrote:
    >> How does it work if there are many rows in there? Say the result
    >> contains 10,000 rows - will the string contain all of them? If so,
    >> might it be worthwhile to cap the number of rows shown and then follow
    >> with a "..." or something?
    >
    > I don't think so.  Any number you pick will be too low for someone.
    > Since this would only be executed when explicitly asked for, it's up to
    > the user to manage this.  It's analogous to print(long_list) -- you
    > wouldn't truncate that.
    
    Fair enough. I was thinking of a specific example when I wrote that,
    bu I can't recall what it was, and clearly using print or the python
    console would be the most similar scenarios. And they both do it the
    way you suggest. So that's probably the right thing to do.
    
    --
     Magnus Hagander
     Me: http://www.hagander.net/
     Work: http://www.redpill-linpro.com/
    
    
    
  6. Re: PL/Python result object str handler

    Peter Eisentraut <peter_e@gmx.net> — 2013-01-08T21:25:37Z

    On 1/8/13 11:55 AM, Daniele Varrazzo wrote:
    >>> <PLyResult status=5 nrows=2 rows=[{'foo': 1, 'bar': '11'}, {'foo': 2, 'bar': '22'}]>
    > This looks more a repr-style format to me (if you implement repr but
    > not str, the latter will default to the former).
    
    The repr style was the only guideline I found.  There is no guideline
    for how str should look like when it's not repr.  Do you have a better
    suggestion for the output format?
    
    (The reason this is str and not repr is that it doesn't contain other
    information such as the tuple descriptor, so str of two different
    results could easily be the same.)
    
    
    
    
    
  7. Re: PL/Python result object str handler

    Steve Singer <steve@ssinger.info> — 2013-02-02T20:43:24Z

    On 13-01-07 09:58 PM, Peter Eisentraut wrote:
    > By implementing a "str" handler for the result object, it now prints
    > something like
    >
    > <PLyResult status=5 nrows=2 rows=[{'foo': 1, 'bar': '11'}, {'foo': 2, 'bar': '22'}]>
    >
    > Patch attached for review.
    >
    
    Here is a review:
    
    This patch adds a function that pl/python functions can call to convert 
    a query result hash into a string suitable for debug purposes. The use 
    case for this feature is primarily for debugging and logging purposes.   
    I feel that this is useful since a lot of debugging of stored functions 
    is usually done with print/elog style debugging.
    
    There already some discussion on the thread as if the number of rows 
    printed should be limited, the consensus seemed to be 'no' since someone 
    would be unhappy with any limit and printing everything is the same 
    behaviour you get with the standard python print.
    
    I've tested this with python2.6 and 3.1 and it seems to work as described.
    
    I've looked through the code and everything looks fine.
    
    The patch includes no documentation.   Adding a few lines to the 
    "Utility Functions" section of the plpython documentation so people know 
    about this feature would be good.
    
    Other than that I think it is fine to commit.  I am setting this as 
    ready for committer,  I assume you'll commit this yourself and that you 
    can add a paragraph to the docs as you commit it.
    
    
    Steve
    
    
    
    >
    >
    
    
    
    
  8. Re: PL/Python result object str handler

    Peter Eisentraut <peter_e@gmx.net> — 2013-02-03T05:35:09Z

    On Sat, 2013-02-02 at 15:43 -0500, Steve Singer wrote:
    > I've looked through the code and everything looks fine.
    > 
    > The patch includes no documentation.   Adding a few lines to the 
    > "Utility Functions" section of the plpython documentation so people know 
    > about this feature would be good.
    
    Added some documentation and committed.  Thanks.