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 a4bf84d
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 21 deletions.
Expand Up @@ -78,6 +78,7 @@ public class GradoopTestUtils {
public static final String KEY_c = "keyc";
public static final String KEY_d = "keyd";
public static final String KEY_e = "keye";
public static final String KEY_f = "keyf";

public static final Object NULL_VAL_0 = null;
public static final boolean BOOL_VAL_1 = true;
Expand Down
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
Expand Up @@ -73,21 +73,22 @@ private static Map<String, Object> getPropertyMap() {
objectMap.put(stringValue2, PropertyValue.create(67.89));

Map<String, Object> propertyMap = new HashMap<>();
propertyMap.put(GradoopTestUtils.KEY_0, GradoopTestUtils.BOOL_VAL_1);
propertyMap.put(GradoopTestUtils.KEY_1, GradoopTestUtils.INT_VAL_2);
propertyMap.put(GradoopTestUtils.KEY_2, GradoopTestUtils.LONG_VAL_3);
propertyMap.put(GradoopTestUtils.KEY_3, GradoopTestUtils.FLOAT_VAL_4);
propertyMap.put(GradoopTestUtils.KEY_4, GradoopTestUtils.DOUBLE_VAL_5);
propertyMap.put(GradoopTestUtils.KEY_5, GradoopTestUtils.STRING_VAL_6);
propertyMap.put(GradoopTestUtils.KEY_6, GradoopId.fromString("000000000000000000000001"));
propertyMap.put(GradoopTestUtils.KEY_7, localDate);
propertyMap.put(GradoopTestUtils.KEY_8, localTime);
propertyMap.put(GradoopTestUtils.KEY_9, LocalDateTime.of(localDate, localTime));
propertyMap.put(GradoopTestUtils.KEY_a, GradoopTestUtils.BIG_DECIMAL_VAL_7);
propertyMap.put(GradoopTestUtils.KEY_b, objectMap);
propertyMap.put(GradoopTestUtils.KEY_c, stringList);
propertyMap.put(GradoopTestUtils.KEY_d, intList);
propertyMap.put(GradoopTestUtils.KEY_e, GradoopTestUtils.SHORT_VAL_e);
propertyMap.put(GradoopTestUtils.KEY_0, GradoopTestUtils.NULL_VAL_0);
propertyMap.put(GradoopTestUtils.KEY_1, GradoopTestUtils.BOOL_VAL_1);
propertyMap.put(GradoopTestUtils.KEY_2, GradoopTestUtils.INT_VAL_2);
propertyMap.put(GradoopTestUtils.KEY_3, GradoopTestUtils.LONG_VAL_3);
propertyMap.put(GradoopTestUtils.KEY_4, GradoopTestUtils.FLOAT_VAL_4);
propertyMap.put(GradoopTestUtils.KEY_5, GradoopTestUtils.DOUBLE_VAL_5);
propertyMap.put(GradoopTestUtils.KEY_6, GradoopTestUtils.STRING_VAL_6);
propertyMap.put(GradoopTestUtils.KEY_7, GradoopId.fromString("000000000000000000000001"));
propertyMap.put(GradoopTestUtils.KEY_8, localDate);
propertyMap.put(GradoopTestUtils.KEY_9, localTime);
propertyMap.put(GradoopTestUtils.KEY_a, LocalDateTime.of(localDate, localTime));
propertyMap.put(GradoopTestUtils.KEY_b, GradoopTestUtils.BIG_DECIMAL_VAL_7);
propertyMap.put(GradoopTestUtils.KEY_c, objectMap);
propertyMap.put(GradoopTestUtils.KEY_d, stringList);
propertyMap.put(GradoopTestUtils.KEY_e, intList);
propertyMap.put(GradoopTestUtils.KEY_f, GradoopTestUtils.SHORT_VAL_e);
return Collections.unmodifiableMap(propertyMap);
}

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 a4bf84d

Please sign in to comment.