Skip to content

Commit 9247626

Browse files
authored
#3811 remove Cypher support from gremlin (#3814)
1 parent f642bb9 commit 9247626

16 files changed

Lines changed: 98 additions & 1887 deletions

File tree

e2e-python/tests/test_arcadedb.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def test_psycopg2_with_named_parameterized_cypher_query():
224224
try:
225225
with conn.cursor() as cursor:
226226
query_params = {'name': 'Stout', 'brewery_id': 350}
227-
cursor.execute('{cypher} MATCH (b:Beer) WHERE b.name =%(name)s AND b.brewery_id = %(brewery_id)s RETURN b', query_params)
227+
cursor.execute('{opencypher} MATCH (b:Beer) WHERE b.name =%(name)s AND b.brewery_id = %(brewery_id)s RETURN b', query_params)
228228
beer = cursor.fetchall()[0]
229229
assert 'Stout' in beer
230230
finally:
@@ -255,17 +255,17 @@ def test_psycopg2_cypher_with_array_parameter_in_clause():
255255
try:
256256
with conn.cursor() as cursor:
257257
# Create test vertices first
258-
cursor.execute('{cypher} CREATE (n:CHUNK {text: "chunk1"}) RETURN ID(n)')
258+
cursor.execute('{opencypher} CREATE (n:CHUNK {text: "chunk1"}) RETURN ID(n)')
259259
rid1 = cursor.fetchone()[0]
260-
cursor.execute('{cypher} CREATE (n:CHUNK {text: "chunk2"}) RETURN ID(n)')
260+
cursor.execute('{opencypher} CREATE (n:CHUNK {text: "chunk2"}) RETURN ID(n)')
261261
rid2 = cursor.fetchone()[0]
262-
cursor.execute('{cypher} CREATE (n:CHUNK {text: "chunk3"}) RETURN ID(n)')
262+
cursor.execute('{opencypher} CREATE (n:CHUNK {text: "chunk3"}) RETURN ID(n)')
263263
rid3 = cursor.fetchone()[0]
264264

265265
# Now query with IN clause using array parameter
266266
rids_list = [rid1, rid2, rid3]
267267
query_params = {'ids': rids_list}
268-
cursor.execute('{cypher} MATCH (n:CHUNK) WHERE ID(n) IN %(ids)s RETURN n.text as text, ID(n) as id', query_params)
268+
cursor.execute('{opencypher} MATCH (n:CHUNK) WHERE ID(n) IN %(ids)s RETURN n.text as text, ID(n) as id', query_params)
269269

270270
results = cursor.fetchall()
271271
assert len(results) == 3

engine/src/main/java/com/arcadedb/database/LocalDatabase.java

