org.unipop.schema.property.ConcatenateFieldPropertySchema Maven / Gradle / Ivy
package org.unipop.schema.property;
import org.apache.tinkerpop.gremlin.process.traversal.P;
import org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer;
import org.json.JSONArray;
import org.json.JSONObject;
import org.unipop.query.predicates.PredicatesHolder;
import org.unipop.query.predicates.PredicatesHolderFactory;
import org.unipop.schema.property.type.PropertyType;
import org.unipop.util.PropertySchemaFactory;
import java.util.*;
import java.util.stream.Collectors;
public class ConcatenateFieldPropertySchema implements ParentSchemaProperty {
private final String key;
private final List schemas;
private String delimiter;
public ConcatenateFieldPropertySchema(String key, List schemas, String delimiter, boolean nullable) {
this.key = key;
this.schemas = schemas;
this.delimiter = delimiter;
}
@Override
public String getKey() {
return key;
}
@Override
public Map toProperties(Map source) {
StringJoiner values = new StringJoiner(delimiter);
for (PropertySchema schema : schemas) {
Map props = schema.toProperties(source);
if (props == null) values.add("null");
else if (props.size() == 0) return Collections.emptyMap();
else props.values().stream().map(Object::toString).forEach(values::add);
}
return Collections.singletonMap(key, values.toString());
}
@Override
public Collection getChildren() {
return schemas;
}
@Override
public Set excludeDynamicFields() {
return schemas.stream()
.map(PropertySchema::excludeDynamicFields)
.flatMap(Collection::stream).collect(Collectors.toSet());
}
@Override
public Set excludeDynamicProperties() {
return Collections.singleton(this.key);
}
@Override
public Map toFields(Map properties) {
// Object value = properties.get(this.key);
// if (value == null) return Collections.emptyMap();
// Map result = new HashMap<>(fields.size());
// String[] values = value.toString().split(delimiter);
// //TODO: what if values.length != fields.length ??? o_O
// for (int i = 0; i < fields.size(); i++) {
// result.put(fields.get(i), values[i]);
// }
// return result;
return Collections.emptyMap();
}
@Override
public Set toFields(Set propertyKeys) {
return schemas.stream().flatMap(s -> s.toFields(propertyKeys).stream()).collect(Collectors.toSet());
}
@Override
public Set
© 2015 - 2025 Weber Informatics LLC | Privacy Policy