Implement mlr uniq -x (#1457)

* mlr uniq -x

* unit-test cases

* make dev
This commit is contained in:
John Kerl 2023-12-23 16:20:11 -05:00 committed by GitHub
parent f4cf166358
commit 0e3a54ed68
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
46 changed files with 238 additions and 35 deletions

View file

@ -96,6 +96,7 @@ Same as uniq -c.
Options:
-f {a,b,c} Field names for distinct count.
-x {a,b,c} Field names to exclude for distinct count: use each record's others instead.
-n Show only the number of distinct values. Not compatible with -u.
-o {name} Field name for output count. Default "count".
Ignored with -u.
@ -1320,6 +1321,7 @@ count-distinct. For uniq, -f is a synonym for -g.
Options:
-g {d,e,f} Group-by-field names for uniq counts.
-x {a,b,c} Field names to exclude for uniq: use each record's others instead.
-c Show repeat counts in addition to unique values.
-n Show only the number of distinct values.
-o {name} Field name for output count. Default "count".

View file

@ -0,0 +1 @@
mlr --dkvp uniq -c -x flag,k,index,quantity,rate test/input/example-with-changed-keys.dkvp

View file

@ -0,0 +1,7 @@
color=yellow,shape=triangle,count=1
color=red,shape=square,count=2
weird=red,shape=circle,count=1
color=purple,shape=triangle,count=2
color=red,shape=square,odd=77.19910000,count=1
color=yellow,shape=circle,count=2
color=purple,shape=square,count=1

View file

@ -0,0 +1 @@
mlr --dkvp uniq -c -x flag,k,index,quantity,rate test/input/example.dkvp

View file

View file

@ -0,0 +1,6 @@
color=yellow,shape=triangle,count=1
color=red,shape=square,count=3
color=red,shape=circle,count=1
color=purple,shape=triangle,count=2
color=yellow,shape=circle,count=2
color=purple,shape=square,count=1

View file

@ -0,0 +1 @@
mlr --dkvp uniq -c -x flag,k,index,quantity,rate test/input/example-with-extra-keys.dkvp

View file

@ -0,0 +1,7 @@
color=yellow,shape=triangle,count=1
color=red,shape=square,count=3
color=red,shape=circle,count=1
color=purple,shape=triangle,extra=here,count=1
color=purple,shape=triangle,count=1
color=yellow,shape=circle,count=2
color=purple,shape=square,count=1

View file

@ -0,0 +1 @@
mlr --dkvp uniq -c -x flag,k,index,quantity,rate test/input/example-with-missing-keys.dkvp

View file

@ -0,0 +1,6 @@
color=yellow,shape=triangle,count=1
color=red,shape=square,count=3
shape=circle,count=1
color=purple,shape=triangle,count=2
color=yellow,shape=circle,count=2
color=purple,shape=square,count=1

View file

@ -0,0 +1 @@
mlr --dkvp uniq -x flag,k,index,quantity,rate test/input/example-with-changed-keys.dkvp

View file

@ -0,0 +1,7 @@
color=yellow,shape=triangle
color=red,shape=square
weird=red,shape=circle
color=purple,shape=triangle
color=red,shape=square,odd=77.19910000
color=yellow,shape=circle
color=purple,shape=square

View file

@ -0,0 +1 @@
mlr --dkvp uniq -x flag,k,index,quantity,rate test/input/example.dkvp

View file

View file

@ -0,0 +1,6 @@
color=yellow,shape=triangle
color=red,shape=square
color=red,shape=circle
color=purple,shape=triangle
color=yellow,shape=circle
color=purple,shape=square

View file

@ -0,0 +1 @@
mlr --dkvp uniq -x flag,k,index,quantity,rate test/input/example-with-extra-keys.dkvp

View file

View file

@ -0,0 +1,7 @@
color=yellow,shape=triangle
color=red,shape=square
color=red,shape=circle
color=purple,shape=triangle,extra=here
color=purple,shape=triangle
color=yellow,shape=circle
color=purple,shape=square

View file

@ -0,0 +1 @@
mlr --dkvp uniq -x flag,k,index,quantity,rate test/input/example-with-missing-keys.dkvp

View file

View file

@ -0,0 +1,6 @@
color=yellow,shape=triangle
color=red,shape=square
shape=circle
color=purple,shape=triangle
color=yellow,shape=circle
color=purple,shape=square

View file

@ -0,0 +1,10 @@
color=yellow,shape=triangle,flag=true,k=1,index=11,quantity=43.6498,rate=9.8870
color=red,shape=square,flag=true,k=2,index=15,quantity=79.2778,rate=0.0130
weird=red,shape=circle,flag=true,k=3,index=16,quantity=13.8103,rate=2.9010
color=red,shape=square,flag=false,k=4,index=48,quantity=77.5542,rate=7.4670
color=purple,shape=triangle,flag=false,k=5,index=51,quantity=81.2290,rate=8.5910
color=red,shape=square,flag=false,k=6,index=64,odd=77.1991,rate=9.5310
color=purple,shape=triangle,flag=false,k=7,index=65,quantity=80.1405,rate=5.8240
color=yellow,shape=circle,flag=true,k=8,index=73,quantity=63.9785,rate=4.2370
color=yellow,shape=circle,flag=true,k=9,index=87,quantity=63.5058,rate=8.3350
color=purple,shape=square,flag=false,k=10,index=91,quantity=72.3735,rate=8.2430

View file

@ -0,0 +1,10 @@
color=yellow,shape=triangle,flag=true,k=1,index=11,quantity=43.6498,rate=9.8870
color=red,shape=square,flag=true,k=2,index=15,quantity=79.2778,rate=0.0130
color=red,shape=circle,flag=true,k=3,index=16,quantity=13.8103,rate=2.9010
color=red,shape=square,flag=false,k=4,index=48,quantity=77.5542,rate=7.4670
color=purple,shape=triangle,flag=false,k=5,index=51,quantity=81.2290,rate=8.5910,extra=here
color=red,shape=square,flag=false,k=6,index=64,quantity=77.1991,rate=9.5310
color=purple,shape=triangle,flag=false,k=7,index=65,quantity=80.1405,rate=5.8240
color=yellow,shape=circle,flag=true,k=8,index=73,quantity=63.9785,rate=4.2370
color=yellow,shape=circle,flag=true,k=9,index=87,quantity=63.5058,rate=8.3350
color=purple,shape=square,flag=false,k=10,index=91,quantity=72.3735,rate=8.2430

View file

@ -0,0 +1,10 @@
color=yellow,shape=triangle,flag=true,k=1,index=11,quantity=43.6498,rate=9.8870
color=red,shape=square,flag=true,k=2,index=15,quantity=79.2778,rate=0.0130
shape=circle,flag=true,k=3,index=16,quantity=13.8103,rate=2.9010
color=red,shape=square,flag=false,k=4,index=48,quantity=77.5542,rate=7.4670
color=purple,shape=triangle,flag=false,index=51,quantity=81.2290,rate=8.5910
color=red,shape=square,flag=false,k=6,index=64,quantity=77.1991,rate=9.5310
color=purple,shape=triangle,flag=false,k=7,index=65,quantity=80.1405,rate=5.8240
color=yellow,shape=circle,flag=true,k=8,index=73,quantity=63.9785,rate=4.2370
color=yellow,shape=circle,flag=true,k=9,index=87,quantity=63.5058,rate=8.3350
color=purple,shape=square,flag=false,k=10,index=91,quantity=72.3735,rate=8.2430

10
test/input/example.dkvp Normal file
View file

@ -0,0 +1,10 @@
color=yellow,shape=triangle,flag=true,k=1,index=11,quantity=43.6498,rate=9.8870
color=red,shape=square,flag=true,k=2,index=15,quantity=79.2778,rate=0.0130
color=red,shape=circle,flag=true,k=3,index=16,quantity=13.8103,rate=2.9010
color=red,shape=square,flag=false,k=4,index=48,quantity=77.5542,rate=7.4670
color=purple,shape=triangle,flag=false,k=5,index=51,quantity=81.2290,rate=8.5910
color=red,shape=square,flag=false,k=6,index=64,quantity=77.1991,rate=9.5310
color=purple,shape=triangle,flag=false,k=7,index=65,quantity=80.1405,rate=5.8240
color=yellow,shape=circle,flag=true,k=8,index=73,quantity=63.9785,rate=4.2370
color=yellow,shape=circle,flag=true,k=9,index=87,quantity=63.5058,rate=8.3350
color=purple,shape=square,flag=false,k=10,index=91,quantity=72.3735,rate=8.2430