Search in sources :

Example 1 with PredicateType

use of com.alibaba.maxgraph.sdkcommon.compiler.custom.PredicateType in project GraphScope by alibaba.

the class TreeBuilder method convertHasContainer.

private HasContainer convertHasContainer(String key, Predicate<?> predicate, ValueType inputValueType) {
    if (null == predicate) {
        return new HasContainer(key, null);
    }
    if (predicate instanceof CustomPredicate) {
        if (StringUtils.isEmpty(key)) {
            checkArgument(inputValueType instanceof ListValueType || inputValueType instanceof ValueValueType, "Output value for predicate must be value while current type=>" + inputValueType);
            PredicateType predicateType = ((CustomPredicate) predicate).getPredicateType();
            Message.VariantType variantType = inputValueType instanceof ListValueType ? Message.VariantType.valueOf(ValueValueType.class.cast(((ListValueType) inputValueType).getListValue()).getDataType().name() + "_LIST") : ValueValueType.class.cast(inputValueType).getDataType();
            validPredicateVariantType(variantType, predicateType);
            return new HasContainer(key, CustomPredicate.class.cast(predicate));
        } else {
            Set<DataType> dataTypeSet = SchemaUtils.getPropDataTypeList(key, schema);
            if (dataTypeSet.isEmpty()) {
                return new HasContainer(key, CustomPredicate.class.cast(predicate));
            } else {
                if (dataTypeSet.size() > 1) {
                    logger.warn("There's multiple type=>" + dataTypeSet + " for property=>" + key);
                    return new HasContainer(key, CustomPredicate.class.cast(predicate));
                } else {
                    Message.VariantType variantType = CompilerUtils.parseVariantFromDataType(dataTypeSet.iterator().next());
                    PredicateType predicateType = ((CustomPredicate) predicate).getPredicateType();
                    validPredicateVariantType(variantType, predicateType);
                    return new HasContainer(key, CustomPredicate.class.cast(predicate));
                }
            }
        }
    } else {
        if (StringUtils.isEmpty(key)) {
            Message.VariantType variantType = ValueValueType.class.cast(inputValueType).getDataType();
            return createContainerFromVariantyType(key, P.class.cast(predicate), variantType);
        } else {
            Set<DataType> dataTypeSet = SchemaUtils.getPropDataTypeList(key, schema);
            if (dataTypeSet.isEmpty()) {
                return new HasContainer(key, P.class.cast(predicate));
            } else {
                if (dataTypeSet.size() > 1) {
                    logger.warn("There's multiple type=>" + dataTypeSet + " for property=>" + key);
                    return new HasContainer(key, P.class.cast(predicate));
                } else {
                    Message.VariantType variantType = CompilerUtils.parseVariantFromDataType(dataTypeSet.iterator().next());
                    return createContainerFromVariantyType(key, P.class.cast(predicate), variantType);
                }
            }
        }
    }
}
Also used : P(org.apache.tinkerpop.gremlin.process.traversal.P) ConnectiveP(org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP) Message(com.alibaba.maxgraph.Message) PredicateType(com.alibaba.maxgraph.sdkcommon.compiler.custom.PredicateType) HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer) ListValueType(com.alibaba.maxgraph.compiler.tree.value.ListValueType) DataType(com.alibaba.maxgraph.compiler.api.schema.DataType) CustomPredicate(com.alibaba.maxgraph.sdkcommon.compiler.custom.CustomPredicate) ValueValueType(com.alibaba.maxgraph.compiler.tree.value.ValueValueType)

Aggregations

Message (com.alibaba.maxgraph.Message)1 DataType (com.alibaba.maxgraph.compiler.api.schema.DataType)1 ListValueType (com.alibaba.maxgraph.compiler.tree.value.ListValueType)1 ValueValueType (com.alibaba.maxgraph.compiler.tree.value.ValueValueType)1 CustomPredicate (com.alibaba.maxgraph.sdkcommon.compiler.custom.CustomPredicate)1 PredicateType (com.alibaba.maxgraph.sdkcommon.compiler.custom.PredicateType)1 P (org.apache.tinkerpop.gremlin.process.traversal.P)1 HasContainer (org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer)1 ConnectiveP (org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP)1