|
10 | 10 | import org.postgresql.copy.CopyManager;
|
11 | 11 | import org.postgresql.core.BaseConnection;
|
12 | 12 | import org.postgresql.util.ByteConverter;
|
| 13 | +import org.postgresql.util.PGBinaryObject; |
13 | 14 |
|
14 | 15 | public class Example {
|
15 | 16 | public static void main(String[] args) throws SQLException {
|
@@ -50,13 +51,20 @@ public static void main(String[] args) throws SQLException {
|
50 | 51 | copyIn.writeToCopy(buffer, 0, 19);
|
51 | 52 |
|
52 | 53 | for (int i = 0; i < rows; i++) {
|
53 |
| - PGvector embedding = new PGvector(embeddings.get(i)); |
| 54 | + PGBinaryObject[] values = {new PGvector(embeddings.get(i))}; |
54 | 55 |
|
55 | 56 | // write row
|
56 |
| - ByteConverter.int2(buffer, 0, 1); |
57 |
| - ByteConverter.int4(buffer, 2, embedding.lengthInBytes()); |
58 |
| - embedding.toBytes(buffer, 6); |
59 |
| - copyIn.writeToCopy(buffer, 0, 6 + embedding.lengthInBytes()); |
| 57 | + ByteConverter.int2(buffer, 0, values.length); |
| 58 | + int pos = 2; |
| 59 | + for (int j = 0; j < values.length; j++) { |
| 60 | + PGBinaryObject value = values[j]; |
| 61 | + int len = value.lengthInBytes(); |
| 62 | + ByteConverter.int4(buffer, pos, len); |
| 63 | + pos += 4; |
| 64 | + value.toBytes(buffer, pos); |
| 65 | + pos += len; |
| 66 | + } |
| 67 | + copyIn.writeToCopy(buffer, 0, pos); |
60 | 68 |
|
61 | 69 | // show progress
|
62 | 70 | if (i % 10000 == 0) {
|
|
0 commit comments