use of com.baidu.hugegraph.loader.source.file.ListFormat in project incubator-hugegraph-toolchain by apache.
the class GraphService method fillProperties.
private void fillProperties(int connId, SchemaLabelEntity schema, GraphElement element, Map<String, Object> properties) {
HugeClient client = this.client(connId);
for (Map.Entry<String, Object> entry : properties.entrySet()) {
String key = entry.getKey();
Object rawValue = entry.getValue();
// Skip nullable property
if (schema.getNullableProps().contains(key)) {
if (rawValue instanceof String && StringUtils.isEmpty((String) rawValue)) {
continue;
}
}
PropertyKeyEntity pkEntity = this.pkService.get(key, connId);
PropertyKey propertyKey = PropertyKeyService.convert(pkEntity, client);
assert propertyKey != null;
Object value;
try {
// DataTypeUtil.convert in loader need param InputSource
FileSource source = new FileSource();
ListFormat listFormat = new ListFormat("", "", ",");
source.listFormat(listFormat);
value = DataTypeUtil.convert(rawValue, propertyKey, source);
} catch (IllegalArgumentException e) {
throw new ExternalException("graph.property.convert.failed", e, key, rawValue);
}
element.property(key, value);
}
}
use of com.baidu.hugegraph.loader.source.file.ListFormat in project incubator-hugegraph-toolchain by apache.
the class DataTypeUtil method split.
private static List<Object> split(String key, String rawValue, InputSource source) {
List<Object> valueColl = new ArrayList<>();
if (rawValue.isEmpty()) {
return valueColl;
}
E.checkState(AbstractSource.class.isAssignableFrom(source.getClass()), "Only accept AbstractSource when parse multi values, " + "but got '%s'", source.getClass().getName());
ListFormat listFormat = ((AbstractSource) source).listFormat();
E.checkArgumentNotNull(listFormat, "The list_format must be set when " + "parse list or set values");
String startSymbol = listFormat.startSymbol();
String endSymbol = listFormat.endSymbol();
E.checkArgument(rawValue.length() >= startSymbol.length() + endSymbol.length(), "The value(key='%s') '%s' length(%s) must be >= " + "start symbol '%s' + end symbol '%s' length", key, rawValue, rawValue.length(), startSymbol, endSymbol);
E.checkArgument(rawValue.startsWith(startSymbol) && rawValue.endsWith(endSymbol), "The value(key='%s') must start with '%s' and " + "end with '%s', but got '%s'", key, startSymbol, endSymbol, rawValue);
rawValue = rawValue.substring(startSymbol.length(), rawValue.length() - endSymbol.length());
String elemDelimiter = listFormat.elemDelimiter();
Splitter.on(elemDelimiter).split(rawValue).forEach(value -> {
if (!listFormat.ignoredElems().contains(value)) {
valueColl.add(value);
}
});
return valueColl;
}
Aggregations