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

Projection: <field>: <1 or true> and <field>: <0 or false> #377

Merged
merged 11 commits into from
Mar 21, 2022
Merged

Projection: <field>: <1 or true> and <field>: <0 or false> #377

merged 11 commits into from
Mar 21, 2022

Conversation

seeforschauer
Copy link
Contributor

@seeforschauer seeforschauer commented Mar 21, 2022

@AlekSi AlekSi added the trust PRs that can access Actions secrets label Mar 21, 2022
@@ -19,5 +19,15 @@ import "github.com/FerretDB/FerretDB/internal/types"
// ProjectDocuments modifies given documents in places according to the given projection.
func ProjectDocuments(docs []*types.Document, projection *types.Document) error {
// TODO

projectionMap := projection.Map()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

it can be done w/o creation of new variable..

@seeforschauer seeforschauer marked this pull request as draft March 21, 2022 09:00
@seeforschauer seeforschauer marked this pull request as ready for review March 21, 2022 09:04
@@ -100,9 +100,6 @@ func (s *storage) MsgCount(ctx context.Context, msg *wire.OpMsg) (*wire.OpMsg, e
resDocs = append(resDocs, doc)
}

if err = common.SortDocuments(resDocs, sort); err != nil {
return nil, err
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If count has limit (i.e. "no more than", then sort makes sense..)

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'd better won't change it here.

Copy link
Member

Choose a reason for hiding this comment

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

No, sorting is really not required. But that's not for that PR

@AlekSi AlekSi requested a review from w84thesun March 21, 2022 09:30
@@ -99,7 +99,6 @@ func (s *storage) MsgCount(ctx context.Context, msg *wire.OpMsg) (*wire.OpMsg, e

resDocs = append(resDocs, doc)
}

Copy link
Member

Choose a reason for hiding this comment

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

Let's keep a blank line there to separate that block

@@ -100,9 +100,6 @@ func (s *storage) MsgCount(ctx context.Context, msg *wire.OpMsg) (*wire.OpMsg, e
resDocs = append(resDocs, doc)
}

if err = common.SortDocuments(resDocs, sort); err != nil {
return nil, err
}
Copy link
Member

Choose a reason for hiding this comment

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

No, sorting is really not required. But that's not for that PR

@@ -45,7 +45,7 @@ func (s *storage) MsgCount(ctx context.Context, msg *wire.OpMsg) (*wire.OpMsg, e
"let",
}
if err := common.Unimplemented(document, unimplementedFields...); err != nil {
return nil, err
Copy link
Member

Choose a reason for hiding this comment

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

No, Unimplemented returns protocol error that we should return as-is to the client

projectionMap := projection.Map()
for i := 0; i < len(docs); i++ {
for k := range docs[i].Map() {
if _, ok := projectionMap[k]; !ok {
Copy link
Member

Choose a reason for hiding this comment

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

We should check the value too. For example, 0 or false should remove the field.

Or the plan is to do that in a different PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Then I'd add new tests for it too.

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'd rather add tests and add code

Copy link
Member

Choose a reason for hiding this comment

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

In this PR, or in different one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this PR

@seeforschauer seeforschauer marked this pull request as draft March 21, 2022 09:38
@seeforschauer seeforschauer changed the title Projection: TestReadOnlyHandlers/FindProjectionActorsFirstAndLastName/monila Projection: <field>: <1 or true> and <field>: <0 or false> Mar 21, 2022
@seeforschauer seeforschauer changed the title Projection: <field>: <1 or true> and <field>: <0 or false> Projection: <field>: <1 or true> and <field>: <0 or false> Mar 21, 2022
@seeforschauer seeforschauer marked this pull request as ready for review March 21, 2022 10:23
@AlekSi AlekSi self-requested a review March 21, 2022 13:31
internal/handlers/common/projection.go Outdated Show resolved Hide resolved
projectionMap := projection.Map()
for i := 0; i < len(docs); i++ {
for k := range docs[i].Map() {
if k == "_id" {
Copy link
Member

Choose a reason for hiding this comment

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

_id handing is more complicated than that


v, ok := projectionMap[k]
if !ok {
docs[i].Remove(k)
Copy link
Member

Choose a reason for hiding this comment

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

Do we have a dance test for that? It is not clear from documentation how MongoDB behaves there

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no, dance has no tests for it at all,
can it be merged to not to stop Dmitry?

Copy link
Member

Choose a reason for hiding this comment

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

Sure

docs[i].Remove(k)
continue
}
continue
Copy link
Member

Choose a reason for hiding this comment

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

We don't need both those continue statements

internal/handlers/common/projection.go Show resolved Hide resolved
case int32, int64, float32, float64:
if compareScalars(v, int32(0)) == equal {
docs[i].Remove(k)
continue
Copy link
Member

Choose a reason for hiding this comment

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

We don't need that continue

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

@AlekSi AlekSi merged commit 1cae572 into FerretDB:main Mar 21, 2022
@AlekSi AlekSi added the code/chore Code maintenance improvements label Mar 21, 2022
@AlekSi AlekSi added this to the v0.0.7 milestone Mar 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code/chore Code maintenance improvements trust PRs that can access Actions secrets
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants