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 1 commit
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
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);
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;

List<Float> res = new ArrayList<>(array.size());
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;
}
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
8 changes: 8 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,14 @@ 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();
Assert.assertEquals(Arrays.asList(2.1f, -0.82f, 1.3f, 4.5f), r.getValue(0));
}

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