Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • graphpolaris/microservices/query-service
1 result
Show changes
Commits on Source (2)
......@@ -175,9 +175,9 @@ export const queryServiceReader = async (frontendPublisher: RabbitMqBroker, mlPu
publisher.publishTranslationResultToFrontend(query);
for (let i = 0; i < ss.dbConnections.length; i++) {
const result = await queryService(ss.dbConnections[i], cypher);
try {
const result = await queryService(ss.dbConnections[i], cypher);
// Cache nodeCounts such that we can display differentiation for each query
await ums.updateQuery(headers.message.sessionData.userID, message.saveStateID, {
...activeQueryInfo,
......
......@@ -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(', ');
......