BQL for non-transactions?

107 views
Skip to the first unread message

Scott

unread,
20 May 2023, 1:10:08 pm20/5/23
to Beancount
Hi,

with the recent fava dashboards plugin, I now have a use case where I'm interested in using BQL to find note directives.  Is this possible?  Looking through the documentation, I suspect it is not, but I may be missing something.  If it's not possible, I might try to take a stab at implementing it, so any useful thoughts/pointers on the best approach would be appreciated.

 -S

Martin Blais

unread,
20 May 2023, 4:57:58 pm20/5/23
to bean...@googlegroups.com
I think not. 
A long long while ago I had an idea for the revamp of the SQL client I thought a good mapping would be for each of the postings and directive types: transactions, balance, note, etc. to be individual tables with their own dedicated set of columns but I don't think this was implemented.

(Note that you could build a little Python script and use petl to achieve this in ~20LOC or something.)


--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/23af24bb-ce74-40b2-863b-6093844da0a8n%40googlegroups.com.

Stefano Zacchiroli

unread,
20 May 2023, 5:31:29 pm20/5/23
to bean...@googlegroups.com
On Sat, May 20, 2023 at 04:57:44PM -0400, Martin Blais wrote:
> (Note that you could build a little Python script and use petl to achieve
> this in ~20LOC or something.)

Is there an existing mapping from Beancount data to Petl that I'm
missing?

I'm aware of Petl usage for importing data into Beancount, which makes a
lot of sense, because you usually have tabular data before ingesting
into Beancount. But I'm not aware of any bridge between Beancount
(presumably and more specifically: the tabular data model on which BQL
evaluate queries) and Petl. Would love to hear about it.

Cheers
--
Stefano Zacchiroli . za...@upsilon.cc . https://upsilon.cc/zack _. ^ ._
Full professor of Computer Science o o o \/|V|\/
Télécom Paris, Polytechnic Institute of Paris o o o </> <\>
Co-founder & CTO Software Heritage o o o o /\|^|/\
https://twitter.com/zacchiro . https://mastodon.xyz/@zacchiro '" V "'

Martin Blais

unread,
20 May 2023, 5:50:34 pm20/5/23
to bean...@googlegroups.com
There isn't one but if needed I can probably make you one in short order.

--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.

Martin Blais

unread,
20 May 2023, 6:02:45 pm20/5/23
to Martin Blais, bean...@googlegroups.com
Here, expand as desired:


#!/usr/bin/env python3
"""Example processing postings using petl.
"""

from beancount import loader
from beancount.core import data

import argparse
import itertools
import petl

petl.config.look_style = "minimal"
petl.config.failonerror = True


HEADER = ["txn", "posting", "date", "account", "units", "cost"]


def rows(entries):
    for txn in data.filter_txns(entries):
        for posting in txn.postings:
            yield (txn, posting, txn.date, posting.account, posting.units, posting.cost)


def main():
    parser = argparse.ArgumentParser(description=__doc__.strip())
    parser.add_argument("filename", help="Ledger filename")
    args = parser.parse_args()

    entries, errors, options_map = loader.load_file(args.filename)
    table = petl.wrap(itertools.chain([HEADER], rows(entries)))
    print(table.cut(["date", "account", "units"]).lookallstr())


if __name__ == "__main__":
    main()



Stefano Zacchiroli

unread,
21 May 2023, 2:52:11 am21/5/23
to bean...@googlegroups.com
On Sat, May 20, 2023 at 06:02:30PM -0400, Martin Blais wrote:
> Here, expand as desired:

Thanks!

Might be worth a (small) place in the Beancount API.

Daniele Nicolodi

unread,
2 June 2023, 5:50:55 am2/6/23
to bean...@googlegroups.com
bean-query allows to run query only on transactions and postings.

In the beanquery project spun off from beancount a while ago, I have
been working on allowing to query other ledger objects. This required
some important changes to beanquery, but most of the foundation work has
been done. A table definition for note directives is not included yet,
but it is not difficult to add. For example
https://github.com/beancount/beanquery/pull/119 adds support for a
``prices`` column.

I don't know whether Fava can use beanquery.

Unfortunately, I have very limited time to work on this.

Cheers,
Dan

Martin Blais

unread,
2 June 2023, 9:28:34 am2/6/23
to bean...@googlegroups.com
Eventually will add some helpers to generate rows and some aggregators.


--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages