Skip to content
Merged
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
113 changes: 52 additions & 61 deletions test-basic/annTopK.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,98 +13,89 @@ let serverConfiguration = {};
const execPlan = pbb.execPlan;

describe('tests for annTopK', function () {
this.timeout(5000)
before(function (done) {
try {
testlib.findServerConfiguration(serverConfiguration);
setTimeout(() => {
if (serverConfiguration.serverVersion < 12) {
this.skip();
}
done();
}, 3000);
} catch (error) {
done(error);
this.timeout(5000);
before(async function () {
await testlib.findServerConfigurationPromise(serverConfiguration);

if (serverConfiguration.serverVersion < 12) {
this.skip();
}
});

it('annTopK without PlanAnnTopKOptions', function (done) {
execPlan(p
it('annTopK without PlanAnnTopKOptions', async function () {
const response = await execPlan(p
.fromView('vectors', 'persons', '')
.annTopK(10, p.col('embedding'), p.vec.vector([1.1, 2.2, 3.3]), p.col('distance'))
.orderBy(p.col('name'))
)
.then(function (response) {
verifyResults(response.rows, done);
})
.catch(error => done(error));
);
verifyResults(response.rows);
});

it('annTopK with PlanAnnTopKOptions as a single string', function (done) {
execPlan(p
it('annTopK with PlanAnnTopKOptions as a single string', async function () {
const response = await execPlan(p
.fromView('vectors', 'persons', '')
.annTopK(10, p.col('embedding'), p.vec.vector([1.1, 2.2, 3.3]), p.col('distance'), 'onlyIndex')
.orderBy(p.col('name'))
)
.then(function (response) {
verifyResults(response.rows, done);
})
.catch(error => done(error));
);
verifyResults(response.rows);
});

it('annTopK with PlanAnnTopKOptions as an array of string', function (done) {
execPlan(p
it('annTopK with PlanAnnTopKOptions as an array of string', async function () {
const response = await execPlan(p
.fromView('vectors', 'persons', '')
.annTopK(10, p.col('embedding'), p.vec.vector([1.1, 2.2, 3.3]), p.col('distance'),
['onlyIndex', "maxDistance=0.15", "searchFactor=1.0"])
.orderBy(p.col('name'))
).then(function (response) {
verifyResults(response.rows, done);
}).catch(error => done(error));
);
verifyResults(response.rows);
});

it('annTopK with PlanAnnTopKOptions as a map', function (done) {
it('annTopK with PlanAnnTopKOptions as a map', async function () {
const planAnnTopKOptionsMap = new Map();
planAnnTopKOptionsMap.set("maxDistance", 0.158454656600952);
planAnnTopKOptionsMap.set("searchFactor", 10.0);
execPlan(p
const response = await execPlan(p
.fromView('vectors', 'persons', '')
.annTopK(10, p.col('embedding'), p.vec.vector([1.1, 2.2, 3.3]), p.col('distance'),
planAnnTopKOptionsMap)
.orderBy(p.col('name'))
)
.then(function (response) {
verifyResults(response.rows, done);
})
.catch(error => done(error));
);
verifyResults(response.rows);
});

it('annTopK with invalid PlanAnnTopKOptions', function (done) {
it('annTopK with invalid PlanAnnTopKOptions', async function () {
const planAnnTopKOptionsMap = new Map();
planAnnTopKOptionsMap.set('invalid', 10.0);
try{
execPlan(p
.fromView('vectors', 'persons', '')
.annTopK(10, p.col('embedding'), p.vec.vector([1.1, 2.2, 3.3]), p.col('distance'),
planAnnTopKOptionsMap)
.orderBy(p.col('name'))
);
} catch(error){
assert(error.message.toString().includes('options argument at 4 of PlanModifyPlan.annTopK() has invalid key- invalid'))
done();
}

await assert.rejects(
async () => {
await execPlan(p
.fromView('vectors', 'persons', '')
.annTopK(10, p.col('embedding'), p.vec.vector([1.1, 2.2, 3.3]), p.col('distance'),
planAnnTopKOptionsMap)
.orderBy(p.col('name'))
);
},
(error) => {
return error.message.toString().includes('options argument at 4 of PlanModifyPlan.annTopK() has invalid key- invalid');
}
);
});

function verifyResults(rows, done){
try {
assert(rows.length === 2, 'Expecting both rows in the view to be returned.');
assert(rows[0].name.value === 'Alice');
assert(rows[0].distance.type === 'xs:float', 'Verifying that the distance column was populated.');
assert(rows[1].name.value === 'Bob');
assert(rows[1].distance.type === 'xs:float', 'Verifying that the distance column was populated.');
done();
} catch (error){
done(error)
}
function verifyResults(rows) {

assert(Array.isArray(rows), 'Expected rows to be an array');
assert(rows.length === 2, 'Expecting both rows in the view to be returned.');
assert(rows[0].name.value === 'Alice');
assert(rows[0].distance.type === 'xs:float', 'Verifying that the distance column was populated.');
assert(rows[1].name.value === 'Bob');
assert(rows[1].distance.type === 'xs:float', 'Verifying that the distance column was populated.');

// Verify each row has the expected structure
rows.forEach((row, index) => {
assert(row.name && row.name.value, `Row ${index} should have a name with a value`);
assert(row.distance && row.distance.type === 'xs:float',
`Row ${index} should have a distance column of type xs:float`);
});
}
});
20 changes: 15 additions & 5 deletions test-basic/basePath-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ describe('basePath tests', function() {
testconfig.restWriterConnectionWithBasePath.basePath = 'invalid';
const dbWriter = marklogic.createDatabaseClient(testconfig.restWriterConnectionWithBasePath);
dbWriter.documents.write(writeObject)
.result(function(response){})
.result(function(response){
done(new Error('Expecting an error to be thrown due to invalid basePath'));
})
.catch(err=>
{
assert(err.toString().includes('path: invalid/v1/documents'));
Expand All @@ -29,7 +31,9 @@ describe('basePath tests', function() {
testconfig.restWriterConnectionWithBasePath.basePath = '/invalid';
const dbWriter = marklogic.createDatabaseClient(testconfig.restWriterConnectionWithBasePath);
dbWriter.documents.write(writeObject)
.result(function(response){})
.result(function(response){
done(new Error('Expecting an error to be thrown due to invalid basePath with a leading slash'));
})
.catch(err=>
{
assert(err.toString().includes('path: /invalid/v1/documents'));
Expand All @@ -41,7 +45,9 @@ describe('basePath tests', function() {
testconfig.restWriterConnectionWithBasePath.basePath = 'invalid/';
const dbWriter = marklogic.createDatabaseClient(testconfig.restWriterConnectionWithBasePath);
dbWriter.documents.write(writeObject)
.result(function(response){})
.result(function(response){
done(new Error('Expecting an error to be thrown due to invalid basePath with a trailing slash'));
})
.catch(err=>
{
assert(err.toString().includes('path: invalid/v1/documents'));
Expand All @@ -53,7 +59,9 @@ describe('basePath tests', function() {
testconfig.restWriterConnectionWithBasePath.basePath = '/invalid/';
const dbWriter = marklogic.createDatabaseClient(testconfig.restWriterConnectionWithBasePath);
dbWriter.documents.write(writeObject)
.result(function(response){})
.result(function(response){
done(new Error('Expecting an error to be thrown due to invalid basePath with starting and trailing slashes'));
})
.catch(err=>
{
assert(err.toString().includes('path: /invalid/v1/documents'));
Expand All @@ -65,7 +73,9 @@ describe('basePath tests', function() {
testconfig.restWriterConnectionWithBasePath.basePath = '//invalid//';
const dbWriter = marklogic.createDatabaseClient(testconfig.restWriterConnectionWithBasePath);
dbWriter.documents.write(writeObject)
.result(function(response){})
.result(function(response){
done(new Error('Expecting an error to be thrown due to invalid basePath with multiple starting and trailing slashes'));
})
.catch(err=>
{
try{
Expand Down
81 changes: 57 additions & 24 deletions test-basic/bindingFromParam.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ describe('optic-update fromParam tests', function(){
const planBuilderTemplate = op.fromParam('myDocs', 'qualifier', outputCols);
const temp = {myDocs: rows};
db.rows.query(planBuilderTemplate,null, temp);
done(new Error('Expecting an error to be thrown due to invalid row-col-types argument'));
} catch (e) {
e.toString().should.equal('Error: row-col-types argument at 2 of PlanBuilder.fromParam() has invalid argument for PlanRowColTypes value: [object Object]');
done();
Expand Down Expand Up @@ -157,6 +158,7 @@ describe('optic-update fromParam tests', function(){
const planBuilderTemplate = op.fromParam('myDocs', 'qualifier', outputCols);
const temp = {myDocs: rows};
db.rows.query(planBuilderTemplate, null, temp);
done(new Error('Expecting an error to be thrown due to invalid row-col-types argument'));
} catch (e) {
e.toString().should.equal('Error: row-col-types argument at 2 of PlanBuilder.fromParam() has another type than string');
done();
Expand Down Expand Up @@ -205,7 +207,11 @@ describe('optic-update fromParam tests', function(){
}, {"column": "lastName", "type": "string"}];
const planBuilderTemplate = op.fromParam('myDocs', 'qualifier', outputCols);
const temp = {myDocs: rows};
db.rows.query(planBuilderTemplate, null, temp).catch(e => {
db.rows.query(planBuilderTemplate, null, temp)
.then(function(response){
done(new Error('Expecting an error to be thrown due to null value for non-nullable column'));
})
.catch(e => {
e.toString().includes('Error: binding arguments /v1/rows: cannot process response with 500 status');
done();
});
Expand All @@ -221,7 +227,11 @@ describe('optic-update fromParam tests', function(){
}, {"column": "lastName", "type": "string", "nullable": true}];
const planBuilderTemplate = op.fromParam('myDocs', 'qualifier', outputCols);
const temp = {myDocs: rows};
db.rows.query(planBuilderTemplate, null,temp).catch(e => {
db.rows.query(planBuilderTemplate, null,temp)
.then(function(response){
done(new Error('Expecting an error to be thrown due to invalid row-col-types argument'));
})
.catch(e => {
e.toString().includes('Error: binding arguments /v1/rows: cannot process response with 500 status');
done();
});
Expand All @@ -237,7 +247,11 @@ describe('optic-update fromParam tests', function(){
}, {"column": "lastName", "type": "string", "nullable": true}];
const planBuilderTemplate = op.fromParam('myDocs', 'qualifier', outputCols);
const temp = {myDocs: rows};
db.rows.query(planBuilderTemplate,null, temp).catch(e => {
db.rows.query(planBuilderTemplate,null, temp)
.then(function(response){
done(new Error('Expecting an error to be thrown due to invalid row-col-types argument'));
})
.catch(e => {
e.toString().includes('Error: binding arguments /v1/rows: cannot process response with 500 status');
done();
});
Expand All @@ -255,10 +269,13 @@ describe('optic-update fromParam tests', function(){
const planBuilderTemplate = op.fromParam('myDocs', null, outputCols);
const temp = {myDocs: rows};
db.rows.query(planBuilderTemplate,null, temp)
.catch(e => {
e.toString().includes('Error: binding arguments /v1/rows: cannot process response with 500 status');
done();
});
.then(function(response){
done(new Error('Expecting an error to be thrown due to null value for non-nullable column'));
})
.catch(e => {
e.toString().includes('Error: binding arguments /v1/rows: cannot process response with 500 status');
done();
});
} catch (e) {
done();
}
Expand All @@ -274,10 +291,13 @@ describe('optic-update fromParam tests', function(){
const planBuilderTemplate = op.fromParam('myDocs', null, outputCols);
const temp = {myDocs: rows};
db.rows.query(planBuilderTemplate, null,temp)
.catch(e => {
e.toString().includes('Error: binding arguments /v1/rows: cannot process response with 500 status');
done();
});
.then(function(response){
done(new Error('Expecting an error to be thrown due to extra non-defined column types'));
})
.catch(e => {
e.toString().includes('Error: binding arguments /v1/rows: cannot process response with 500 status');
done();
});

});

Expand All @@ -290,10 +310,13 @@ describe('optic-update fromParam tests', function(){
const planBuilderTemplate = op.fromParam('myDocs', null, outputCols);
const temp = {bindingParam: rows};
db.rows.query(planBuilderTemplate, null, temp)
.catch(e => {
e.toString().includes('Error: binding arguments /v1/rows: cannot process response with 500 status');
done();
});
.then(function(response){
done(new Error('Expecting an error to be thrown due to non-consistent binding argument name'));
})
.catch(e => {
e.toString().includes('Error: binding arguments /v1/rows: cannot process response with 500 status');
done();
});

});

Expand All @@ -311,10 +334,13 @@ describe('optic-update fromParam tests', function(){
const planBuilderTemplate = op.fromParam('myDocs', null, outputCols);
const temp = {myDocs: rows};
db.rows.query(planBuilderTemplate, null, temp)
.catch(e => {
e.toString().includes('Error: binding arguments /v1/rows: cannot process response with 500 status');
done();
});
.then(function(response){
done(new Error('Expecting an error to be thrown due to mismatch type'));
})
.catch(e => {
e.toString().includes('Error: binding arguments /v1/rows: cannot process response with 500 status');
done();
});

});

Expand All @@ -333,6 +359,7 @@ describe('optic-update fromParam tests', function(){
const planBuilderTemplate = op.fromParam('myDocs', 1234, outputCols);
const temp = {myDocs: rows};
db.rows.query(planBuilderTemplate, null, temp);
done(new Error('Expecting an error to be thrown due to invalid qualifier argument'));
} catch (e) {
e.toString().includes('Error: qualifier argument at 1 of PlanBuilder.fromParam() must be a XsString value');
done();
Expand All @@ -353,11 +380,17 @@ describe('optic-update fromParam tests', function(){
const planBuilderTemplate = op.fromParam('myDocs', null, outputCols);
const temp = {myDocs: rows};
db.rows.query(planBuilderTemplate, null, temp).then(res => {
const rows = res.rows;
rows[0].id.value.should.equal(1);
rows[0].firstName.value.should.equal("firstName_1");
rows[0].lastName.value.should.equal("lastName_1");
done();
try {
const rows = res.rows;
rows[0].id.value.should.equal(1);
rows[0].firstName.value.should.equal("firstName_1");
rows[0].lastName.value.should.equal("lastName_1");
done();
} catch (e) {
done(e);
}
}).catch(e => {
done(e);
});

});
Expand Down
Loading