Skip to content

Commit b657d61

Browse files
committed
Support smaller integer arrays and scalars
and test more conversions
1 parent 8697312 commit b657d61

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

core/src/main/java/org/neo4j/gds/core/loading/GdsNeo4jValueConverter.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,13 @@ private static Array convertArrayValueOrFail(ArrayValue array) {
9191
return PrimitiveValues.EMPTY_LONG_ARRAY;
9292
}
9393
var arrayCopy = array.asObjectCopy();
94-
if (arrayCopy instanceof long[]) {
94+
if (arrayCopy instanceof byte[]) {
95+
return PrimitiveValues.byteArray((byte[]) arrayCopy);
96+
} else if (arrayCopy instanceof short[]) {
97+
return PrimitiveValues.shortArray((short[]) arrayCopy);
98+
} else if (arrayCopy instanceof int[]) {
99+
return PrimitiveValues.intArray((int[]) arrayCopy);
100+
} else if (arrayCopy instanceof long[]) {
95101
return PrimitiveValues.longArray((long[]) arrayCopy);
96102
} else if (arrayCopy instanceof double[]) {
97103
return PrimitiveValues.doubleArray((double[]) arrayCopy);

core/src/test/java/org/neo4j/gds/core/loading/GdsNeo4jValueConverterTest.java

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,70 @@
2020
package org.neo4j.gds.core.loading;
2121

2222
import org.junit.jupiter.api.Test;
23-
2423
import org.neo4j.gds.values.primitive.PrimitiveValues;
2524
import org.neo4j.values.storable.Values;
2625

2726
import static org.assertj.core.api.Assertions.assertThat;
2827

2928
class GdsNeo4jValueConverterTest {
29+
3030
@Test
3131
void shouldConvertFloatArray() {
3232
assertThat(GdsNeo4jValueConverter.toValue(Values.of(new float[]{1, -1})))
3333
.isEqualTo(PrimitiveValues.floatArray(new float[]{1, -1}));
3434
}
35+
36+
@Test
37+
void shouldConvertDoubleArray() {
38+
assertThat(GdsNeo4jValueConverter.toValue(Values.of(new double[]{1, -1})))
39+
.isEqualTo(PrimitiveValues.doubleArray(new double[]{1, -1}));
40+
}
41+
@Test
42+
void shouldConvertLongArray() {
43+
assertThat(GdsNeo4jValueConverter.toValue(Values.of(new long[]{1, -1})))
44+
.isEqualTo(PrimitiveValues.longArray(new long[]{1, -1}));
45+
}
46+
47+
@Test
48+
void shouldConvertIntArray() {
49+
assertThat(GdsNeo4jValueConverter.toValue(Values.of(new int[]{1, -1})))
50+
.isEqualTo(PrimitiveValues.intArray(new int[]{1, -1}));
51+
}
52+
53+
@Test
54+
void shouldConvertShortArray() {
55+
assertThat(GdsNeo4jValueConverter.toValue(Values.of(new short[]{1, -1})))
56+
.isEqualTo(PrimitiveValues.shortArray(new short[]{1, -1}));
57+
}
58+
59+
@Test
60+
void shouldConvertByteArray() {
61+
assertThat(GdsNeo4jValueConverter.toValue(Values.of(new byte[]{1, -1})))
62+
.isEqualTo(PrimitiveValues.byteArray(new byte[]{1, -1}));
63+
}
64+
65+
@Test
66+
void shouldConvertFloat() {
67+
assertThat(GdsNeo4jValueConverter.toValue(Values.of(1F)))
68+
.isEqualTo(PrimitiveValues.floatingPointValue(1F));
69+
}
70+
71+
@Test
72+
void shouldConvertDouble() {
73+
assertThat(GdsNeo4jValueConverter.toValue(Values.of(1D)))
74+
.isEqualTo(PrimitiveValues.floatingPointValue(1D));
75+
}
76+
77+
@Test
78+
void shouldConvertInt() {
79+
assertThat(GdsNeo4jValueConverter.toValue(Values.of(1)))
80+
.isEqualTo(PrimitiveValues.longValue(1));
81+
}
82+
83+
@Test
84+
void shouldConvertLong() {
85+
assertThat(GdsNeo4jValueConverter.toValue(Values.of(1L)))
86+
.isEqualTo(PrimitiveValues.longValue(1L));
87+
}
88+
3589
}

0 commit comments

Comments
 (0)