Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for new Vector type #74

Merged
merged 4 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .sdkmanrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Enable auto-env through the sdkman_auto_env config
# Add key=value pairs of SDKs to use below
java=17.0.12-graal
12 changes: 12 additions & 0 deletions src/main/java/com/falkordb/impl/resultset/ResultSetImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@
return deserializeMap(obj);
case VALUE_POINT:
return deserializePoint(obj);
case VALUE_VECTORF32:
return deserializeVector(obj);

Check warning on line 250 in src/main/java/com/falkordb/impl/resultset/ResultSetImpl.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/falkordb/impl/resultset/ResultSetImpl.java#L250

Added line #L250 was not covered by tests
case VALUE_UNKNOWN:
default:
return obj;
Expand All @@ -256,6 +258,16 @@
return new Point(BuilderFactory.DOUBLE_LIST.build(rawScalarData));
}

private List<Float> deserializeVector(Object rawScalarData) {
List<byte[]> array = (List<byte[]>) rawScalarData;

Check warning on line 262 in src/main/java/com/falkordb/impl/resultset/ResultSetImpl.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/falkordb/impl/resultset/ResultSetImpl.java#L262

Added line #L262 was not covered by tests

List<Float> res = new ArrayList<>(array.size());

Check warning on line 264 in src/main/java/com/falkordb/impl/resultset/ResultSetImpl.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/falkordb/impl/resultset/ResultSetImpl.java#L264

Added line #L264 was not covered by tests
for (byte[] val : array) {
res.add(Float.parseFloat(SafeEncoder.encode(val)));
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Show resolved Hide resolved
gkorland marked this conversation as resolved.
Show resolved Hide resolved
gkorland marked this conversation as resolved.
Show resolved Hide resolved
}
return res;

Check warning on line 268 in src/main/java/com/falkordb/impl/resultset/ResultSetImpl.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/falkordb/impl/resultset/ResultSetImpl.java#L266-L268

Added lines #L266 - L268 were not covered by tests
}
gkorland marked this conversation as resolved.
Show resolved Hide resolved

@SuppressWarnings("unchecked")
private Map<String, Object> deserializeMap(Object rawScalarData) {
List<Object> keyTypeValueEntries = (List<Object>) rawScalarData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ enum ResultSetScalarTypes {
VALUE_NODE,
VALUE_PATH,
VALUE_MAP,
VALUE_POINT;
VALUE_POINT,
VALUE_VECTORF32;
gkorland marked this conversation as resolved.
Show resolved Hide resolved

private static final ResultSetScalarTypes[] values = values();

Expand Down
13 changes: 13 additions & 0 deletions src/test/java/com/falkordb/GraphAPITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,19 @@ public void test64bitnumber() {
Assert.assertEquals(Long.valueOf(value), r.getValue(0));
}

@Test
public void testVecf32() {
ResultSet resultSet = client.query("RETURN vecf32([2.1, -0.82, 1.3, 4.5]) AS vector");
Assert.assertEquals(1, resultSet.size());
Record r = resultSet.iterator().next();
List<Double> vector = r.getValue(0);
Assert.assertEquals(4, vector.size());
Assert.assertEquals(2.1f, vector.get(0), 0.01);
Assert.assertEquals(-0.82f, vector.get(1), 0.01);
Assert.assertEquals(1.3f, vector.get(2), 0.01);
Assert.assertEquals(4.5f, vector.get(3), 0.01);
}

@Test
public void testCachedExecution() {
client.query("CREATE (:N {val:1}), (:N {val:2})");
Expand Down