Skip to content
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: 1 addition & 1 deletion e2e/src/test/java/com/arcadedb/e2e/JdbcQueriesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void bigResultSetSQLQuery() throws Exception {
void simpleGremlinQuery() throws Exception {
try (final Statement st = conn.createStatement()) {

try (final ResultSet rs = st.executeQuery("{gremlin}g.V().limit(1)")) {
try (final ResultSet rs = st.executeQuery("{gremlin}g.V().hasLabel('Beer').limit(1)")) {
assertThat(rs.next()).isTrue();

assertThat(rs.getString("name")).isNotBlank();
Expand Down
18 changes: 12 additions & 6 deletions engine/src/main/java/com/arcadedb/graph/GraphEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,7 @@ public List<Edge> newEdges(VertexInternal sourceVertex, final List<CreateEdgeOpe
final List<Edge> edges = new ArrayList<>(connections.size());
final List<Pair<Identifiable, Identifiable>> outEdgePairs = new ArrayList<>();

for (int i = 0; i < connections.size(); ++i) {
final CreateEdgeOperation connection = connections.get(i);

for (final CreateEdgeOperation connection : connections) {
final MutableEdge edge;

final Identifiable destinationVertex = connection.destinationVertex;
Expand Down Expand Up @@ -552,7 +550,10 @@ public boolean isVertexConnectedTo(final VertexInternal vertex, final Identifiab
return false;
}

public boolean isVertexConnectedTo(final VertexInternal vertex, final Identifiable toVertex, final Vertex.DIRECTION direction,
public boolean isVertexConnectedTo(
final VertexInternal vertex,
final Identifiable toVertex,
final Vertex.DIRECTION direction,
final String edgeType) {
if (toVertex == null)
throw new IllegalArgumentException("Destination vertex is null");
Expand All @@ -563,8 +564,13 @@ public boolean isVertexConnectedTo(final VertexInternal vertex, final Identifiab
if (edgeType == null)
throw new IllegalArgumentException("Edge type is null");

final int[] bucketFilter = vertex.getDatabase().getSchema().getType(edgeType).getBuckets(true).stream()
.mapToInt(x -> x.getFileId()).toArray();
final int[] bucketFilter = vertex.getDatabase()
.getSchema()
.getType(edgeType)
.getBuckets(true)
.stream()
.mapToInt(x -> x.getFileId())
.toArray();

if (direction == Vertex.DIRECTION.OUT || direction == Vertex.DIRECTION.BOTH) {
final EdgeLinkedList outEdges = getEdgeHeadChunk(vertex, Vertex.DIRECTION.OUT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.arcadedb.database.Database;
import com.arcadedb.exception.CommandSQLParsingException;
import com.arcadedb.index.TypeIndex;
import com.arcadedb.query.sql.parser.CreateEdgeStatement;
import com.arcadedb.query.sql.parser.Expression;
import com.arcadedb.query.sql.parser.Identifier;
Expand All @@ -28,8 +29,10 @@
import com.arcadedb.query.sql.parser.JsonArray;
import com.arcadedb.query.sql.parser.UpdateItem;
import com.arcadedb.schema.DocumentType;
import com.arcadedb.schema.EdgeType;

import java.util.*;
import java.util.ArrayList;
import java.util.List;

/**
* Created by luigidellaquila on 08/08/16.
Expand Down Expand Up @@ -85,7 +88,19 @@ public InsertExecutionPlan createExecutionPlan(final CommandContext context) {
handleGlobalLet(result, new Identifier("$__ARCADEDB_CREATE_EDGE_toV"), rightExpression, context);

final String uniqueIndexName;
uniqueIndexName = null;
// if (context.getDatabase().getSchema().existsType(targetClass.getStringValue())) {
// final EdgeType type = (EdgeType) context.getDatabase().getSchema().getType(targetClass.getStringValue());
// uniqueIndexName = type.getAllIndexes(true)
// .stream()
// .filter(TypeIndex::isUnique)
// .filter(x -> x.getPropertyNames().size() == 2
// && x.getPropertyNames().contains("@out")
// && x.getPropertyNames().contains("@in"))
// .map(TypeIndex::getName)
// .findFirst()
// .orElse(null);
// } else
uniqueIndexName = null;

result.chain(
new CreateEdgesStep(targetClass, targetBucketName, uniqueIndexName, new Identifier("$__ARCADEDB_CREATE_EDGE_fromV"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@
import com.arcadedb.index.IndexCursor;
import com.arcadedb.query.sql.parser.Identifier;

import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;

/**
* Created by luigidellaquila on 28/11/16.
Expand All @@ -58,8 +62,14 @@ public class CreateEdgesStep extends AbstractExecutionStep {

private boolean initiated = false;

public CreateEdgesStep(final Identifier targetClass, final Identifier targetBucketName, final String uniqueIndex,
final Identifier fromAlias, final Identifier toAlias, final boolean unidirectional, final boolean ifNotExists,
public CreateEdgesStep(
final Identifier targetClass,
final Identifier targetBucketName,
final String uniqueIndex,
final Identifier fromAlias,
final Identifier toAlias,
final boolean unidirectional,
final boolean ifNotExists,
final CommandContext context) {
super(context);
this.targetClass = targetClass;
Expand Down Expand Up @@ -91,8 +101,15 @@ public Result next() {

@Override
public Result next(final Object[] properties) {
if (currentTo == null)
if (currentTo == null) {
loadNextFromTo();
if(edgeToUpdate != null && !ifNotExists) {
System.out.println("edgeToUpdate = " + edgeToUpdate);
currentTo = null;
currentBatch++;
return new UpdatableResult(edgeToUpdate);
}
}

final long begin = context.isProfiling() ? System.nanoTime() : 0;
try {
Expand All @@ -103,11 +120,21 @@ public Result next(final Object[] properties) {
if (currentTo == null)
throw new CommandExecutionException("Invalid TO vertex for edge");

if (ifNotExists)
if (ifNotExists) {
if (context.getDatabase().getGraphEngine()
.isVertexConnectedTo((VertexInternal) currentFrom, currentTo, Vertex.DIRECTION.OUT, targetClass.getStringValue()))
// SKIP CREATING EDGE
return null;
.isVertexConnectedTo((VertexInternal) currentFrom, currentTo, Vertex.DIRECTION.OUT, targetClass.getStringValue())) {

for (Edge existingEdge : context.getDatabase().getGraphEngine()
.getEdges((VertexInternal) currentFrom, Vertex.DIRECTION.OUT, targetClass.getStringValue())) {

if (existingEdge.getOut().equals(currentTo)) {
currentTo = null;
currentBatch++;
return new UpdatableResult(existingEdge.modify());
}
}
}
}

final String target = targetBucket != null ? "bucket:" + targetBucket.getStringValue() : targetClass.getStringValue();

Expand All @@ -119,7 +146,7 @@ public Result next(final Object[] properties) {
currentBatch++;
return result;
} finally {
if( context.isProfiling() ) {
if (context.isProfiling()) {
cost += (System.nanoTime() - begin);
}
}
Expand Down Expand Up @@ -223,7 +250,7 @@ protected void loadNextFromTo() {
this.currentTo = null;
}
} finally {
if( context.isProfiling() ) {
if (context.isProfiling()) {
cost += (System.nanoTime() - begin);
}
}
Expand Down Expand Up @@ -271,7 +298,7 @@ public String prettyPrint(final int depth, final int indent) {
result += spaces + " FOR EACH y in " + toAlias + "\n";
result +=
spaces + " CREATE EDGE " + targetClass + " FROM x TO y " + (unidirectional ? "UNIDIRECTIONAL" : "BIDIRECTIONAL");
if ( context.isProfiling() )
if (context.isProfiling())
result += " (" + getCostFormatted() + ")";

if (targetBucket != null)
Expand All @@ -287,8 +314,14 @@ public boolean canBeCached() {

@Override
public ExecutionStep copy(final CommandContext context) {
return new CreateEdgesStep(targetClass == null ? null : targetClass.copy(), targetBucket == null ? null : targetBucket.copy(),
uniqueIndexName, fromAlias == null ? null : fromAlias.copy(), toAlias == null ? null : toAlias.copy(), unidirectional,
ifNotExists, context);
return new CreateEdgesStep(
targetClass == null ? null : targetClass.copy(),
targetBucket == null ? null : targetBucket.copy(),
uniqueIndexName,
fromAlias == null ? null : fromAlias.copy(),
toAlias == null ? null : toAlias.copy(),
unidirectional,
ifNotExists,
context);
}
}
23 changes: 15 additions & 8 deletions engine/src/test/java/com/arcadedb/graph/BasicGraphTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,12 @@
import com.arcadedb.query.sql.function.SQLFunctionAbstract;
import com.arcadedb.schema.EdgeType;
import com.arcadedb.schema.Schema;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.*;
import java.util.concurrent.atomic.*;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;

import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;

Expand Down Expand Up @@ -490,7 +488,8 @@ public void customFunction() {
try {
((SQLQueryEngine) database.getQueryEngine("sql")).getFunctionFactory().register(new SQLFunctionAbstract("ciao") {
@Override
public Object execute(final Object iThis, final Identifiable iCurrentRecord, final Object iCurrentResult, final Object[] iParams,
public Object execute(final Object iThis, final Identifiable iCurrentRecord, final Object iCurrentResult,
final Object[] iParams,
final CommandContext iContext) {
return "Ciao";
}
Expand Down Expand Up @@ -575,7 +574,7 @@ public void rollbackEdge() {
}

@Test
public void reuseRollbackedTx() {
public void reuseRollBackedTx() {
final AtomicReference<RID> v1RID = new AtomicReference<>();

database.transaction(() -> {
Expand Down Expand Up @@ -655,6 +654,7 @@ public void edgeUnivocitySQL() {

v1[0] = database.newVertex(VERTEX1_TYPE_NAME).set("id", 1001).save();
v2[0] = database.newVertex(VERTEX1_TYPE_NAME).set("id", 1002).save();

final ResultSet result = database.command("sql", "create edge OnlyOneBetweenVertices from ? to ?", v1[0], v2[0]);
assertThat(result.hasNext()).isTrue();
});
Expand All @@ -673,7 +673,14 @@ public void edgeUnivocitySQL() {
// EXPECTED
}

database.transaction(() -> database.command("sql", "create edge OnlyOneBetweenVertices from ? to ? IF NOT EXISTS", v1[0], v2[0]));
try {
database.transaction(
() -> database.command("sql", "create edge OnlyOneBetweenVertices from ? to ? IF NOT EXISTS", v1[0], v2[0]));
fail("");
} catch (final DuplicatedKeyException ex) {
// EXPECTED
}

}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,25 @@
import com.arcadedb.schema.Schema;
import com.arcadedb.schema.Type;
import com.arcadedb.serializer.json.JSONObject;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.*;
import java.util.concurrent.*;
import java.util.stream.*;
import java.util.List;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* @author Luca Garulli ([email protected])
*/
public class SelectExecutionIT extends TestHelper {
public class SelectExecutionTest extends TestHelper {

public SelectExecutionIT() {
public SelectExecutionTest() {
autoStartTx = false;
}

Expand All @@ -61,12 +62,17 @@ protected void beginTest() {
}

for (int i = 1; i < 100; i++) {
final Vertex root = database.select().fromType("Vertex").where().property("id").eq().value(0).vertices().nextOrNull();
assertNotNull(root);
assertEquals(0, root.getInteger("id"));

root.newEdge("Edge", database.select().fromType("Vertex").where().property("id").eq().value(i).vertices().nextOrNull(),
true).save();
final Vertex root = database.select()
.fromType("Vertex")
.where().property("id").eq().value(0).vertices()
.nextOrNull();
assertThat(root).isNotNull();
assertThat(root.getInteger("id")).isEqualTo(0);
root.newEdge("Edge", database.select()
.fromType("Vertex")
.where().property("id").eq().value(i)
.vertices().nextOrNull(), true)
.save();
}
});
}
Expand Down Expand Up @@ -356,11 +362,8 @@ public void okLike() {

@Test
public void okILike() {
final SelectCompiled select = database.select()
.fromType("Vertex")//
.where()
.property("name").ilike().value("j%")
.compile();
final SelectCompiled select = database.select().fromType("Vertex")//
.where().property("name").ilike().value("j%").compile();

for (int i = 0; i < 100; i++) {
final SelectIterator<Vertex> result = select.parameter("value", i).vertices();
Expand Down Expand Up @@ -409,13 +412,15 @@ private void expectingException(final Runnable callback, final Class<? extends T
callback.run();
failed = false;
} catch (Throwable e) {
if (!expectedException.equals(e.getClass())) e.printStackTrace();
if (!expectedException.equals(e.getClass()))
e.printStackTrace();

assertThat(e.getClass()).isEqualTo(expectedException);
assertThat(e.getMessage().contains(mustContains)).as(
"Expected '" + mustContains + "' in the error message. Error message is: " + e.getMessage()).isTrue();
}

if (!failed) fail("Expected exception " + expectedException);
if (!failed)
fail("Expected exception " + expectedException);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
/**
* @author Luca Garulli ([email protected])
*/
public class SelectIndexExecutionIT extends TestHelper {
public class SelectIndexExecutionTest extends TestHelper {

public SelectIndexExecutionIT() {
public SelectIndexExecutionTest() {
autoStartTx = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
/**
* @author Luca Garulli ([email protected])
*/
public class SelectOrderByIT extends TestHelper {
public class SelectOrderByTest extends TestHelper {

public SelectOrderByIT() {
public SelectOrderByTest() {
autoStartTx = true;
}

Expand Down
Loading
Loading