Issue 21 in linqbridge: GroupBy fails on null keys

0 views
Skip to first unread message

linqb...@googlecode.com

unread,
Apr 29, 2011, 5:30:01 AM4/29/11
to linqbridg...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 21 by ilya.ind...@gmail.com: GroupBy fails on null keys
http://code.google.com/p/linqbridge/issues/detail?id=21

The following test fails with LINQBridge and passes with System.Core:

[Test]
public void GroupBy_NullKey()
{
var arr = new[] { "notnull", null };

var groups = arr.GroupBy(s => s);
foreach (var @group in groups)
{
Console.WriteLine(@group.Key ?? "[null]");
}
}

linqb...@googlecode.com

unread,
Apr 29, 2011, 5:34:03 AM4/29/11
to linqbridg...@googlegroups.com

Comment #1 on issue 21 by ilya.ind...@gmail.com: GroupBy fails on null keys
http://code.google.com/p/linqbridge/issues/detail?id=21

Proposed solution:

Use as a backing store for Lookup<TKey, TElement> not Dictionary<TKey, ...>
but Dictionary<Wrapped<TKey>, ...>, where Wrapped<TKey> is some wrapper
structure that would never be null.

linqb...@googlecode.com

unread,
Apr 29, 2011, 6:30:38 AM4/29/11
to linqbridg...@googlegroups.com

Comment #2 on issue 21 by ilya.ind...@gmail.com: GroupBy fails on null keys
http://code.google.com/p/linqbridge/issues/detail?id=21

Here is a proof-of-concept implementation of this Wrapped<> structure and
it's equality comparer.


Attachments:
Wrapped.cs 1.7 KB

linqb...@googlecode.com

unread,
Apr 30, 2011, 9:47:35 AM4/30/11
to linqbridg...@googlegroups.com
Updates:
Status: Accepted
Labels: Milestone-Release1.3

Comment #3 on issue 21 by azizatif: GroupBy fails on null keys
http://code.google.com/p/linqbridge/issues/detail?id=21

(No comment was entered for this change.)

linqb...@googlecode.com

unread,
Apr 30, 2011, 10:11:00 AM4/30/11
to linqbridg...@googlegroups.com
Updates:
Status: Started
Owner: azizatif

Comment #4 on issue 21 by azizatif: GroupBy fails on null keys

linqb...@googlecode.com

unread,
Apr 30, 2011, 12:24:10 PM4/30/11
to linqbridg...@googlegroups.com
Updates:
Status: Fixed

Comment #5 on issue 21 by azizatif: GroupBy fails on null keys
http://code.google.com/p/linqbridge/issues/detail?id=21

Fixed in changeset c74eb37b988b[1]

[1]
http://code.google.com/p/linqbridge/source/detail?r=c74eb37b988be35a8a62b703218414dc889b5372

linqb...@googlecode.com

unread,
Apr 30, 2011, 3:19:13 PM4/30/11
to linqbridg...@googlegroups.com

Comment #6 on issue 21 by ilya.ind...@gmail.com: GroupBy fails on null keys
http://code.google.com/p/linqbridge/issues/detail?id=21

The Count property of the Lookup is now broken.
What do you have against wrapping dictionary key in the non-nullable
structure? This seems to be more "straight solution".

linqb...@googlecode.com

unread,
Apr 30, 2011, 3:41:29 PM4/30/11
to linqbridg...@googlegroups.com

Comment #7 on issue 21 by ilya.ind...@gmail.com: GroupBy fails on null keys
http://code.google.com/p/linqbridge/issues/detail?id=21

Please, take a look at my solution:
http://code.google.com/r/ilyaindustry-linqbridge-issue21/source/detail?r=00f4036bafdf260f69e4910006c8c62b931ea18d

PS: Thanks for migrating to mercurial.

linqb...@googlecode.com

unread,
May 1, 2011, 6:12:40 AM5/1/11
to linqbridg...@googlegroups.com

Comment #8 on issue 21 by azizatif: GroupBy fails on null keys
http://code.google.com/p/linqbridge/issues/detail?id=21

> The Count property of the Lookup is now broken.

Good catch.

> What do you have against wrapping dictionary key in
> the non-nullable structure

Nothing against it. I was trying to solve three problems (order keys for
GroupBy, null keys and move to Hg) at the same time. I have merged your
version (thanks) and will be adding back key order for GroupBy; it is
required as per the documentation:

“The IGrouping(TKey, TElement) objects are yielded in an order based on the
order of the elements in source that produced the first key of each
IGrouping(TKey, TElement). Elements in a grouping are yielded in the order
they appear in source.”

GroupBy internally relies on ToLookup.


Reply all
Reply to author
Forward
0 new messages