Skip to content

Commit 76f212a

Browse files
authored
fix: add support for LSM sparse vector type in BoltNetworkExecutor (ArcadeData#4079)
1 parent 95c57ba commit 76f212a

2 files changed

Lines changed: 47 additions & 19 deletions

File tree

bolt/src/main/java/com/arcadedb/bolt/BoltNetworkExecutor.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@
4141
import com.arcadedb.index.Index;
4242
import com.arcadedb.index.TypeIndex;
4343
import com.arcadedb.log.LogManager;
44+
import com.arcadedb.query.sql.executor.Result;
45+
import com.arcadedb.query.sql.executor.ResultSet;
4446
import com.arcadedb.schema.DocumentType;
4547
import com.arcadedb.schema.EdgeType;
4648
import com.arcadedb.schema.Property;
4749
import com.arcadedb.schema.Schema;
4850
import com.arcadedb.schema.VertexType;
49-
import com.arcadedb.query.sql.executor.Result;
50-
import com.arcadedb.query.sql.executor.ResultSet;
5151
import com.arcadedb.server.ArcadeDBServer;
5252
import com.arcadedb.server.security.ServerSecurityException;
5353
import com.arcadedb.server.security.ServerSecurityUser;
@@ -252,9 +252,9 @@ private boolean performHandshake() throws IOException {
252252
if (magic[0] == 0x16 && magic[1] == 0x03)
253253
LogManager.instance().log(this, Level.WARNING,
254254
"""
255-
TLS/SSL connection attempted on BOLT port but TLS is disabled. \
256-
Configure arcadedb.bolt.ssl=OPTIONAL or REQUIRED to enable TLS, \
257-
or use bolt:// (unencrypted) on the client""");
255+
TLS/SSL connection attempted on BOLT port but TLS is disabled. \
256+
Configure arcadedb.bolt.ssl=OPTIONAL or REQUIRED to enable TLS, \
257+
or use bolt:// (unencrypted) on the client""");
258258
else
259259
LogManager.instance().log(this, Level.WARNING,
260260
"Invalid BOLT magic bytes: [%d, %d, %d, %d]", magic[0], magic[1], magic[2], magic[3]);
@@ -1083,7 +1083,8 @@ private boolean handleSystemQuery(final String query) throws IOException {
10831083
|| normalized.startsWith("show point index")
10841084
|| normalized.startsWith("show lookup index")
10851085
|| normalized.startsWith("show fulltext index")
1086-
|| normalized.startsWith("show vector index")) {
1086+
|| normalized.startsWith("show vector index")
1087+
|| normalized.startsWith("show sparse_vector index")) {
10871088
// SHOW INDEXES / SHOW ... INDEXES - list indexes from ArcadeDB schema
10881089
currentFields = List.of("id", "name", "state", "populationPercent", "type", "entityType",
10891090
"labelsOrTypes", "properties", "indexProvider", "owningConstraint", "lastRead", "readCount");
@@ -1266,6 +1267,7 @@ private static String mapIndexTypeToNeo4j(final Schema.INDEX_TYPE type) {
12661267
case HASH -> "HASH";
12671268
case FULL_TEXT -> "FULLTEXT";
12681269
case LSM_VECTOR -> "VECTOR";
1270+
case LSM_SPARSE_VECTOR -> "SPARSE_VECTOR";
12691271
case GEOSPATIAL -> "POINT";
12701272
};
12711273
}
@@ -1278,6 +1280,7 @@ private static String mapIndexTypeToProvider(final Schema.INDEX_TYPE type) {
12781280
case HASH -> "hash-1.0";
12791281
case FULL_TEXT -> "fulltext-1.0";
12801282
case LSM_VECTOR -> "vector-2.0";
1283+
case LSM_SPARSE_VECTOR -> "sparse-vector-2.0";
12811284
case GEOSPATIAL -> "point-1.0";
12821285
};
12831286
}
@@ -1295,6 +1298,8 @@ private static boolean indexTypeMatchesFilter(final String filter, final String
12951298
return "FULLTEXT".equals(neoType);
12961299
if (filter.startsWith("show vector index"))
12971300
return "VECTOR".equals(neoType);
1301+
if (filter.startsWith("show sparse_vector index"))
1302+
return "SPARSE_VECTOR".equals(neoType);
12981303
return true;
12991304
}
13001305

bolt/src/test/java/com/arcadedb/bolt/BoltProtocolIT.java

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,21 @@
2323
import com.arcadedb.schema.Schema;
2424
import com.arcadedb.schema.Type;
2525
import com.arcadedb.test.BaseGraphServerTest;
26-
2726
import org.assertj.core.data.Offset;
2827
import org.junit.jupiter.api.AfterEach;
2928
import org.junit.jupiter.api.Test;
30-
import org.neo4j.driver.*;
29+
import org.neo4j.driver.AuthTokens;
30+
import org.neo4j.driver.Config;
31+
import org.neo4j.driver.Driver;
32+
import org.neo4j.driver.GraphDatabase;
33+
import org.neo4j.driver.Record;
34+
import org.neo4j.driver.Result;
35+
import org.neo4j.driver.Session;
36+
import org.neo4j.driver.SessionConfig;
37+
import org.neo4j.driver.Transaction;
38+
import org.neo4j.driver.Values;
3139
import org.neo4j.driver.exceptions.ClientException;
3240
import org.neo4j.driver.summary.ResultSummary;
33-
import org.neo4j.driver.Values;
3441

3542
import java.io.BufferedReader;
3643
import java.io.DataInputStream;
@@ -44,20 +51,18 @@
4451
import java.nio.ByteBuffer;
4552
import java.nio.charset.StandardCharsets;
4653
import java.security.MessageDigest;
47-
import java.util.Base64;
48-
import java.util.concurrent.CompletableFuture;
49-
import java.util.concurrent.CompletionStage;
50-
import java.util.concurrent.TimeUnit;
5154
import java.util.ArrayList;
55+
import java.util.Base64;
5256
import java.util.HashMap;
5357
import java.util.List;
5458
import java.util.Map;
59+
import java.util.concurrent.CompletableFuture;
60+
import java.util.concurrent.CompletionStage;
61+
import java.util.concurrent.TimeUnit;
5562

5663
import static org.assertj.core.api.Assertions.assertThat;
5764
import static org.assertj.core.api.Assertions.assertThatThrownBy;
5865

59-
import org.neo4j.driver.Record;
60-
6166
/**
6267
* Integration tests for BOLT protocol using Neo4j Java driver.
6368
*/
@@ -161,7 +166,8 @@ void createAndMatchEdge() {
161166
session.run("CREATE (a:EdgePerson {name: 'EdgeAlice'}), (b:EdgePerson {name: 'EdgeBob'})");
162167

163168
// Create edge
164-
session.run("MATCH (a:EdgePerson {name: 'EdgeAlice'}), (b:EdgePerson {name: 'EdgeBob'}) CREATE (a)-[:KNOWS {since: 2020}]->(b)");
169+
session.run(
170+
"MATCH (a:EdgePerson {name: 'EdgeAlice'}), (b:EdgePerson {name: 'EdgeBob'}) CREATE (a)-[:KNOWS {since: 2020}]->(b)");
165171

166172
// Query edge
167173
final Result result = session.run(
@@ -877,7 +883,8 @@ void concurrentSessions() throws Exception {
877883

878884
// Check for errors
879885
if (!errors.isEmpty()) {
880-
throw new AssertionError("Concurrent test failed with " + errors.size() + " errors: " + errors.get(0).getMessage(), errors.get(0));
886+
throw new AssertionError("Concurrent test failed with " + errors.size() + " errors: " + errors.get(0).getMessage(),
887+
errors.get(0));
881888
}
882889
}
883890

@@ -957,7 +964,8 @@ void largeParameterMap() {
957964
// Build a query that uses all parameters
958965
StringBuilder query = new StringBuilder("RETURN ");
959966
for (int i = 0; i < 50; i++) {
960-
if (i > 0) query.append(" + ");
967+
if (i > 0)
968+
query.append(" + ");
961969
query.append("$param").append(i);
962970
}
963971
query.append(" AS sum");
@@ -1103,7 +1111,8 @@ void httpDiscoveryOnBoltPort() throws Exception {
11031111
@Test
11041112
void systemDatabaseDbmsComponents() {
11051113
// Neo4j Desktop queries the "system" database for version info
1106-
try (final Driver driver = GraphDatabase.driver("bolt://localhost:7687", AuthTokens.basic("root", DEFAULT_PASSWORD_FOR_TESTS))) {
1114+
try (final Driver driver = GraphDatabase.driver("bolt://localhost:7687",
1115+
AuthTokens.basic("root", DEFAULT_PASSWORD_FOR_TESTS))) {
11071116
try (final Session session = driver.session(SessionConfig.forDatabase("system"))) {
11081117
final var result = session.run("CALL dbms.components()");
11091118
assertThat(result.hasNext()).isTrue();
@@ -1615,4 +1624,18 @@ void showVectorIndexesReturnsEmptyWithoutVectorIndexes() {
16151624
}
16161625
}
16171626
}
1627+
1628+
@Test
1629+
void showSparseVectorIndexesReturnsEmptyWithoutSparseVectorIndexes() {
1630+
try (Driver driver = getDriver()) {
1631+
try (Session session = driver.session(SessionConfig.forDatabase(getDatabaseName()))) {
1632+
final Result result = session.run("SHOW SPARSE_VECTOR INDEXES");
1633+
assertThat(result.keys()).containsExactly("id", "name", "state", "populationPercent", "type",
1634+
"entityType", "labelsOrTypes", "properties", "indexProvider", "owningConstraint", "lastRead", "readCount");
1635+
final List<Record> rows = result.list();
1636+
for (final Record r : rows)
1637+
assertThat(r.get("type").asString()).isEqualTo("SPARSE_VECTOR");
1638+
}
1639+
}
1640+
}
16181641
}

0 commit comments

Comments
 (0)