Skip to content
Snippets Groups Projects
Commit ffba8d3a authored by Leonardo's avatar Leonardo
Browse files

fix: count query error empty entities

parent b03745e5
No related tags found
No related merge requests found
Pipeline #145472 passed
......@@ -630,4 +630,37 @@ describe('query2Cypher', () => {
expect(fixCypherSpaces(cypher.query)).toEqual(fixCypherSpaces(expectedCypher));
});
it('should return correctly on a query with count', () => {
const query: BackendQueryFormat = {
saveStateID: 'b1873956-e51b-46db-9c33-ab8bfbd177ef',
query: [
{
id: 'path_0',
node: {
relation: {
id: 'id_1739982191754',
label: 'HAS',
depth: {
max: 1,
min: 1,
},
direction: 'BOTH',
node: {},
},
},
},
],
limit: 555,
return: ['*'],
cached: false,
};
const cypher = query2Cypher(query);
const expectedCypher = 'MATCH path_0 = (()-[id_1739982191754:HAS*1..1]-()) RETURN * LIMIT 555';
expect(fixCypherSpaces(cypher.query)).toEqual(fixCypherSpaces(expectedCypher));
const expectedCypherCount =
'MATCH path_0 = (()-[id_1739982191754:HAS*1..1]-()) RETURN COUNT(DISTINCT id_1739982191754) as id_1739982191754_count';
expect(fixCypherSpaces(cypher.countQuery)).toEqual(fixCypherSpaces(expectedCypherCount));
});
});
......@@ -95,7 +95,8 @@ export function query2Cypher(JSONQuery: BackendQueryFormat): QueryCypher {
countQuery += Object.values(cacheData.entities)
.map(e => `COUNT(DISTINCT ${e.id}) as ${e.id}_count`)
.join(', ');
countQuery += Object.values(cacheData.relations).length > 0 ? ', ' : '';
countQuery += Object.values(cacheData.entities).length > 0 && Object.values(cacheData.relations).length > 0 ? ', ' : '';
countQuery += Object.values(cacheData.relations)
.map(r => `COUNT(DISTINCT ${r.id}) as ${r.id}_count`)
.join(', ');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment