Search in sources :

Example 1 with PropertyDefNotFoundException

use of com.alibaba.maxgraph.compiler.api.exception.PropertyDefNotFoundException in project GraphScope by alibaba.

the class DataBuildMapper method buildPropertiesMap.

private Map<Integer, PropertyValue> buildPropertiesMap(GraphElement typeDef, String[] items, Map<Integer, Integer> columnMapping) {
    Map<Integer, PropertyValue> operationProperties = new HashMap<>(columnMapping.size());
    columnMapping.forEach((colIdx, propertyId) -> {
        GraphProperty propertyDef = typeDef.getProperty(propertyId);
        if (propertyDef == null) {
            throw new PropertyDefNotFoundException("property [" + propertyId + "] not found in [" + typeDef.getLabel() + "]");
        }
        if (colIdx >= items.length) {
            throw new IllegalArgumentException("label [" + typeDef.getLabel() + "], invalid mapping [" + colIdx + "] -> [" + propertyId + "], data [" + items + "]");
        }
        DataType dataType = propertyDef.getDataType();
        String val = items[colIdx];
        if (ldbcCustomize) {
            String name = propertyDef.getName();
            switch(name) {
                case "creationDate":
                case "joinDate":
                    val = converteDate(val);
                    break;
                case "birthday":
                    val = val.replace("-", "");
                    break;
            }
        }
        PropertyValue propertyValue = new PropertyValue(dataType, val);
        operationProperties.put(propertyId, propertyValue);
    });
    return operationProperties;
}
Also used : PropertyValue(com.alibaba.maxgraph.sdkcommon.schema.PropertyValue) PropertyDefNotFoundException(com.alibaba.maxgraph.compiler.api.exception.PropertyDefNotFoundException)

Example 2 with PropertyDefNotFoundException

use of com.alibaba.maxgraph.compiler.api.exception.PropertyDefNotFoundException in project GraphScope by alibaba.

the class GraphWriter method parseRawProperties.

public static Map<Integer, PropertyValue> parseRawProperties(GraphElement graphElement, Map<String, Object> properties) {
    Map<Integer, PropertyValue> res = new HashMap<>();
    if (properties != null) {
        properties.forEach((propertyName, valString) -> {
            GraphProperty propertyDef = graphElement.getProperty(propertyName);
            if (propertyDef == null) {
                throw new PropertyDefNotFoundException("property [" + propertyName + "] not found in [" + graphElement.getLabel() + "]");
            }
            int id = propertyDef.getId();
            DataType dataType = propertyDef.getDataType();
            PropertyValue propertyValue = new PropertyValue(dataType, valString);
            res.put(id, propertyValue);
        });
    }
    return res;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GraphProperty(com.alibaba.maxgraph.compiler.api.schema.GraphProperty) HashMap(java.util.HashMap) PropertyValue(com.alibaba.maxgraph.sdkcommon.schema.PropertyValue) DataType(com.alibaba.maxgraph.compiler.api.schema.DataType) PropertyDefNotFoundException(com.alibaba.maxgraph.compiler.api.exception.PropertyDefNotFoundException)

Aggregations

PropertyDefNotFoundException (com.alibaba.maxgraph.compiler.api.exception.PropertyDefNotFoundException)2 PropertyValue (com.alibaba.maxgraph.sdkcommon.schema.PropertyValue)2 DataType (com.alibaba.maxgraph.compiler.api.schema.DataType)1 GraphProperty (com.alibaba.maxgraph.compiler.api.schema.GraphProperty)1 HashMap (java.util.HashMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1