Skip to content

GODRIVER-3522 Add support for the rawData option for time-series bucket access. #2079

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

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[submodule "specifications"]
path = testdata/specifications
url = https://github.com/mongodb/specifications
url = https://github.com/qingyang-hu/specifications.git
branch = drivers3064
2 changes: 2 additions & 0 deletions internal/integration/unified/client_operation_execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ func executeClientBulkWrite(ctx context.Context, operation *operation) (*operati
return nil, err
}
opts.SetWriteConcern(c)
case "rawData":
opts.SetRawData(val.Boolean())
default:
return nil, fmt.Errorf("unrecognized bulkWrite option %q", key)
}
Expand Down
38 changes: 37 additions & 1 deletion internal/integration/unified/collection_operation_execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ func executeAggregate(ctx context.Context, operation *operation) (*operationResu
pipeline = bsonutil.RawToInterfaces(bsonutil.RawArrayToDocuments(val.Array())...)
case "let":
opts.SetLet(val.Document())
case "rawData":
opts.SetRawData(val.Boolean())
default:
return nil, fmt.Errorf("unrecognized aggregate option %q", key)
}
Expand Down Expand Up @@ -125,6 +127,8 @@ func executeBulkWrite(ctx context.Context, operation *operation) (*operationResu
}
case "let":
opts.SetLet(val.Document())
case "rawData":
opts.SetRawData(val.Boolean())
default:
return nil, fmt.Errorf("unrecognized bulkWrite option %q", key)
}
Expand Down Expand Up @@ -202,6 +206,8 @@ func executeCountDocuments(ctx context.Context, operation *operation) (*operatio
return nil, fmt.Errorf("the maxTimeMS collection option is not supported")
case "skip":
opts.SetSkip(int64(val.Int32()))
case "rawData":
opts.SetRawData(val.Boolean())
default:
return nil, fmt.Errorf("unrecognized countDocuments option %q", key)
}
Expand All @@ -225,6 +231,7 @@ func executeCreateIndex(ctx context.Context, operation *operation) (*operationRe

var keys bson.Raw
indexOpts := options.Index()
opts := options.CreateIndexes()

elems, err := operation.Arguments.Elements()
if err != nil {
Expand Down Expand Up @@ -279,6 +286,8 @@ func executeCreateIndex(ctx context.Context, operation *operation) (*operationRe
indexOpts.SetWeights(val.Document())
case "wildcardProjection":
indexOpts.SetWildcardProjection(val.Document())
case "rawData":
opts.SetRawData(val.Boolean())
default:
return nil, fmt.Errorf("unrecognized createIndex option %q", key)
}
Expand All @@ -291,7 +300,8 @@ func executeCreateIndex(ctx context.Context, operation *operation) (*operationRe
Keys: keys,
Options: indexOpts,
}
name, err := coll.Indexes().CreateOne(ctx, model)

name, err := coll.Indexes().CreateOne(ctx, model, opts)
return newValueResult(bson.TypeString, bsoncore.AppendString(nil, name), err), nil
}

Expand Down Expand Up @@ -433,6 +443,8 @@ func executeDeleteOne(ctx context.Context, operation *operation) (*operationResu
opts.SetHint(hint)
case "let":
opts.SetLet(val.Document())
case "rawData":
opts.SetRawData(val.Boolean())
default:
return nil, fmt.Errorf("unrecognized deleteOne option %q", key)
}
Expand Down Expand Up @@ -487,6 +499,8 @@ func executeDeleteMany(ctx context.Context, operation *operation) (*operationRes
opts.SetHint(hint)
case "let":
opts.SetLet(val.Document())
case "rawData":
opts.SetRawData(val.Boolean())
default:
return nil, fmt.Errorf("unrecognized deleteMany option %q", key)
}
Expand Down Expand Up @@ -545,6 +559,8 @@ func executeDistinct(ctx context.Context, operation *operation) (*operationResul
// ensured an analogue exists, extend "skippedTestDescriptions" to avoid
// this error.
return nil, fmt.Errorf("the maxTimeMS collection option is not supported")
case "rawData":
opts.SetRawData(val.Boolean())
default:
return nil, fmt.Errorf("unrecognized distinct option %q", key)
}
Expand Down Expand Up @@ -593,6 +609,8 @@ func executeDropIndex(ctx context.Context, operation *operation) (*operationResu
// ensured an analogue exists, extend "skippedTestDescriptions" to avoid
// this error.
return nil, fmt.Errorf("the maxTimeMS collection option is not supported")
case "rawData":
dropIndexOpts.SetRawData(val.Boolean())
default:
return nil, fmt.Errorf("unrecognized dropIndex option %q", key)
}
Expand Down Expand Up @@ -690,6 +708,8 @@ func executeEstimatedDocumentCount(ctx context.Context, operation *operation) (*
// ensured an analogue exists, extend "skippedTestDescriptions" to avoid
// this error.
return nil, fmt.Errorf("the maxTimeMS collection option is not supported")
case "rawData":
opts.SetRawData(val.Boolean())
default:
return nil, fmt.Errorf("unrecognized estimatedDocumentCount option %q", key)
}
Expand Down Expand Up @@ -842,6 +862,8 @@ func executeFindOneAndDelete(ctx context.Context, operation *operation) (*operat
opts.SetSort(val.Document())
case "let":
opts.SetLet(val.Document())
case "rawData":
opts.SetRawData(val.Boolean())
default:
return nil, fmt.Errorf("unrecognized findOneAndDelete option %q", key)
}
Expand Down Expand Up @@ -924,6 +946,8 @@ func executeFindOneAndReplace(ctx context.Context, operation *operation) (*opera
opts.SetSort(val.Document())
case "upsert":
opts.SetUpsert(val.Boolean())
case "rawData":
opts.SetRawData(val.Boolean())
default:
return nil, fmt.Errorf("unrecognized findOneAndReplace option %q", key)
}
Expand Down Expand Up @@ -1016,6 +1040,8 @@ func executeFindOneAndUpdate(ctx context.Context, operation *operation) (*operat
}
case "upsert":
opts.SetUpsert(val.Boolean())
case "rawData":
opts.SetRawData(val.Boolean())
default:
return nil, fmt.Errorf("unrecognized findOneAndUpdate option %q", key)
}
Expand Down Expand Up @@ -1062,6 +1088,8 @@ func executeInsertMany(ctx context.Context, operation *operation) (*operationRes
documents = bsonutil.RawToInterfaces(bsonutil.RawArrayToDocuments(val.Array())...)
case "ordered":
opts.SetOrdered(val.Boolean())
case "rawData":
opts.SetRawData(val.Boolean())
default:
return nil, fmt.Errorf("unrecognized insertMany option %q", key)
}
Expand Down Expand Up @@ -1112,6 +1140,8 @@ func executeInsertOne(ctx context.Context, operation *operation) (*operationResu
opts.SetBypassDocumentValidation(val.Boolean())
case "comment":
opts.SetComment(val)
case "rawData":
opts.SetRawData(val.Boolean())
default:
return nil, fmt.Errorf("unrecognized insertOne option %q", key)
}
Expand Down Expand Up @@ -1156,6 +1186,8 @@ func executeListIndexes(ctx context.Context, operation *operation) (*operationRe
switch key {
case "batchSize":
opts.SetBatchSize(val.Int32())
case "rawData":
opts.SetRawData(val.Boolean())
default:
return nil, fmt.Errorf("unrecognized listIndexes option: %q", key)
}
Expand Down Expand Up @@ -1302,6 +1334,8 @@ func executeReplaceOne(ctx context.Context, operation *operation) (*operationRes
opts.SetUpsert(val.Boolean())
case "let":
opts.SetLet(val.Document())
case "rawData":
opts.SetRawData(val.Boolean())
default:
return nil, fmt.Errorf("unrecognized replaceOne option %q", key)
}
Expand Down Expand Up @@ -1500,6 +1534,8 @@ func createFindCursor(ctx context.Context, operation *operation) (*cursorResult,
case "maxAwaitTimeMS":
maxAwaitTimeMS := time.Duration(val.Int32()) * time.Millisecond
opts.SetMaxAwaitTime(maxAwaitTimeMS)
case "rawData":
opts.SetRawData(val.Boolean())
default:
return nil, fmt.Errorf("unrecognized find option %q", key)
}
Expand Down
6 changes: 6 additions & 0 deletions internal/integration/unified/crud_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ func createUpdateManyArguments(args bson.Raw) (*updateArguments, *options.Update
}
case "upsert":
opts.SetUpsert(val.Boolean())
case "rawData":
opts.SetRawData(val.Boolean())
default:
return nil, nil, fmt.Errorf("unrecognized update option %q", key)
}
Expand Down Expand Up @@ -125,6 +127,8 @@ func createUpdateOneArguments(args bson.Raw) (*updateArguments, *options.UpdateO
opts.SetUpsert(val.Boolean())
case "sort":
opts.SetSort(val.Document())
case "rawData":
opts.SetRawData(val.Boolean())
default:
return nil, nil, fmt.Errorf("unrecognized update option %q", key)
}
Expand Down Expand Up @@ -162,6 +166,8 @@ func createListCollectionsArguments(args bson.Raw) (*listCollectionsArguments, e
lca.filter = val.Document()
case "nameOnly":
lca.opts.SetNameOnly(val.Boolean())
case "rawData":
lca.opts.SetRawData(val.Boolean())
default:
return nil, fmt.Errorf("unrecognized listCollections option %q", key)
}
Expand Down
13 changes: 13 additions & 0 deletions mongo/bulk_write.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type bulkWrite struct {
writeConcern *writeconcern.WriteConcern
result BulkWriteResult
let interface{}
rawData *bool
}

