sort order across multiple files?

65 views
Skip to first unread message

scha...@gmail.com

unread,
Aug 27, 2019, 3:16:17 AM8/27/19
to Beancount
Hi,

I've recently migrated to Beancount from Ledger. I'm really happy with it so far. :)

One issue I've had is around transaction ordering across files. (To be clear, this is not at all a criticism of Beancount relative to Ledger; the plugin I'm trying to write wouldn't be possible in Ledger for a dozen reasons.)

I mostly keep one file per "physical" account (e.g. one file for my Vanguard 401k). I also have a "budget" file that keeps transactions I use for envelope budgeting. Some of the budget transactions are logically linked with a debit to my checking account; in effect, money is divided up the instant it arrives.

I'm trying to implement a plugin that ensures that my various budget accounts never drop below zero. However, if I'm reading the code correctly, transactions are sorted based on their date, type, and line number -- but not based on filename, and not based on anything that a plugin is supposed to be able to control.

My questions are:

1. Is there a reason for this particular sorting order? It seems odd that line number would be used without filename -- it means that the order of two transactions could be changed by adding a lot of whitespace to one file, or by adding/removing metadata tags. (I tested this out, and confirmed that whitespace does have this effect.)

2. More generally, are there any recommended patterns for imposing partial orders on transactions in different files? I know that I could put everything in one file, but I'd rather not; it's much easier for me to read and write (and make bulk changes to) my files if they're split up as they are now.

Note that addressing #1 (e.g. by changing the sort key to include filename before lineno) would not fully address my use case, since I want to interleave transactions between different files.

Thanks!
~ aleksandra (pronouns: she/her)

Martin Blais

unread,
Aug 27, 2019, 9:17:12 AM8/27/19
to Beancount
On Tue, Aug 27, 2019 at 3:16 AM <scha...@gmail.com> wrote:
Hi,

I've recently migrated to Beancount from Ledger. I'm really happy with it so far. :)

One issue I've had is around transaction ordering across files. (To be clear, this is not at all a criticism of Beancount relative to Ledger; the plugin I'm trying to write wouldn't be possible in Ledger for a dozen reasons.)

I mostly keep one file per "physical" account (e.g. one file for my Vanguard 401k). I also have a "budget" file that keeps transactions I use for envelope budgeting. Some of the budget transactions are logically linked with a debit to my checking account; in effect, money is divided up the instant it arrives.

I'm trying to implement a plugin that ensures that my various budget accounts never drop below zero. However, if I'm reading the code correctly, transactions are sorted based on their date, type, and line number -- but not based on filename, and not based on anything that a plugin is supposed to be able to control.

My questions are:

1. Is there a reason for this particular sorting order? It seems odd that line number would be used without filename -- it means that the order of two transactions could be changed by adding a lot of whitespace to one file, or by adding/removing metadata tags. (I tested this out, and confirmed that whitespace does have this effect.)

Hmm, I think it's an oversight. Sorting should be stable. I should add the filename to the sort key.


2. More generally, are there any recommended patterns for imposing partial orders on transactions in different files? I know that I could put everything in one file, but I'd rather not; it's much easier for me to read and write (and make bulk changes to) my files if they're split up as they are now.

I think the absolute filename should disambiguate it enouhg.

 

Note that addressing #1 (e.g. by changing the sort key to include filename before lineno) would not fully address my use case, since I want to interleave transactions between different files.

I don't understand this. They would be sorted by date, but within each date, sorted by file, and then by line number.
(You're not supposed to rely on ordering within a day, Beancount does not provide guarantees on ordering that way, just stable ordering.)
 


 

Thanks!
~ aleksandra (pronouns: she/her)

--
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/2c8b10d2-12e6-4170-829b-de5a0bb269c8%40googlegroups.com.

Aleksandra Culver

unread,
Aug 27, 2019, 6:30:06 PM8/27/19
to bean...@googlegroups.com


On Tue, Aug 27, 2019, at 06:17, Martin Blais wrote:
On Tue, Aug 27, 2019 at 3:16 AM <scha...@gmail.com> wrote:
Hi,

I've recently migrated to Beancount from Ledger. I'm really happy with it so far. :)

One issue I've had is around transaction ordering across files. (To be clear, this is not at all a criticism of Beancount relative to Ledger; the plugin I'm trying to write wouldn't be possible in Ledger for a dozen reasons.)

