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

Fix #209

Closed
wants to merge 3 commits into from
Closed

Fix #209

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
6 changes: 3 additions & 3 deletions src/utils/sharedUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ const VARIABLE_REGEX = /^[a-zA-Z_]\w*$/; // vars of form aA4_f allowed
export function getColumNameForJsonField(jsonField) {
// ignoring sonar security error as md5 function is not used for security
// Md5 function is used here to increase the length of jsonfield to more than 64 characters
return crypto.createHash('md5').update(jsonField).digest('hex'); //NOSONAR
const hash = crypto.createHash('md5').update(jsonField).digest('hex'); //NOSONAR
return "col_" + hash;
}

export function isAlphaNumChar(char) {
char = char.charCodeAt(0);
if (!(char > 47 && char < 58) && // numeric (0-9)
Expand Down Expand Up @@ -69,4 +69,4 @@ export function isNestedVariableNameLike(nameToTest) {
}
}
return true;
}
}
23 changes: 23 additions & 0 deletions test/integration/libmysql-test.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,28 @@ describe('Integration: libMySql', function () {
});
await deleteData(results);
});
it('create and validate Index should pass', async function () {
const numberOfEntries = 1000;
const results = await testReadWrite(numberOfEntries);
let isSuccess = await createIndexForJsonField(tableName, 'userId', DATA_TYPES.VARCHAR(50),
false);
expect(isSuccess).to.eql(true);
isSuccess = await createIndexForJsonField(tableName, 'Age', DATA_TYPES.INT, false);
expect(isSuccess).to.eql(true);
const queryResults = await getFromIndex(tableName, {
'userId': 'ABCD',
'Age': 100
});
expect(queryResults.length).to.eql(numberOfEntries);
queryResults.forEach(result => {
expect(result.lastName).to.eql('Alice');
expect(results.userId).to.eql("ABCD");
expect(result.Age).to.eql(100);
expect(result.active).to.eql(true);
expect(result.documentId.length).gt(0);
});
await deleteData(results);
});

it('create and validate Index return empty list if nothing matches', async function () {
let isSuccess = await createIndexForJsonField(tableName, 'location.layout.block', DATA_TYPES.VARCHAR(50),
Expand Down Expand Up @@ -786,6 +808,7 @@ async function testReadWrite(numberOfWrites) {
async function populateTestTable(numberOfWrites) {
const document = {
'lastName': 'Alice',
'userId': "ABCD",
'Age': 100,
'active': true,
'location': {
Expand Down
4 changes: 2 additions & 2 deletions test/unit/utils/db-test.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ describe('Unit tests for db.js', function () {
const tableName = 'test.hello';
await deleteDocuments(tableName, "$.x<10 AND $.hotel.name='oyo'", ['hotel.name']);
expect(savedSql).to.eql("DELETE FROM test.hello WHERE document->>\"$.x\"<10" +
" AND b978c733175ca5d9503b1cc095eece1f='oyo';");
" AND col_b978c733175ca5d9503b1cc095eece1f='oyo';");
mockedFunctions.connection.execute = saveExecute;
});
});
Expand Down Expand Up @@ -2566,7 +2566,7 @@ describe('Unit tests for db.js', function () {
await _validateQueryPass("$.s<10 && !$.j.k || $.y!='hello'",
["s", "j.k"],
"SELECT documentID,document FROM test.customer " +
"WHERE 03c7c0ace395d80182db07ae2c30f034<10 && !91e12519d4a93e0ce72a98c42383e747 " +
"WHERE col_03c7c0ace395d80182db07ae2c30f034<10 && !col_91e12519d4a93e0ce72a98c42383e747 " +
"|| document->>\"$.y\"!='hello' LIMIT 1000");
});

Expand Down
3 changes: 2 additions & 1 deletion test/unit/utils/query-test.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ describe('Query Utils test', function () {

it('should transformCocoToSQLQuery success cases with index field', function () {
expect(Query.transformCocoToSQLQuery("$.y>5 || $.x > 10 && $.price.tax = 18", ["x", "price.tax"]))
.to.eql('document->>"$.y">5 || 9dd4e461268c8034f5c8564e155c67a6 > 10 && 6a1a731895e201b727851bc567ac1e8a = 18');
// eslint-disable-next-line max-len
.to.eql('document->>"$.y">5 || col_9dd4e461268c8034f5c8564e155c67a6 > 10 && col_6a1a731895e201b727851bc567ac1e8a = 18');
});

it('should transformCocoToSQLQuery error cases', function () {
Expand Down
Loading