-
-
Notifications
You must be signed in to change notification settings - Fork 623
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: fully support VECTOR type results
- Loading branch information
Showing
6 changed files
with
73 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { test, assert, describe } from 'poku'; | ||
import { createRequire } from 'node:module'; | ||
|
||
const require = createRequire(import.meta.url); | ||
const common = require('../../../common.test.cjs'); | ||
|
||
const sql = `SELECT TO_VECTOR("[1.05, -17.8, 32, 123.456]") as test`; | ||
const expectedArray = [1.05, -17.8, 32, 123.456]; | ||
const epsilon = 1e-6; | ||
|
||
const compareFloat = (a, b) => Math.abs((a - b) / a) < epsilon; | ||
const compareFLoatsArray = (a, b) => a.every((v, i) => compareFloat(v, b[i])); | ||
|
||
(async () => { | ||
const connection = common.createConnection().promise(); | ||
|
||
const mySqlVersion = await common.getMysqlVersion(connection); | ||
|
||
if (mySqlVersion.major < 9) { | ||
console.log( | ||
`Skipping the test, required mysql version is 9 and above, actual version is ${mySqlVersion.major}`, | ||
); | ||
await connection.end(); | ||
return; | ||
} | ||
|
||
await test(async () => { | ||
describe( | ||
'Execute PS with vector response is parsed correctly', | ||
common.describeOptions, | ||
); | ||
|
||
const [_rows] = await connection.execute(sql); | ||
assert.equal( | ||
compareFLoatsArray(_rows[0].test, expectedArray), | ||
true, | ||
`${_rows[0].test} should be equal to ${expectedArray}`, | ||
); | ||
}); | ||
|
||
await test(async () => { | ||
describe( | ||
'Select returning vector is parsed correctly', | ||
common.describeOptions, | ||
); | ||
|
||
const [_rows] = await connection.query(sql); | ||
assert.equal( | ||
compareFLoatsArray(_rows[0].test, expectedArray), | ||
true, | ||
`${_rows[0].test} should be equal to ${expectedArray}`, | ||
); | ||
}); | ||
|
||
await connection.end(); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters