Search in sources :

Example 1 with ValueType

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;
}
Also used : VarietyValueType(com.alibaba.maxgraph.compiler.tree.value.VarietyValueType) VertexValueType(com.alibaba.maxgraph.compiler.tree.value.VertexValueType) ListValueType(com.alibaba.maxgraph.compiler.tree.value.ListValueType) ValueValueType(com.alibaba.maxgraph.compiler.tree.value.ValueValueType) ValueType(com.alibaba.maxgraph.compiler.tree.value.ValueType) VarietyValueType(com.alibaba.maxgraph.compiler.tree.value.VarietyValueType) SourceDelegateNode(com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode) CustomAggregationListTraversal(com.alibaba.maxgraph.sdkcommon.compiler.custom.aggregate.CustomAggregationListTraversal) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) SourceTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode) EstimateCountTreeNode(com.alibaba.maxgraph.compiler.tree.source.EstimateCountTreeNode) SourceEdgeTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceEdgeTreeNode) SourceVertexTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceVertexTreeNode) SourceCreateGraphTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceCreateGraphTreeNode)

Example 2 with ValueType

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));
                }
        }
    }
}
Also used : AndP(org.apache.tinkerpop.gremlin.process.traversal.util.AndP) GraphSchema(com.alibaba.maxgraph.compiler.api.schema.GraphSchema) java.util(java.util) GraphVertex(com.alibaba.maxgraph.compiler.api.schema.GraphVertex) CompositeId(com.alibaba.maxgraph.sdkcommon.graph.CompositeId) Pop(org.apache.tinkerpop.gremlin.process.traversal.Pop) DataType(com.alibaba.maxgraph.compiler.api.schema.DataType) Contains(org.apache.tinkerpop.gremlin.process.traversal.Contains) StringUtils(org.apache.commons.lang3.StringUtils) QueryFlowOuterClass(com.alibaba.maxgraph.QueryFlowOuterClass) GraphEdge(com.alibaba.maxgraph.compiler.api.schema.GraphEdge) BiPredicate(java.util.function.BiPredicate) DimMatchType(com.alibaba.maxgraph.sdkcommon.compiler.custom.dim.DimMatchType) Lists(com.google.common.collect.Lists) Pair(org.apache.commons.lang3.tuple.Pair) OrP(org.apache.tinkerpop.gremlin.process.traversal.util.OrP) ListValueType(com.alibaba.maxgraph.compiler.tree.value.ListValueType) P(org.apache.tinkerpop.gremlin.process.traversal.P) Edge(org.apache.tinkerpop.gremlin.structure.Edge) LogicalEdge(com.alibaba.maxgraph.compiler.logical.LogicalEdge) HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer) DimPredicate(com.alibaba.maxgraph.sdkcommon.compiler.custom.dim.DimPredicate) Predicate(java.util.function.Predicate) com.alibaba.maxgraph.compiler.tree(com.alibaba.maxgraph.compiler.tree) GraphProperty(com.alibaba.maxgraph.compiler.api.schema.GraphProperty) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Message(com.alibaba.maxgraph.Message) T(org.apache.tinkerpop.gremlin.structure.T) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Compare(org.apache.tinkerpop.gremlin.process.traversal.Compare) InternalDataType(com.alibaba.maxgraph.sdkcommon.meta.InternalDataType) SchemaUtils(com.alibaba.maxgraph.sdkcommon.util.SchemaUtils) ValueType(com.alibaba.maxgraph.compiler.tree.value.ValueType) VarietyValueType(com.alibaba.maxgraph.compiler.tree.value.VarietyValueType) com.alibaba.maxgraph.sdkcommon.compiler.custom(com.alibaba.maxgraph.sdkcommon.compiler.custom) BranchStep(org.apache.tinkerpop.gremlin.process.traversal.step.branch.BranchStep) GraphElement(com.alibaba.maxgraph.compiler.api.schema.GraphElement) VarietyValueType(com.alibaba.maxgraph.compiler.tree.value.VarietyValueType) ListValueType(com.alibaba.maxgraph.compiler.tree.value.ListValueType) ValueType(com.alibaba.maxgraph.compiler.tree.value.ValueType) VarietyValueType(com.alibaba.maxgraph.compiler.tree.value.VarietyValueType) ListValueType(com.alibaba.maxgraph.compiler.tree.value.ListValueType)

