diff options
author | Lynne Wang <lynne.wang@mongodb.com> | 2022-08-10 12:46:20 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-08-10 13:20:08 +0000 |
commit | 85ff13118e4f882b7c254fd1d3c2f4abd4c5296b (patch) | |
tree | 6c67145c7f707cdf63ccd7e75a35aedf66151265 /jstests/cqf | |
parent | 86c0cc1046f22753ae9c5c82d62329f491d70e71 (diff) | |
download | mongo-85ff13118e4f882b7c254fd1d3c2f4abd4c5296b.tar.gz |
SERVER-67997 Validation of analyze parameters
Diffstat (limited to 'jstests/cqf')
-rw-r--r-- | jstests/cqf/analyze_command.js | 90 |
1 files changed, 87 insertions, 3 deletions
diff --git a/jstests/cqf/analyze_command.js b/jstests/cqf/analyze_command.js index 903cfd2ddf8..445480aca86 100644 --- a/jstests/cqf/analyze_command.js +++ b/jstests/cqf/analyze_command.js @@ -10,14 +10,98 @@ if (!checkCascadesOptimizerEnabled(db)) { const coll = db.cqf_analyze; coll.drop(); -assert.commandWorked(coll.insert({a: [1, 2, 4, 4, 5, 6]})); +assert.commandWorked(coll.insert({a: [1, 2, 4, 4, 5, 6, {b: 1}]})); -let res = db.runCommand({analyze: coll.getName()}); -assert.commandFailedWithCode(res, ErrorCodes.NotImplemented); +let res = null; + +(function validateNamespace() { + res = db.runCommand({analyze: ""}); + assert.commandFailedWithCode(res, ErrorCodes.InvalidNamespace); + + res = db.runCommand({analyze: "hello"}); + assert.commandFailedWithCode(res, 6799700); + + const view = db.cqf_analyze_view; + view.drop(); + assert.commandWorked(db.createView(view.getName(), coll.getName(), [])); + res = db.runCommand({analyze: view.getName()}); + assert.commandFailedWithCode(res, ErrorCodes.CommandNotSupportedOnView); + + const ts = db.cqf_analyze_timeseries; + ts.drop(); + const timeField = "tm"; + assert.commandWorked(db.createCollection(ts.getName(), {timeseries: {timeField: timeField}})); + res = db.runCommand({analyze: ts.getName()}); + assert.commandFailedWithCode(res, ErrorCodes.CommandNotSupportedOnView); + + const capped = db.cqf_analyze_capped; + capped.drop(); + assert.commandWorked(db.createCollection(capped.getName(), {capped: true, size: 256})); + res = db.runCommand({analyze: capped.getName()}); + assert.commandFailedWithCode(res, 6799701); + + const system_profile = db.system.profile; + system_profile.drop(); + assert.commandWorked(db.createCollection(system_profile.getName())); + res = db.runCommand({analyze: system_profile.getName()}); + assert.commandFailedWithCode(res, 6799702); + + // Correct error thrown under cqf flag + res = db.runCommand({analyze: coll.getName()}); + assert.commandFailedWithCode(res, ErrorCodes.NotImplemented); +})(); + +(function validateKey() { + res = db.runCommand({analyze: coll.getName(), key: ""}); + assert.commandFailedWithCode(res, 6799703); + + res = db.runCommand({analyze: coll.getName(), key: "a..b"}); + assert.commandFailedWithCode(res, 15998); + + res = db.runCommand({analyze: coll.getName(), key: "a.$b"}); + assert.commandFailedWithCode(res, 16410); + + res = db.runCommand({analyze: coll.getName(), key: "a.0.b"}); + assert.commandFailedWithCode(res, 6799704); + + res = db.runCommand({analyze: coll.getName(), key: "a.b"}); + assert.commandFailedWithCode(res, ErrorCodes.NotImplemented); +})(); + +(function validateSampleRateAndSize() { + res = db.runCommand({analyze: coll.getName(), key: "a.b", sampleRate: 0.1, sampleSize: 1000}); + assert.commandFailedWithCode(res, 6799705); + + res = db.runCommand({analyze: coll.getName(), sampleRate: 0.1}); + assert.commandFailedWithCode(res, 6799706); + + res = db.runCommand({analyze: coll.getName(), key: "a.b", sampleRate: "hello"}); + assert.commandFailedWithCode(res, ErrorCodes.TypeMismatch); + + res = db.runCommand({analyze: coll.getName(), key: "a.b", sampleRate: 1.5}); + assert.commandFailedWithCode(res, 51024); + + res = db.runCommand({analyze: coll.getName(), key: "a.b", sampleRate: null}); + assert.commandFailedWithCode(res, ErrorCodes.NotImplemented); + + res = db.runCommand({analyze: coll.getName(), sampleSize: 123}); + assert.commandFailedWithCode(res, 6799706); + + res = db.runCommand({analyze: coll.getName(), key: "a.b", sampleSize: "hello"}); + assert.commandFailedWithCode(res, ErrorCodes.TypeMismatch); + + res = db.runCommand({analyze: coll.getName(), key: "a.b", sampleSize: -5}); + assert.commandFailedWithCode(res, 51024); + + res = db.runCommand({analyze: coll.getName(), key: "a.b", sampleSize: null}); + assert.commandFailedWithCode(res, ErrorCodes.NotImplemented); +})(); +// Test API Strict res = db.runCommand({analyze: coll.getName(), apiVersion: "1", apiStrict: true}); assert.commandFailedWithCode(res, ErrorCodes.APIStrictError); +// Test write concern res = db.runCommand({analyze: coll.getName(), writeConcern: {w: 1}}); assert.commandFailedWithCode(res, ErrorCodes.NotImplemented); }()); |