use of com.alibaba.maxgraph.compiler.tree.value.VarietyValueType 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.VarietyValueType 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.VarietyValueType 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.VarietyValueType in project GraphScope by alibaba.
the class TreeBuilder method visitSelectStep.
private TreeNode visitSelectStep(SelectStep step, TreeNode prev) {
List<String> selectKeyList = ReflectionUtils.getFieldValue(SelectStep.class, step, "selectKeys");
Pop pop = step.getPop();
List<Traversal.Admin<?, ?>> ringTraversalList = step.getLocalChildren();
if (selectKeyList.size() < 2) {
throw new IllegalArgumentException("select key size < 2 for select operator");
}
Map<String, List<TreeNode>> labelTreeNodeList = Maps.newHashMap();
selectKeyList.forEach(v -> {
if (treeNodeLabelManager.getLabelIndexList().containsKey(v)) {
labelTreeNodeList.put(v, treeNodeLabelManager.getTreeNodeList(v));
}
});
SelectTreeNode selectTreeNode = new SelectTreeNode(prev, selectKeyList, pop, labelTreeNodeList, schema);
boolean saveFlag = rootPathFlag;
rootPathFlag = false;
if (!ringTraversalList.isEmpty()) {
Set<ValueType> valueTypeList = selectKeyList.stream().map(v -> treeNodeLabelManager.getValueType(v, pop)).collect(Collectors.toSet());
ValueType selectValueType = valueTypeList.size() > 1 ? new VarietyValueType(valueTypeList) : valueTypeList.iterator().next();
ringTraversalList.forEach(v -> {
SourceDelegateNode sourceDelegateNode = new SourceDelegateNode(selectTreeNode, schema);
sourceDelegateNode.setDelegateOutputValueType(selectValueType);
selectTreeNode.addTraversalTreeNode(travelTraversalAdmin(v, sourceDelegateNode));
});
}
rootPathFlag = saveFlag;
return selectTreeNode;
}
Aggregations