Example 3 with ValueType

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());
}
Also used : VarietyValueType(com.alibaba.maxgraph.compiler.tree.value.VarietyValueType) ValueType(com.alibaba.maxgraph.compiler.tree.value.ValueType) VarietyValueType(com.alibaba.maxgraph.compiler.tree.value.VarietyValueType) MapValueType(com.alibaba.maxgraph.compiler.tree.value.MapValueType) ValueValueType(com.alibaba.maxgraph.compiler.tree.value.ValueValueType) MapValueType(com.alibaba.maxgraph.compiler.tree.value.MapValueType) ValueValueType(com.alibaba.maxgraph.compiler.tree.value.ValueValueType)

Example 4 with ValueType

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);
}
Also used : MapValueType(com.alibaba.maxgraph.compiler.tree.value.MapValueType) VertexValueType(com.alibaba.maxgraph.compiler.tree.value.VertexValueType) ValueType(com.alibaba.maxgraph.compiler.tree.value.ValueType) MapValueType(com.alibaba.maxgraph.compiler.tree.value.MapValueType)

Example 5 with ValueType

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);
}
Also used : VertexValueType(com.alibaba.maxgraph.compiler.tree.value.VertexValueType) VertexValueType(com.alibaba.maxgraph.compiler.tree.value.VertexValueType) ListValueType(com.alibaba.maxgraph.compiler.tree.value.ListValueType) ValueValueType(com.alibaba.maxgraph.compiler.tree.value.ValueValueType) ValueType(com.alibaba.maxgraph.compiler.tree.value.ValueType) VarietyValueType(com.alibaba.maxgraph.compiler.tree.value.VarietyValueType) SourceTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode) SourceTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode) EstimateCountTreeNode(com.alibaba.maxgraph.compiler.tree.source.EstimateCountTreeNode) SourceEdgeTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceEdgeTreeNode) SourceVertexTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceVertexTreeNode) SourceCreateGraphTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceCreateGraphTreeNode) SourceDelegateNode(com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode)

Aggregations

ValueType (com.alibaba.maxgraph.compiler.tree.value.ValueType)6 VarietyValueType (com.alibaba.maxgraph.compiler.tree.value.VarietyValueType)5 ListValueType (com.alibaba.maxgraph.compiler.tree.value.ListValueType)4 ValueValueType (com.alibaba.maxgraph.compiler.tree.value.ValueValueType)4 VertexValueType (com.alibaba.maxgraph.compiler.tree.value.VertexValueType)4 EstimateCountTreeNode (com.alibaba.maxgraph.compiler.tree.source.EstimateCountTreeNode)3 SourceCreateGraphTreeNode (com.alibaba.maxgraph.compiler.tree.source.SourceCreateGraphTreeNode)3 SourceDelegateNode (com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode)3 SourceEdgeTreeNode (com.alibaba.maxgraph.compiler.tree.source.SourceEdgeTreeNode)3 SourceTreeNode (com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode)3 SourceVertexTreeNode (com.alibaba.maxgraph.compiler.tree.source.SourceVertexTreeNode)3 Message (com.alibaba.maxgraph.Message)2 DataType (com.alibaba.maxgraph.compiler.api.schema.DataType)2 GraphSchema (com.alibaba.maxgraph.compiler.api.schema.GraphSchema)2 MapValueType (com.alibaba.maxgraph.compiler.tree.value.MapValueType)2 CustomAggregationListTraversal (com.alibaba.maxgraph.sdkcommon.compiler.custom.aggregate.CustomAggregationListTraversal)2 SchemaUtils (com.alibaba.maxgraph.sdkcommon.util.SchemaUtils)2 QueryFlowOuterClass (com.alibaba.maxgraph.QueryFlowOuterClass)1 GraphEdge (com.alibaba.maxgraph.compiler.api.schema.GraphEdge)1 GraphElement (com.alibaba.maxgraph.compiler.api.schema.GraphElement)1