func (bw *bulkWrite) execute(ctx context.Context) error {
Expand Down Expand Up @@ -209,6 +210,10 @@ func (bw *bulkWrite) runInsert(ctx context.Context, batch bulkWriteBatch) (opera
}
op = op.Retry(retry)

if bw.rawData != nil {
op.RawData(*bw.rawData)
}

err := op.Execute(ctx)

return op.Result(), err
Expand Down Expand Up @@ -282,6 +287,10 @@ func (bw *bulkWrite) runDelete(ctx context.Context, batch bulkWriteBatch) (opera
}
op = op.Retry(retry)

if bw.rawData != nil {
op.RawData(*bw.rawData)
}

err := op.Execute(ctx)

return op.Result(), err
Expand Down Expand Up @@ -415,6 +424,10 @@ func (bw *bulkWrite) runUpdate(ctx context.Context, batch bulkWriteBatch) (opera
}
op = op.Retry(retry)

if bw.rawData != nil {
op.RawData(*bw.rawData)
}

err := op.Execute(ctx)

return op.Result(), err
Expand Down
1 change: 1 addition & 0 deletions mongo/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,7 @@ func (c *Client) BulkWrite(ctx context.Context, writes []ClientBulkWrite,
client: c,
selector: selector,
writeConcern: wc,
rawData: bwo.RawData,
}
if bwo.VerboseResults == nil || !(*bwo.VerboseResults) {
op.errorsOnly = true
Expand Down
5 changes: 5 additions & 0 deletions mongo/client_bulk_write.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type clientBulkWrite struct {
client *Client
selector description.ServerSelector
writeConcern *writeconcern.WriteConcern
rawData *bool

result ClientBulkWriteResult
}
Expand Down Expand Up @@ -143,6 +144,10 @@ func (bw *clientBulkWrite) newCommand() func([]byte, description.SelectedServer)
}
dst = bsoncore.AppendDocumentElement(dst, "let", let)
}
// Set rawData for 8.2+ servers.
if bw.rawData != nil && desc.WireVersion != nil && driverutil.VersionRangeIncludes(*desc.WireVersion, 27) {
dst = bsoncore.AppendBooleanElement(dst, "rawData", *bw.rawData)
}
return dst, nil
}
}
Expand Down
Loading