hledger icon indicating copy to clipboard operation
hledger copied to clipboard

Original use of --pivot got broken in 9501b43

Open maralorn opened this issue 7 years ago • 9 comments

Hey,

I am the original contributor of the --pivot option. I kinda promised to write more doku or something for it, but never did. Sorry, about that.

But after I switched to a new system, I noticed, that the --pivot option got broken in it’s initial intended use. This completely breaks my workflow.

Let me explain what happened. Let's assume the following ledger:

2018-01-29 test
	account:a  -5.00 EUR
	account:b   5.00 EUR
	; tag: value

using hledger --pivot tag print I get

2018/01/29 test
                -5.00 EUR
    value        5.00 EUR
    ; tag: value

which is not even a valid ledger file. The original behaviour was

2018/01/29 test
    account:a            -5.00 EUR
    tag:value              5.00 EUR
    ; tag: value

The culprit is commit 9501b43 in which this function was refactored to fullfill other feature requests, especially #608. The code even says now:

Replace this posting's account name with the value of the given field or tag, if any, otherwise the empty string.

So on the one hand the set account name changed from TAGNAME:TAGVALUE to just TAGVALUE with this commit. On the other hand now the account name gets set as empty, when the tag is not found. Both changes to not work with my usecase.

I see, that other users have different needs. But I am of course not very happy about this breaking behaviour change. Also the tests regarding this feature look very strange now. The question would be, how to procede. Add a different pivot option with the old semantics or make this pivot option more configurable?

Regards, maralorn

maralorn avatar Jan 29 '18 19:01 maralorn

I didn't like the old behaviour of showing the unpivoted account when the tag is absent. It felt confusing to "half-pivot". Showing nothing in that case made sense to me in a balance report. But you're right, it's no good for print. Let's mock up some alternative output.

simonmichael avatar Jan 29 '18 20:01 simonmichael

PS sorry for breaking your workflow. Tell us more about it if you like.

simonmichael avatar Jan 29 '18 20:01 simonmichael

I was concerned about old behaviour because it basically produce result that might be confusing when tag name and value may form string that matches account name. I prefer to have clear separate namespaces (account:.... and tag:... or tag:... and untagged). Though I don't like empty string either and thus I don't really like removing tag name prefix. Now there is no clash with accounts but there is a clash between postings that have tag with empty value and records without tag that gets also empty as an account name. I don't rely on any of that behaviours. Just make two requests hledger bal --pivot reimburse tag:reimburse and hledger bal not:tag:reimburse if you want to know distribution and total of untagged postings.

I also interested in a use case when you want to use it for print command for non-debugging purposes.

ony avatar Jan 29 '18 20:01 ony

How about "-". Suggests "missing", language neutral, syntactically valid, unlikely to clash with a real account.

2018/01/29 test
    -           -5.00 EUR
    value        5.00 EUR
    ; tag: value

simonmichael avatar Jan 29 '18 20:01 simonmichael

My workflow is to create (with a frequently run script) a new ledger file (I call cache) with the --pivot applied which I can then process further with any other compatible tool. But the bug made me think about that process and I think I can manage with the current behavior. I also vote for using "-" that is definitely better than "".

maralorn avatar Feb 03 '18 18:02 maralorn

i just ran into this the other day while doing a complex query like hledger print --pivot sometag ... | hledger bal ... . as above, the issue is that print --pivot sometag can output a syntactically invalid journal.

@simonmichael would you be open to a PR implementing "use - for blanks in pivoted print"? guess it could also be configurable, something like --pivot-blanks='-'.

lubieowoce avatar Jun 30 '21 03:06 lubieowoce

@lubieowoce, great! Please go ahead. I wouldn't bother adding an option until we find it's really needed.

simonmichael avatar Jun 30 '21 04:06 simonmichael

This bug is still open as originally reported. @lubieowoce, might you still be interested in working on it ?

simonmichael avatar Jun 21 '23 07:06 simonmichael

hi, unfortunately i don't think I can help here. i haven't done any real Haskell in quite a while and I'm not using hledger anymore (not bc of the bug tho!)

lubieowoce avatar Jun 21 '23 10:06 lubieowoce