Skip to content

Commit

Permalink
'dbs-leipzig#877 added support for property value null'
Browse files Browse the repository at this point in the history
  • Loading branch information
2start committed Jul 26, 2018
1 parent 68efc3d commit 1694715
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 6 deletions.
Expand Up @@ -77,6 +77,7 @@ private static Map<String, Function<String, Object>> getTypeParserMap() {
map.put(TypeString.LOCALDATE.getTypeString(), LocalDate::parse);
map.put(TypeString.LOCALTIME.getTypeString(), LocalTime::parse);
map.put(TypeString.LOCALDATETIME.getTypeString(), LocalDateTime::parse);
map.put(TypeString.NULL.getTypeString(), MetaDataParser::parseNullProperty);
return Collections.unmodifiableMap(map);
}

Expand Down Expand Up @@ -284,14 +285,31 @@ private static Object parseMapProperty(
.collect(Collectors.toMap(e -> PropertyValue.create(e[0]), e -> PropertyValue.create(e[1])));
}

/**
* Parse function to create null from the null string representation.
*
* @param nullString The string representing null.
* @throws IllegalArgumentException The string that is passed has to represent null.
* @return Returns null
*/
private static Object parseNullProperty(String nullString) throws IllegalArgumentException {
if (nullString != null && nullString.equalsIgnoreCase("null")) {
return null;
} else {
throw new IllegalArgumentException("Only null represents a null string.");
}
}

/**
* Returns the type string for the specified property value.
*
* @param propertyValue property value
* @return property type string
*/
public static String getTypeString(PropertyValue propertyValue) {
if (propertyValue.isShort()) {
if (propertyValue.isNull()) {
return TypeString.NULL.getTypeString();
} else if (propertyValue.isShort()) {
return TypeString.SHORT.getTypeString();
} else if (propertyValue.isInt()) {
return TypeString.INTEGER.getTypeString();
Expand Down Expand Up @@ -336,6 +354,10 @@ public static String getTypeString(PropertyValue propertyValue) {
* Supported type strings for the CSV format.
*/
private enum TypeString {
/**
* Null type
*/
NULL("null"),
/**
* Boolean type
*/
Expand Down
@@ -1,5 +1,5 @@
expected [
(v0:A {a:"foo",b:42,c:13.37f})-[e0:a {a:1234,b:13.37f}]->(v1:A {a:"bar",b:23,c:19.84f}),
(v0:A {a:"foo",b:42,c:13.37f, d: NULL})-[e0:a {a:1234,b:13.37f}]->(v1:A {a:"bar",b:23,c:19.84f}),
(v1)-[e1:a {a:5678,b:23.42f}]->(v0),
(v1)-[e2:b {a:3141L}]->(v2:B {a:1234L,b:true,c:0.123d}),
(v2)-[e3:b {a:2718L}]->(v3:B {a:5678L,b:false,c:4.123d}),
Expand Down
@@ -1,4 +1,4 @@
v;A;a:string,b:int,c:float
v;A;a:string,b:int,c:float,d:null
v;B;a:long,b:boolean,c:double
e;a;a:int,b:float
e;b;a:long
@@ -1,4 +1,4 @@
000000000000000000000000;A;foo|42|13.37
000000000000000000000000;A;foo|42|13.37|null
000000000000000000000001;A;bar|23|19.84
000000000000000000000002;B;1234|true|0.123
000000000000000000000003;B;5678|false|4.123
Expand Down
@@ -1,4 +1,4 @@
v;A;a:string,b:int,c:float
v;A;a:string,b:int,c:float,d:null
v;B;a:long,b:boolean,c:double
e;a;a:int,b:float
e;b;a:long
@@ -1,2 +1,2 @@
000000000000000000000000;A;foo|42|13.37
000000000000000000000000;A;foo|42|13.37|null
000000000000000000000001;A;bar|23|19.84

0 comments on commit 1694715

Please sign in to comment.