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

Support count and storageStats fields in $collStats aggregation pipeline stage #2338

Merged
merged 44 commits into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
8d430a3
init
chilagrow Mar 31, 2023
cc3be43
return simply information
chilagrow Mar 31, 2023
ff2d008
wip
chilagrow Mar 31, 2023
733122e
impl count field
chilagrow Mar 31, 2023
80489e5
check count
chilagrow Mar 31, 2023
2ba2716
refactor
chilagrow Mar 31, 2023
fc65613
comment
chilagrow Mar 31, 2023
e0f8561
Merge branch 'main' into issue-1416-collstats
chilagrow Mar 31, 2023
3c8ee11
add to do
chilagrow Mar 31, 2023
810988c
Merge branch 'issue-1416-collstats' of github.com:chilagrow/FerretDB …
chilagrow Mar 31, 2023
34f3cc4
lint
chilagrow Mar 31, 2023
70514f6
add comment
chilagrow Mar 31, 2023
5788b79
merge
rumyantseva Mar 31, 2023
1da617a
wip
rumyantseva Mar 31, 2023
588082f
wip
rumyantseva Apr 1, 2023
2944e91
wip
rumyantseva Apr 1, 2023
c984025
wip
rumyantseva Apr 1, 2023
b3164c2
wip
rumyantseva Apr 2, 2023
7970ad1
Merge branch 'main' into altenative-stats-aggegation
Apr 2, 2023
ab1e6ad
wip
rumyantseva Apr 2, 2023
6245400
wip
rumyantseva Apr 2, 2023
5c95197
wip
rumyantseva Apr 2, 2023
8e50034
wip
rumyantseva Apr 2, 2023
ad80b73
Support for Tigris
rumyantseva Apr 2, 2023
4a252cd
wip
rumyantseva Apr 2, 2023
89bcd9a
Support for scale
rumyantseva Apr 3, 2023
a3ede8c
wip
rumyantseva Apr 3, 2023
8a8e3a5
wip
rumyantseva Apr 3, 2023
6356c36
wip
rumyantseva Apr 3, 2023
bf556fb
wip
rumyantseva Apr 3, 2023
eb7156e
wip
rumyantseva Apr 3, 2023
a853ee0
wip
rumyantseva Apr 3, 2023
d23de0e
wip
rumyantseva Apr 3, 2023
e0b712f
wip
rumyantseva Apr 3, 2023
67000bb
wip
rumyantseva Apr 3, 2023
4d6879a
Merge branch 'main' into altenative-stats-aggegation
Apr 3, 2023
5d1bf66
Merge branch 'main' into altenative-stats-aggegation
Apr 3, 2023
930fec8
wip
rumyantseva Apr 3, 2023
1a98b42
Merge branch 'altenative-stats-aggegation' of https://github.com/rumy…
rumyantseva Apr 3, 2023
b5f57e9
wip
rumyantseva Apr 3, 2023
823068a
wip
rumyantseva Apr 3, 2023
4ac1b72
wip
rumyantseva Apr 3, 2023
95ea7f0
having the same type (didn't really help)
rumyantseva Apr 3, 2023
c264984
merge
rumyantseva Apr 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
wip
  • Loading branch information
rumyantseva committed Apr 3, 2023
commit d23de0e77ac65f1701b2b725d2f058c04e827640
2 changes: 0 additions & 2 deletions integration/commands_administration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -639,8 +639,6 @@ func TestCommandsAdministrationCollStatsWithScale(t *testing.T) {
func TestCommandsAdministrationDataSize(t *testing.T) {
t.Parallel()

// FIXME !!!

t.Run("Existing", func(t *testing.T) {
t.Parallel()
ctx, collection := setup.Setup(t, shareddata.DocumentsStrings)
Expand Down
14 changes: 7 additions & 7 deletions internal/handlers/common/aggregations/collstats.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
"github.com/FerretDB/FerretDB/internal/util/must"
)

// collStats represents $collStats stage.
type collStats struct {
// collStatsStage represents $collStats stage.
type collStatsStage struct {
storageStats *storageStats
count bool
latencyStats bool
Expand All @@ -48,7 +48,7 @@ func newCollStats(stage *types.Document) (Stage, error) {
)
}

var cs collStats
var cs collStatsStage

// TODO Return error on invalid type of count: https://github.com/FerretDB/FerretDB/issues/2336
cs.count = fields.Has("count")
Expand Down Expand Up @@ -79,10 +79,10 @@ func newCollStats(stage *types.Document) (Stage, error) {
//
// Processing consists of modification of the input document, so it contains all the necessary fields
// and the data is modified according to the given request.
func (c *collStats) Process(ctx context.Context, in []*types.Document) ([]*types.Document, error) {
func (c *collStatsStage) Process(ctx context.Context, in []*types.Document) ([]*types.Document, error) {
// The result of $collStats stage is always an array with a single document, and we expect the same input.
Copy link
Member

Choose a reason for hiding this comment

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

$collStats returns an array with single document for non-shared collection, https://www.mongodb.com/docs/manual/reference/operator/aggregation/collStats/#mongodb-pipeline-pipe.-collStats

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rephrased the comment

if len(in) != 1 {
panic(fmt.Sprintf("collStats: expected 1 document, got %d", len(in)))
panic(fmt.Sprintf("collStatsStage: Process: expected 1 document, got %d", len(in)))
}

res := in[0]
Expand All @@ -102,11 +102,11 @@ func (c *collStats) Process(ctx context.Context, in []*types.Document) ([]*types
}

// Type implements Stage interface.
func (c *collStats) Type() StageType {
func (c *collStatsStage) Type() StageType {
return StageTypeStats
}

// check interfaces
var (
_ Stage = (*collStats)(nil)
_ Stage = (*collStatsStage)(nil)
)
2 changes: 1 addition & 1 deletion internal/handlers/common/aggregations/statistics.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func GetStatistics(stages []Stage) map[Statistic]struct{} {

for _, stage := range stages {
switch st := stage.(type) {
case *collStats:
case *collStatsStage:
if st.count {
stats[StatisticCount] = struct{}{}
}
Expand Down
10 changes: 6 additions & 4 deletions internal/handlers/pg/msg_datasize.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,16 @@ func (h *Handler) MsgDataSize(ctx context.Context, msg *wire.OpMsg) (*wire.OpMsg
elapses := time.Since(started)

addEstimate := true
if err != nil {
if !errors.Is(err, pgx.ErrNoRows) {
return nil, lazyerrors.Error(err)
}

switch {
case err == nil, errors.Is(err, pgx.ErrNoRows):
// do nothing
case errors.Is(err, pgdb.ErrTableNotExist):
// return zeroes for non-existent collection
stats = new(pgdb.DBStats)
addEstimate = false
default:
return nil, lazyerrors.Error(err)
}

var pairs []any
Expand Down