use of com.alibaba.maxgraph.compiler.tree.value.ValueType in project GraphScope by alibaba.
the class TreeBuilder method visitPathStep.
private TreeNode visitPathStep(PathStep step, TreeNode prev) {
String from = ReflectionUtils.getFieldValue(PathStep.class, step, "fromLabel");
String to = ReflectionUtils.getFieldValue(PathStep.class, step, "toLabel");
Set<String> keepLabels = ReflectionUtils.getFieldValue(PathStep.class, step, "keepLabels");
if (StringUtils.isNotEmpty(from) || StringUtils.isNotEmpty(to) || (null != keepLabels && keepLabels.size() > 0)) {
throw new UnsupportedOperationException("Not support from/to/keepLabels in path step");
}
PathTreeNode pathTreeNode = new PathTreeNode(prev, schema);
pathTreeNode.addPathRequirement();
pathTreeNode.getUsedLabelList().addAll(treeNodeLabelManager.getUserLabelList());
boolean savePathFlag = this.rootPathFlag;
this.rootPathFlag = false;
Set<SourceDelegateNode> ringSourceNodeList = Sets.newHashSet();
List<Traversal.Admin<?, ?>> traversalRingList = step.getLocalChildren();
List<TreeNode> ringTreeNodeList = Lists.newArrayList();
for (Traversal.Admin<?, ?> traversalAdmin : traversalRingList) {
SourceDelegateNode sourceDelegateNode = new SourceDelegateNode(pathTreeNode, schema);
ringSourceNodeList.add(sourceDelegateNode);
ringTreeNodeList.add(travelTraversalAdmin(traversalAdmin, sourceDelegateNode));
}
pathTreeNode.setRingTreeNodeList(ringTreeNodeList);
Set<String> propKeyList = pathTreeNode.getOutputPropList();
Set<ValueType> pathValueList = Sets.newHashSet();
processPathRequirement(pathTreeNode, propKeyList, pathValueList);
pathTreeNode.setPathValueList(pathValueList);
ringSourceNodeList.forEach(v -> {
if (pathValueList.size() > 1) {
v.setDelegateOutputValueType(new VarietyValueType(pathValueList));
} else {
v.setDelegateOutputValueType(pathValueList.iterator().next());
}
});
if (!propKeyList.isEmpty()) {
if (pathTreeNode.getInputNode() instanceof PropFillTreeNode) {
PropFillTreeNode propFillTreeNode = PropFillTreeNode.class.cast(pathTreeNode.getInputNode());
propFillTreeNode.getPropKeyList().addAll(propKeyList);
} else {
PropFillTreeNode propFillTreeNode = new PropFillTreeNode(prev, propKeyList, schema);
pathTreeNode.setInputNode(propFillTreeNode);
}
}
this.rootPathFlag = savePathFlag;
return pathTreeNode;
}
use of com.alibaba.maxgraph.compiler.tree.value.ValueType in project GraphScope by alibaba.
the class CompilerUtils method parseValueTypeWithPop.
/**
* Get the output value type with tree node list and pop
*
* @param treeNodeList The given tree node list
* @param pop The given pop
* @return The output value type
*/
public static ValueType parseValueTypeWithPop(List<TreeNode> treeNodeList, Pop pop) {
if (treeNodeList == null || treeNodeList.isEmpty()) {
return null;
}
if (pop == null) {
Set<ValueType> valueTypeSet = Sets.newHashSet();
treeNodeList.forEach(v -> valueTypeSet.add(v.getOutputValueType()));
List<ValueType> valueTypeList = Lists.newArrayList(valueTypeSet);
if (valueTypeList.size() == 1) {
return valueTypeList.get(0);
} else {
return new ListValueType(new VarietyValueType(valueTypeSet));
}
} else {
switch(pop) {
case first:
{
return treeNodeList.get(0).getOutputValueType();
}
case last:
{
return treeNodeList.get(treeNodeList.size() - 1).getOutputValueType();
}
default:
{
Set<ValueType> valueTypeSet = Sets.newHashSet();
treeNodeList.forEach(v -> valueTypeSet.add(v.getOutputValueType()));
return new ListValueType(valueTypeSet.size() == 1 ? Lists.newArrayList(valueTypeSet).get(0) : new VarietyValueType(valueTypeSet));
}
}
}
}
use of com.alibaba.maxgraph.compiler.tree.value.ValueType in project GraphScope by alibaba.
the class AggregationListTreeNode method getOutputValueType.
@Override
public ValueType getOutputValueType() {
Set<ValueType> aggValueList = Sets.newHashSet();
aggNodeList.forEach(v -> aggValueList.add(v.getOutputValueType()));
return new MapValueType(new ValueValueType(Message.VariantType.VT_STRING), aggValueList.size() > 1 ? new VarietyValueType(aggValueList) : aggValueList.iterator().next());
}
use of com.alibaba.maxgraph.compiler.tree.value.ValueType in project GraphScope by alibaba.
the class GroupTreeNode method getOutputValueType.
@Override
public ValueType getOutputValueType() {
ValueType keyValueType = null == keyTreeNode ? getInputNode().getOutputValueType() : keyTreeNode.getOutputValueType();
ValueType valueValueType = valueTreeNode.getOutputValueType();
return new MapValueType(keyValueType, valueValueType);
}
use of com.alibaba.maxgraph.compiler.tree.value.ValueType in project GraphScope by alibaba.
the class TreeBuilder method processPathRequirement.
private void processPathRequirement(TreeNode treeNode, Set<String> propKeyList, Set<ValueType> pathValueList) {
if (treeNode instanceof SourceDelegateNode) {
processPathRequirement(SourceDelegateNode.class.cast(treeNode).getDelegate(), propKeyList, pathValueList);
return;
}
if (treeNode instanceof SourceTreeNode || treeNode.getNodeType() == NodeType.AGGREGATE) {
return;
}
UnaryTreeNode unaryTreeNode = UnaryTreeNode.class.cast(treeNode);
if (treeNode instanceof RepeatTreeNode) {
RepeatTreeNode repeatTreeNode = RepeatTreeNode.class.cast(treeNode);
TreeNode repeatBodyTreeNode = repeatTreeNode.getRepeatBodyTreeNode();
processPathRequirement(repeatBodyTreeNode, propKeyList, pathValueList);
} else {
if (treeNode.isPathFlag()) {
treeNode.addPathRequirement();
if (treeNode instanceof PathTreeNode) {
((PathTreeNode) treeNode).disablePathDelete();
}
ValueType inputValueType = unaryTreeNode.getInputNode().getOutputValueType();
pathValueList.add(inputValueType);
if (null != propKeyList && !propKeyList.isEmpty() && inputValueType instanceof VertexValueType) {
if (unaryTreeNode.getInputNode() instanceof PropFillTreeNode) {
PropFillTreeNode propFillTreeNode = PropFillTreeNode.class.cast(unaryTreeNode.getInputNode());
propFillTreeNode.getPropKeyList().addAll(propKeyList);
} else {
PropFillTreeNode propFillTreeNode = new PropFillTreeNode(null, propKeyList, schema);
TreeNode inputTreeNode = unaryTreeNode.getInputNode();
unaryTreeNode.setInputNode(propFillTreeNode);
propFillTreeNode.setInputNode(inputTreeNode);
}
}
}
}
processPathRequirement(unaryTreeNode.getInputNode(), propKeyList, pathValueList);
}
Aggregations