Skip to content
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

feat: Add group by support for commits #887

Merged
merged 6 commits into from
Oct 12, 2022

Conversation

AndrewSisley
Copy link
Contributor

Relevant issue(s)

Resolves #886

Description

Adds group by support for commits.

@AndrewSisley AndrewSisley added feature New feature or request area/query Related to the query component action/no-benchmark Skips the action that runs the benchmark. labels Oct 11, 2022
@AndrewSisley AndrewSisley added this to the DefraDB v0.4 milestone Oct 11, 2022
@AndrewSisley AndrewSisley requested a review from a team October 11, 2022 20:06
@AndrewSisley AndrewSisley self-assigned this Oct 11, 2022
cid, hasCid := n.docMapper.DocumentMap().FirstOfName(n.currentValue, "cid").(*cid.Cid)
if hasCid {
// dagScanNode yields cids, but we want to yield strings
n.docMapper.DocumentMap().SetFirstOfName(&n.currentValue, "cid", cid.String())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was tempted to do this in the ToMap func (newish equivalent of old renderNode), for all Cids, but decided to keep this local for now. Let me know you you feel.

@AndrewSisley AndrewSisley force-pushed the sisley/feat/I886-commit-groupby branch from 26ef2ce to 3cada1b Compare October 11, 2022 20:09
@codecov
Copy link

codecov bot commented Oct 11, 2022

Codecov Report

Merging #887 (1a6371b) into develop (bdd9b03) will increase coverage by 0.05%.
The diff coverage is 93.65%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #887      +/-   ##
===========================================
+ Coverage    59.75%   59.80%   +0.05%     
===========================================
  Files          157      157              
  Lines        17420    17452      +32     
===========================================
+ Hits         10409    10438      +29     
- Misses        6069     6071       +2     
- Partials       942      943       +1     
Impacted Files Coverage Δ
query/graphql/planner/planner.go 77.35% <81.81%> (-0.39%) ⬇️
query/graphql/mapper/mapper.go 85.20% <100.00%> (-0.04%) ⬇️
query/graphql/parser/commit.go 75.58% <100.00%> (+3.21%) ⬆️
query/graphql/planner/commit.go 91.52% <100.00%> (+0.53%) ⬆️
query/graphql/planner/dagscan.go 75.49% <100.00%> (+0.12%) ⬆️
query/graphql/planner/multi.go 76.25% <100.00%> (ø)
query/graphql/schema/generate.go 81.60% <100.00%> (+0.15%) ⬆️

Comment on lines 126 to 137
fields := make([]string, 0)
for _, v := range obj.Values {
fields = append(fields, v.GetValue().(string))
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick(non-blocking): Since we know the size, can allocate upfront and just reassign, rather than append. Non-blocking because is not a hot path.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also think the size should be allocated according to the length of obj.Values. Specially since the effort was made to use make.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was copy-pasted, and authored according to the original author's taste at the time. really doesn't matter here (RE performance or readability) but I'll change it if I'm about

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it as I had to rebase anyway (got its own commit, the message highlights the reasoning behind my choice)

Copy link
Collaborator

@fredcarle fredcarle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I encourage the change suggested by Shahzad before merging.

The non-deterministic mapping complicates the group-by code when adding support for commits as children and parent mappings will not always match.
Was previously declared and unset and unused
Was sometimes string, sometimes cid and sometimes *cid.  Now it is always *cid
Declaring it suggests importance, and wastes developer attention on irrelevent stuff
@AndrewSisley AndrewSisley force-pushed the sisley/feat/I886-commit-groupby branch from 3cada1b to 1a6371b Compare October 12, 2022 18:56
@@ -131,7 +131,7 @@ func parseCommitSelect(field *ast.Field) (*CommitSelect, error) {
commit.Depth = client.Some(depth)
} else if prop == parserTypes.GroupByClause {
obj := argument.Value.(*ast.ListValue)
fields := make([]string, 0)
fields := []string{}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: That's a weird change lol. Why not set the length to len(obj.Values) if you decided to make a change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reason noted in the commit message

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just saw. I don't always think of looking at the commit message.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tend to put a fair amount of info in those when needed (and when I am not too lazy) - I see this kind of thing as a major part of the (line 1+) commit message's reason-to-be. It is a very good place to note down the reasons for making changes IMO.

@AndrewSisley AndrewSisley merged commit 8f57a7f into develop Oct 12, 2022
@AndrewSisley AndrewSisley deleted the sisley/feat/I886-commit-groupby branch October 12, 2022 19:08
shahzadlone pushed a commit to shahzadlone/defradb that referenced this pull request Feb 23, 2024
* Simplify walkAndFindPlanType

* Make commit field mapping deterministic

The non-deterministic mapping complicates the group-by code when adding support for commits as children and parent mappings will not always match.

* Set commit node docMapper

Was previously declared and unset and unused

* Return consistent type from dagscan

Was sometimes string, sometimes cid and sometimes *cid.  Now it is always *cid

* Add group by support for commits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action/no-benchmark Skips the action that runs the benchmark. area/query Related to the query component feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Commits: Add groupBy support to commits
3 participants