I mostly keep one file per "physical" account (e.g. one file for my Vanguard 401k). I also have a "budget" file that keeps transactions I use for envelope budgeting. Some of the budget transactions are logically linked with a debit to my checking account; in effect, money is divided up the instant it arrives.

I'm trying to implement a plugin that ensures that my various budget accounts never drop below zero. However, if I'm reading the code correctly, transactions are sorted based on their date, type, and line number -- but not based on filename, and not based on anything that a plugin is supposed to be able to control.

My questions are:

1. Is there a reason for this particular sorting order? It seems odd that line number would be used without filename -- it means that the order of two transactions could be changed by adding a lot of whitespace to one file, or by adding/removing metadata tags. (I tested this out, and confirmed that whitespace does have this effect.)

Hmm, I think it's an oversight. Sorting should be stable. I should add the filename to the sort key.


2. More generally, are there any recommended patterns for imposing partial orders on transactions in different files? I know that I could put everything in one file, but I'd rather not; it's much easier for me to read and write (and make bulk changes to) my files if they're split up as they are now.

I think the absolute filename should disambiguate it enouhg.

 


Note that addressing #1 (e.g. by changing the sort key to include filename before lineno) would not fully address my use case, since I want to interleave transactions between different files.

I don't understand this. They would be sorted by date, but within each date, sorted by file, and then by line number.
(You're not supposed to rely on ordering within a day, Beancount does not provide guarantees on ordering that way, just stable ordering.)

I guess I was too tired last night to think about this properly. :) I updated my plugin so that it only checks balances at day boundaries, and now it works perfectly. Thanks for your help! :)

 


 

Thanks!
~ aleksandra (pronouns: she/her)


--
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.


--
You received this message because you are subscribed to a topic in the Google Groups "Beancount" group.
To unsubscribe from this group and all its topics, send an email to beancount+...@googlegroups.com.

--
  Aleksandra Culver (pronouns: she/her)

Martin Blais

unread,
Aug 27, 2019, 10:50:33 PM8/27/19
to Beancount
On Tue, Aug 27, 2019 at 6:30 PM Aleksandra Culver <m...@aleksculver.com> wrote:


On Tue, Aug 27, 2019, at 06:17, Martin Blais wrote:
On Tue, Aug 27, 2019 at 3:16 AM <scha...@gmail.com> wrote:
Hi,

I've recently migrated to Beancount from Ledger. I'm really happy with it so far. :)

One issue I've had is around transaction ordering across files. (To be clear, this is not at all a criticism of Beancount relative to Ledger; the plugin I'm trying to write wouldn't be possible in Ledger for a dozen reasons.)

I mostly keep one file per "physical" account (e.g. one file for my Vanguard 401k). I also have a "budget" file that keeps transactions I use for envelope budgeting. Some of the budget transactions are logically linked with a debit to my checking account; in effect, money is divided up the instant it arrives.

I'm trying to implement a plugin that ensures that my various budget accounts never drop below zero. However, if I'm reading the code correctly, transactions are sorted based on their date, type, and line number -- but not based on filename, and not based on anything that a plugin is supposed to be able to control.

My questions are:

1. Is there a reason for this particular sorting order? It seems odd that line number would be used without filename -- it means that the order of two transactions could be changed by adding a lot of whitespace to one file, or by adding/removing metadata tags. (I tested this out, and confirmed that whitespace does have this effect.)

Hmm, I think it's an oversight. Sorting should be stable. I should add the filename to the sort key.


2. More generally, are there any recommended patterns for imposing partial orders on transactions in different files? I know that I could put everything in one file, but I'd rather not; it's much easier for me to read and write (and make bulk changes to) my files if they're split up as they are now.

I think the absolute filename should disambiguate it enouhg.

 


Note that addressing #1 (e.g. by changing the sort key to include filename before lineno) would not fully address my use case, since I want to interleave transactions between different files.

I don't understand this. They would be sorted by date, but within each date, sorted by file, and then by line number.
(You're not supposed to rely on ordering within a day, Beancount does not provide guarantees on ordering that way, just stable ordering.)

I guess I was too tired last night to think about this properly. :) I updated my plugin so that it only checks balances at day boundaries, and now it works perfectly. Thanks for your help! :)

Do you still need me to insert the filename in the sort key?
(I think I should do that regardless, to ensure stable sort.) 
Let me know,

Aleksandra Culver

unread,
Aug 28, 2019, 1:39:15 AM8/28/19
to bean...@googlegroups.com
It no longer makes a difference for my plugin, but I agree it's a good idea anyway. :)



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