apoc.load.Mapping Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of apoc-common Show documentation
Show all versions of apoc-common Show documentation
Data types package for Neo4j Procedures
package apoc.load;
import apoc.load.util.LoadCsvConfig;
import apoc.meta.Types;
import apoc.util.Util;
import org.apache.commons.lang3.StringUtils;
import org.neo4j.values.storable.DateTimeValue;
import org.neo4j.values.storable.DateValue;
import org.neo4j.values.storable.DurationValue;
import org.neo4j.values.storable.LocalDateTimeValue;
import org.neo4j.values.storable.LocalTimeValue;
import org.neo4j.values.storable.TimeValue;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Supplier;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import static apoc.ApocConfig.apocConfig;
import static apoc.util.Util.parseCharFromConfig;
import static java.util.Collections.emptyList;
import static org.neo4j.configuration.GraphDatabaseSettings.db_temporal_timezone;
public class Mapping {
public static final Mapping EMPTY = new Mapping("", Collections.emptyMap(), LoadCsvConfig.DEFAULT_ARRAY_SEP, false);
final String name;
final Collection nullValues;
final Types type;
final boolean array;
final boolean ignore;
final char arraySep;
private final Pattern arrayPattern;
private final Map optionalData;
public Mapping(String name, Map mapping, char arraySep, boolean ignore) {
this.name = mapping.getOrDefault("name", name).toString();
this.array = (Boolean) mapping.getOrDefault("array", false);
this.optionalData = (Map) mapping.get("optionalData");
this.ignore = (Boolean) mapping.getOrDefault("ignore", ignore);
this.nullValues = (Collection) mapping.getOrDefault("nullValues", emptyList());
this.arraySep = parseCharFromConfig(mapping, "arraySep", arraySep);
this.type = Types.from(mapping.getOrDefault("type", "STRING").toString());
this.arrayPattern = Pattern.compile(String.valueOf(this.arraySep), Pattern.LITERAL);
if (this.type == null) {
// Call this out to the user explicitly because deep inside of LoadCSV and others you will get
// NPEs that are hard to spot if this is allowed to go through.
throw new RuntimeException("In specified mapping, there is no type by the name " +
mapping.getOrDefault("type", "STRING").toString());
}
}
public Object convert(String value) {
return array ? convertArray(value) : convertType(value);
}
private Object convertArray(String value) {
String[] values = arrayPattern.split(value);
List
© 2015 - 2024 Weber Informatics LLC | Privacy Policy