Lines changed: 67 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@
5151
import com.arcadedb.graph.Edge;
5252
import com.arcadedb.graph.GraphBatch;
5353
import com.arcadedb.graph.GraphEngine;
54+
import com.arcadedb.graph.GraphTraversalProviderRegistry;
5455
import com.arcadedb.graph.MutableVertex;
5556
import com.arcadedb.graph.Vertex;
5657
import com.arcadedb.graph.VertexInternal;
57-
import com.arcadedb.graph.GraphTraversalProviderRegistry;
5858
import com.arcadedb.graph.olap.GraphAnalyticalView;
5959
import com.arcadedb.graph.olap.GraphAnalyticalViewPersistence;
6060
import com.arcadedb.graph.olap.GraphAnalyticalViewRegistry;
@@ -133,9 +133,10 @@
133133
* @author Luca Garulli (l.garulli@arcadedata.com)
134134
*/
135135
public class LocalDatabase extends RWLockContext implements DatabaseInternal {
136-
public static final int EDGE_LIST_INITIAL_CHUNK_SIZE = 64;
137-
public static final int MAX_RECOMMENDED_EDGE_LIST_CHUNK_SIZE = 8192;
138-
private static final Set<String> SUPPORTED_FILE_EXT = Set.of(
136+
public static final int EDGE_LIST_INITIAL_CHUNK_SIZE = 64;
137+
public static final int MAX_RECOMMENDED_EDGE_LIST_CHUNK_SIZE = 8192;
138+
139+
private static final Set<String> SUPPORTED_FILE_EXT = Set.of(
139140
Dictionary.DICT_EXT,
140141
LocalBucket.BUCKET_EXT,
141142
LSMTreeIndexMutable.NOTUNIQUE_INDEX_EXT,
@@ -147,57 +148,50 @@ public class LocalDatabase extends RWLockContext implements DatabaseInternal {
147148
TimeSeriesBucket.BUCKET_EXT,
148149
HashIndexBucket.UNIQUE_INDEX_EXT,
149150
HashIndexBucket.NOTUNIQUE_INDEX_EXT);
150-
public final AtomicLong indexCompactions =
151-
new AtomicLong();
152-
protected final String name;
153-
protected final ComponentFile.MODE mode;
154-
protected final ContextConfiguration configuration;
155-
protected final String databasePath;
156-
protected final BinarySerializer serializer;
157-
protected final RecordFactory recordFactory =
158-
new RecordFactory();
159-
protected final GraphEngine graphEngine;
160-
protected final WALFileFactory walFactory;
161-
protected final DocumentIndexer indexer;
162-
protected final DatabaseStats stats =
163-
new DatabaseStats();
164-
protected FileManager fileManager;
165-
protected LocalSchema schema;
166-
protected TransactionManager transactionManager;
167-
protected volatile DatabaseAsyncExecutorImpl async = null;
168-
protected final Lock asyncLock =
169-
new ReentrantLock();
170-
protected boolean autoTransaction = false;
171-
protected volatile boolean open = false;
172-
private boolean readYourWrites = true;
173-
private final Map<CALLBACK_EVENT, List<Callable<Void>>> callbacks;
174-
private final StatementCache statementCache;
175-
private final ExecutionPlanCache executionPlanCache;
176-
private final CypherStatementCache cypherStatementCache;
177-
private final CypherPlanCache cypherPlanCache;
178-
private final File configurationFile;
179-
private DatabaseInternal wrappedDatabaseInstance = this;
180-
private final SecurityManager security;
181-
private final Map<String, Object> wrappers = new HashMap<>();
182-
private File lockFile;
183-
private RandomAccessFile lockFileIO;
184-
private FileChannel lockFileIOChannel;
185-
private FileLock lockFileLock;
186-
private final RecordEventsRegistry events =
187-
new RecordEventsRegistry();
188-
private final ConcurrentHashMap<String, QueryEngine> reusableQueryEngines =
189-
new ConcurrentHashMap<>();
190-
private final ConcurrentHashMap<String, Object> globalVariables =
191-
new ConcurrentHashMap<>();
192-
private TRANSACTION_ISOLATION_LEVEL transactionIsolationLevel =
193-
TRANSACTION_ISOLATION_LEVEL.READ_COMMITTED;
194-
private long openedOn;
195-
private long lastUpdatedOn;
196-
private long lastUsedOn;
197-
private int cachedHashCode = 0;
151+
152+
public final AtomicLong indexCompactions = new AtomicLong();
153+
protected final String name;
154+
protected final ComponentFile.MODE mode;
155+
protected final ContextConfiguration configuration;
156+
protected final String databasePath;
157+
protected final BinarySerializer serializer;
158+
protected final RecordFactory recordFactory = new RecordFactory();
159+
protected final GraphEngine graphEngine;
160+
protected final WALFileFactory walFactory;
161+
protected final DocumentIndexer indexer;
162+
protected final DatabaseStats stats = new DatabaseStats();
163+
protected FileManager fileManager;
164+
protected LocalSchema schema;
165+
protected TransactionManager transactionManager;
166+
protected volatile DatabaseAsyncExecutorImpl async = null;
167+
protected final Lock asyncLock = new ReentrantLock();
168+
protected boolean autoTransaction = false;
169+
protected volatile boolean open = false;
170+
private boolean readYourWrites = true;
171+
private final Map<CALLBACK_EVENT, List<Callable<Void>>> callbacks;
172+
private final StatementCache statementCache;
173+
private final ExecutionPlanCache executionPlanCache;
174+
private final CypherStatementCache cypherStatementCache;
175+
private final CypherPlanCache cypherPlanCache;
176+
private final File configurationFile;
177+
private DatabaseInternal wrappedDatabaseInstance = this;
178+
private final SecurityManager security;
179+
private final Map<String, Object> wrappers = new HashMap<>();
180+
private File lockFile;
181+
private RandomAccessFile lockFileIO;
182+
private FileChannel lockFileIOChannel;
183+
private FileLock lockFileLock;
184+
private final RecordEventsRegistry events = new RecordEventsRegistry();
185+
private final ConcurrentHashMap<String, QueryEngine> reusableQueryEngines = new ConcurrentHashMap<>();
186+
private final ConcurrentHashMap<String, Object> globalVariables = new ConcurrentHashMap<>();
187+
private TRANSACTION_ISOLATION_LEVEL transactionIsolationLevel = TRANSACTION_ISOLATION_LEVEL.READ_COMMITTED;
188+
private long openedOn;
189+
private long lastUpdatedOn;
190+
private long lastUsedOn;
191+
private int cachedHashCode = 0;
198192

199193
protected LocalDatabase(final String path, final ComponentFile.MODE mode, final ContextConfiguration configuration,
200-
final SecurityManager security, final Map<CALLBACK_EVENT, List<Callable<Void>>> callbacks) {
194+
final SecurityManager security, final Map<CALLBACK_EVENT, List<Callable<Void>>> callbacks) {
201195
try {
202196
this.mode = mode;
203197
this.configuration = configuration;
@@ -600,7 +594,7 @@ public void scanType(final String typeName, final boolean polymorphic, final Doc
600594

601595
@Override
602596
public void scanType(final String typeName, final boolean polymorphic, final DocumentCallback callback,
603-
final ErrorRecordCallback errorRecordCallback) {
597+
final ErrorRecordCallback errorRecordCallback) {
604598
stats.scanType.incrementAndGet();
605599

606600
executeInReadLock(() -> {
@@ -643,7 +637,7 @@ public void scanBucket(final String bucketName, final RecordCallback callback) {
643637

644638
@Override
645639
public void scanBucket(final String bucketName, final RecordCallback callback,
646-
final ErrorRecordCallback errorRecordCallback) {
640+
final ErrorRecordCallback errorRecordCallback) {
647641
stats.scanBucket.incrementAndGet();
648642

649643
executeInReadLock(() -> {
@@ -826,7 +820,7 @@ record = recordFactory.newImmutableRecord(wrappedDatabaseInstance, type, rid, ty
826820

827821
@Override
828822
public IndexCursor lookupByKey(final String type, final String keyName, final Object keyValue) {
829-
return lookupByKey(type, new String[]{keyName}, new Object[]{keyValue});
823+
return lookupByKey(type, new String[] { keyName }, new Object[] { keyValue });
830824
}
831825

832826
@Override
@@ -1191,8 +1185,8 @@ public boolean transaction(final TransactionScope txBlock, final boolean joinCur
11911185

11921186
@Override
11931187
public boolean transaction(final TransactionScope txBlock, final boolean joinCurrentTx, int attempts,
1194-
final OkCallback ok,
1195-
final ErrorCallback error) {
1188+
final OkCallback ok,
1189+
final ErrorCallback error) {
11961190
if (txBlock == null)
11971191
throw new IllegalArgumentException("Transaction block is null");
11981192

@@ -1319,11 +1313,11 @@ public MutableVertex newVertex(final String typeName) {
13191313
}
13201314

13211315
public Edge newEdgeByKeys(final String sourceVertexType, final String[] sourceVertexKeyNames,
1322-
final Object[] sourceVertexKeyValues, final String destinationVertexType,
1323-
final String[] destinationVertexKeyNames,
1324-
final Object[] destinationVertexKeyValues, final boolean createVertexIfNotExist,
1325-
final String edgeType,
1326-
final boolean bidirectional, final Object... properties) {
1316+
final Object[] sourceVertexKeyValues, final String destinationVertexType,
1317+
final String[] destinationVertexKeyNames,
1318+
final Object[] destinationVertexKeyValues, final boolean createVertexIfNotExist,
1319+
final String edgeType,
1320+
final boolean bidirectional, final Object... properties) {
13271321
if (sourceVertexKeyNames == null)
13281322
throw new IllegalArgumentException("Source vertex key is null");
13291323

@@ -1375,10 +1369,10 @@ public Edge newEdgeByKeys(final String sourceVertexType, final String[] sourceVe
13751369

13761370
@Deprecated
13771371
public Edge newEdgeByKeys(final Vertex sourceVertex, final String destinationVertexType,
1378-
final String[] destinationVertexKeyNames,
1379-
final Object[] destinationVertexKeyValues, final boolean createVertexIfNotExist,
1380-
final String edgeType,
1381-
final boolean bidirectional, final Object... properties) {
1372+
final String[] destinationVertexKeyNames,
1373+
final Object[] destinationVertexKeyValues, final boolean createVertexIfNotExist,
1374+
final String edgeType,
1375+
final boolean bidirectional, final Object... properties) {
13821376
if (!bidirectional && ((EdgeType) schema.getType(edgeType)).isBidirectional())
13831377
throw new IllegalArgumentException("Edge type '" + edgeType + "' is not bidirectional");
13841378

@@ -1387,10 +1381,10 @@ public Edge newEdgeByKeys(final Vertex sourceVertex, final String destinationVer
13871381
}
13881382

13891383
public Edge newEdgeByKeys(final Vertex sourceVertex, final String destinationVertexType,
1390-
final String[] destinationVertexKeyNames,
1391-
final Object[] destinationVertexKeyValues, final boolean createVertexIfNotExist,
1392-
final String edgeType,
1393-
final Object... properties) {
1384+
final String[] destinationVertexKeyNames,
1385+
final Object[] destinationVertexKeyValues, final boolean createVertexIfNotExist,
1386+
final String edgeType,
1387+
final Object... properties) {
13941388
if (sourceVertex == null)
13951389
throw new IllegalArgumentException("Source vertex is null");
13961390

@@ -1501,7 +1495,7 @@ public ResultSet command(final String language, final String query, final Object
15011495

15021496
@Override
15031497
public ResultSet command(final String language, final String query, final ContextConfiguration configuration,
1504-
final Object... parameters) {
1498+
final Object... parameters) {
15051499
checkDatabaseIsOpen(true, "Cannot execute command on a read only database");
15061500
stats.commands.incrementAndGet();
15071501
return getQueryEngine(language).command(query, configuration, parameters);
@@ -1514,7 +1508,7 @@ public ResultSet command(final String language, final String query, final Map<St
15141508

15151509
@Override
15161510
public ResultSet command(final String language, final String query, final ContextConfiguration configuration,
1517-
final Map<String, Object> parameters) {
1511+
final Map<String, Object> parameters) {
15181512
checkDatabaseIsOpen(true, "Cannot execute command on a read only database");
15191513
stats.commands.incrementAndGet();
15201514
return getQueryEngine(language).command(query, configuration, parameters);

engine/src/main/java/com/arcadedb/query/QueryEngineManager.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ private QueryEngineManager() {
6666

6767
// REGISTER GREMLIN AND ITS CYPHER ENGINE (OVERRIDES "cypher" WITH GREMLIN-BASED IMPLEMENTATION IF AVAILABLE)
6868
register("com.arcadedb.gremlin.query.GremlinQueryEngineFactory");
69-
register("com.arcadedb.cypher.query.CypherQueryEngineFactory");
7069
}
7170

7271
public static QueryEngineManager getInstance() {

graphql/src/main/java/com/arcadedb/graphql/schema/GraphQLResultSet.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ private GraphQLResult mapProjections(final Result current, final List<Projection
172172

173173
Object projectionValue = current.getProperty(projName);
174174

175+
if (projectionValue == null && current.getElement().isPresent())
176+
// PROPERTY NOT FOUND IN PROJECTION, TRY DIRECTLY FROM THE ELEMENT (E.G. CYPHER RETURN)
177+
projectionValue = current.getElement().get().get(projName);
178+
175179
if (projectionValue == null) {
176180
// TRY THE FIELD FIRST
177181
projectionValue = evaluateDirectives(current, entry.field);

graphql/src/test/java/com/arcadedb/graphql/GraphQLCypherDirectivesTest.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@
2121
import com.arcadedb.database.Database;
2222

2323
public class GraphQLCypherDirectivesTest extends AbstractGraphQLNativeLanguageDirectivesTest {
24-
@Override
25-
protected int getExpectedPropertiesMetadata() {
26-
return 0;
27-
}
28-
2924
@Override
3025
protected void defineTypes(final Database database) {
3126
super.defineTypes(database);

gremlin/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,6 @@
137137
</exclusions>
138138
</dependency>
139139

140-
<dependency>
141-
<groupId>org.opencypher.gremlin</groupId>
142-
<artifactId>translation</artifactId>
143-
<version>${translation.version}</version>
144-
</dependency>
145140

146141
<!-- ARCADEDB DOES NOT USE THIS LIBRARY BUT GREMLIN DOES. REPLACING IT WITH THE LAST RELEASE BECAUSE OF THE SECURITY ISSUE
147142
https://nvd.nist.gov/vuln/detail/CVE-2022-1471 -->

0 commit comments

Comments
 (0)