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 vector support #220

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions src/main/proto/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ message Value {
bytes datetime_val = 9;
string password_val = 10;
uint64 uid_val=11;
// number 12 is reserved for bigfloat
bytes vfloat32_val=13;
}
}

Expand Down
40 changes: 40 additions & 0 deletions src/test/java/io/dgraph/ExceptionTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package io.dgraph;

import com.google.protobuf.ByteString;
import io.dgraph.DgraphProto.Mutation;
import io.dgraph.DgraphProto.NQuad;
import io.dgraph.DgraphProto.Response;
import io.dgraph.DgraphProto.Value;
import org.testng.annotations.Test;

Expand Down Expand Up @@ -37,4 +39,42 @@ public void testReadOnlyException() {
Transaction txn = dgraphClient.newReadOnlyTransaction();
txn.mutate(mu);
}

@Test
public void testVectorSupport() {
String vect = "[1, 2, 3, 4, 5]";
NQuad quad1 =
NQuad.newBuilder()
.setSubject("0x1000")
.setPredicate("productV")
.setObjectValue(
Value.newBuilder().setVfloat32Val(ByteString.copyFromUtf8(vect)).build())
.build();

System.out.println("quad1: " + quad1.toString());
Mutation mu1 = Mutation.newBuilder().addSet(quad1).build();
Transaction txn = dgraphClient.newTransaction();
Response response1 = txn.mutate(mu1);
System.out.printf("response:---------------------------> " + response1.toString());
try {
txn.commit();
} catch (Exception e) {
System.out.printf("response------------exe: " + e.toString());
}

String query =
"{\n" + " q(func: has(productV)) {\n" + " uid\n" + " productV\n" + " }\n" + "}";

// Create a transaction
Transaction txn1 = dgraphClient.newTransaction();
try {
// Run the query
DgraphProto.Response response = txn1.query(query);

// Print the response JSON
System.out.println(response.getJson().toStringUtf8());
} catch (Exception e) {
System.out.println(e.toString());
}
}
}
Loading