-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add SELECT DISTINCT queries support #264
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Codecov Report
@@ Coverage Diff @@
## master #264 +/- ##
==========================================
+ Coverage 61.32% 61.53% +0.20%
==========================================
Files 68 71 +3
Lines 6345 6574 +229
==========================================
+ Hits 3891 4045 +154
- Misses 1938 1996 +58
- Partials 516 533 +17
Continue to review full report at Codecov.
|
sql/planner/hash_set.go
Outdated
func (s documentHashSet) generateKey(d document.Document) (uint64, error) { | ||
defer s.hash.Reset() | ||
|
||
err := d.Iterate(func(field string, value document.Value) error { | ||
var buf []byte | ||
buf, err := key.AppendValue(buf, value) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = s.hash.Write(buf) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
buf = buf[0:] | ||
return nil | ||
}) | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
return s.hash.Sum64(), nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function relies on Iterate
function implementation, so if it does not guarantee order of field iteration (for example map
-based) then hash will be incorrect.
For now, Genji does not have such implementation, but it can be added later.
I think document.Value
/document.Document
should have some Hash
function to use it in hash table.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not rely on the implicit behavior of Document implementations as the Document
interface doesn't guarantee the order of iteration.
Instead, we must use the document.Fields() function, which gets the document keys and sorts them, and use GetByField
for each key.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pk()
/literal
tests were failing, when I used documentMask.GetByField
, it tries to get a value from masked document, but literals and functions values are not stored in document.
So, I added IterateInOrder
function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It appears to be a bug, they should be stored in DocumentMask
:
genji> create table foo;
genji> insert into foo(a) values (1), (2), (3);
genji> select pk() from foo;
{
"pk()": 1
}
{
"pk()": 2
}
{
"pk()": 3
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I have some comments after skimming through the changes.
@tdakkota thanks! Can you please mark the discussions as resolved? It looks like only PR author can do that in GitHub… |
c44d95d
to
0a8c1a2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @tdakkota !
Adds new
DISTINCT
keywordUses hash set to make projection result unique.