Skip to content

Commit

Permalink
feat: format yield in query
Browse files Browse the repository at this point in the history
  • Loading branch information
hetao92 committed Dec 21, 2021
1 parent 9c7c994 commit 8087100
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 31 deletions.
2 changes: 1 addition & 1 deletion app/assets/modules/Import/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
.import-log {
height: 100%;
overflow: auto;
padding: 10px 20px 20px;
padding: 10px 20px 120px;
font-size: 18px;
text-align: left;
background: #333;
Expand Down
58 changes: 30 additions & 28 deletions app/assets/store/models/explore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,16 @@ import { parsePathToGraph, setLink } from '#assets/utils/parseData';

function getBidrectVertexIds(data) {
const { tables } = data;
// go from nqgl return [{*._dst: id}]
const ids = _.uniq(
tables
.map(row => {
return Object.values(row);
})
.flat(),
)
.filter(id => id !== 0)
.map(id => String(id));
return ids;
// go from yield edge nqgl return [{_edgesParsedList: srcID: xx, dstID: xx}]
const vertexIds: string[] = [];
tables.forEach(item => {
item._edgesParsedList.forEach(edge => {
const { dstID, srcID } = edge;
vertexIds.push(String(dstID));
vertexIds.push(String(srcID));
});
});
return _.uniq(vertexIds);
}

interface IExportEdge {
Expand Down Expand Up @@ -95,7 +94,7 @@ function getGroup(tags) {
return 't-' + tags.sort().join('-');
}

function getTagData(nodes, expand) {
function getTagData(nodes, expand?) {
const data = nodes.map(node => {
const { vid, tags, properties } = node;
const group = getGroup(tags);
Expand Down Expand Up @@ -352,9 +351,21 @@ export const explore = createModel({
quantityLimit: number | null;
}) {
const { code, data, message } = await fetchVertexPropsWithIndex(payload);
if (code === 0 && data.tables.length !== 0) {
const ids = data.tables && data.tables.map(i => i.VertexID || i._vid);
this.asyncImportNodes({ ids });
if (code === 0) {
if (data.tables.length === 0) {
message.info(intl.get('common.noData'));
} else {
const vertexList = data.tables.map(i => i._verticesParsedList).flat();
const vertexes = vertexList.map(({ vid, tags, properties }) => ({
vid: vid || '',
tags: tags || [],
properties: properties || {},
}));
this.addNodesAndEdges({
vertexes: getTagData(vertexes),
edges: [],
});
}
} else {
throw new Error(message);
}
Expand All @@ -369,6 +380,7 @@ export const explore = createModel({
};
}) {
const { ids, expand } = payload;
console.log('ids', ids);
const _ids = _.uniqBy(ids, i => convertBigNumberToString(i));
const vertexes: any =
_ids.length > 0
Expand Down Expand Up @@ -437,19 +449,9 @@ export const explore = createModel({
const {
nebula: { spaceVidType },
} = rootState;
// If these ids have hanging edges, get the src/dst id of these input ids on the hanging edges
let bidirectRes = await fetchBidirectVertexes({ ids, spaceVidType });
let _ids =
bidirectRes.code === 0 ? getBidrectVertexIds(bidirectRes.data) : [];
if (_ids.length > 0) {
// Batch query cannot accurately know which input ids have hanging edges
// So use the result ids to query the corresponding ids on all edges
// these ids must include vertex id of the haning edge
bidirectRes = await fetchBidirectVertexes({ ids: _ids, spaceVidType });
_ids =
bidirectRes.code === 0 ? getBidrectVertexIds(bidirectRes.data) : [];
}
return _ids;
const res = await fetchBidirectVertexes({ ids, spaceVidType });
const vertexIds = res.code === 0 ? getBidrectVertexIds(res.data) : [];
return vertexIds.filter(id => ids.includes(id));
},

async asyncGetExploreEdge(edgeList: IExportEdge[], rootState) {
Expand Down
4 changes: 3 additions & 1 deletion app/assets/utils/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export async function fetchEdgeProps(payload: {
gql += `,${edgeType}.${edgeField}`;
}
});
} else {
gql += ' YIELD edge as `_edge`';
}

const { data } = (await service.execNGQL({
Expand Down Expand Up @@ -73,7 +75,7 @@ export async function fetchBidirectVertexes(payload: {
}) {
const { ids, spaceVidType } = payload;
const _ids = ids.map(id => handleVidStringName(id, spaceVidType)).join(', ');
const gql = `GO FROM ${_ids} OVER * BIDIRECT`;
const gql = `GO FROM ${_ids} OVER * BIDIRECT yield edge as \`_edge\``;
const { code, data, message } = (await service.execNGQL({
gql,
})) as any;
Expand Down
6 changes: 5 additions & 1 deletion app/assets/utils/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ export const getExploreGQLWithIndex = (params: {
const gql =
`LOOKUP ON
${handleKeyword(tag)} ${wheres ? `\nWHERE ${wheres}` : ''}
` + `| LIMIT ${quantityLimit ? quantityLimit : 100}`;
` +
` yield vertex as \`_vertex\` | LIMIT ${
quantityLimit ? quantityLimit : 100
}`;

return gql;
};
Expand Down Expand Up @@ -283,6 +286,7 @@ export const getPathGQL = (params: {
`FIND ${type} PATH FROM ${_srcIds} TO ${_dstIds} over ${_relation}` +
`${direction ? ` ${direction}` : ''}` +
`${stepLimit ? ' UPTO ' + stepLimit + ' STEPS' : ''}` +
' yield path as `_path`' +
`${quantityLimit ? ' | LIMIT ' + quantityLimit : ''}`;

return gql;
Expand Down

0 comments on commit 8087100

Please sign in to comment.