Skip to content

Commit

Permalink
more java17
Browse files Browse the repository at this point in the history
  • Loading branch information
robfrank committed Nov 3, 2024
1 parent 76d842d commit fb21033
Show file tree
Hide file tree
Showing 7 changed files with 391 additions and 393 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.arcadedb.TestHelper;
import com.arcadedb.database.bucketselectionstrategy.BucketSelectionStrategy;
import com.arcadedb.database.bucketselectionstrategy.PartitionedBucketSelectionStrategy;
import com.arcadedb.schema.DocumentType;
import com.arcadedb.serializer.json.JSONObject;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
Expand All @@ -43,10 +44,10 @@ public void sqlAlterTypeInheritanceUsing() {
database.command("sql", "ALTER TYPE Car SUPERTYPE +Vehicle");

assertThat(database.getSchema().getType("Car").getSuperTypes().size()).isEqualTo(1);
assertThat(database.getSchema().getType("Car").getSuperTypes().stream().map(x -> x.getName()).collect(Collectors.toSet())
assertThat(database.getSchema().getType("Car").getSuperTypes().stream().map(DocumentType::getName).collect(Collectors.toSet())
.contains("Vehicle")).isTrue();
assertThat(database.getSchema().getType("Vehicle").getSubTypes().size()).isEqualTo(1);
assertThat(database.getSchema().getType("Vehicle").getSubTypes().stream().map(x -> x.getName()).collect(Collectors.toSet())
assertThat(database.getSchema().getType("Vehicle").getSubTypes().stream().map(DocumentType::getName).toList()
.contains("Car")).isTrue();
assertThat(database.getSchema().getType("Vehicle").isSuperTypeOf("Car")).isTrue();

Expand All @@ -57,7 +58,7 @@ public void sqlAlterTypeInheritanceUsing() {
assertThat(database.getSchema().getType("Suv").getSuperTypes().size()).isEqualTo(1);
assertThat(database.getSchema().getType("Car").isSuperTypeOf("Suv")).isTrue();
assertThat(database.getSchema().getType("Car").getSubTypes().size()).isEqualTo(1);
assertThat(database.getSchema().getType("Car").getSubTypes().stream().map(x -> x.getName()).collect(Collectors.toSet())
assertThat(database.getSchema().getType("Car").getSubTypes().stream().map(DocumentType::getName).collect(Collectors.toSet())
.contains("Suv")).isTrue();
assertThat(database.getSchema().getType("Car").isSuperTypeOf("Suv")).isTrue();

Expand All @@ -71,7 +72,7 @@ public void sqlAlterTypeInheritanceUsing() {
assertThat(database.getSchema().getType("Vehicle").isSuperTypeOf("Suv")).isTrue();
assertThat(database.getSchema().getType("Car").getSubTypes().size()).isEqualTo(1);
assertThat(database.getSchema().getType("Vehicle").getSubTypes().size()).isEqualTo(1);
assertThat(database.getSchema().getType("Car").getSubTypes().stream().map(x -> x.getName()).collect(Collectors.toSet())
assertThat(database.getSchema().getType("Car").getSubTypes().stream().map(DocumentType::getName).collect(Collectors.toSet())
.contains("Suv")).isTrue();
assertThat(database.getSchema().getType("Car").isSuperTypeOf("Suv")).isTrue();
assertThat(database.getSchema().getType("Vehicle").isSuperTypeOf("Suv")).isTrue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import org.junit.jupiter.api.Test;

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
Expand All @@ -40,24 +42,19 @@ public CreateVertexStatementExecutionTest() {
@Test
public void testVerticesContentJsonArray() {
final String className = "testVertexContentArray";
database.getSchema().createVertexType(className, 1);

String array = "[";
for (int i = 0; i < 1000; i++) {
if (i > 0)
array += ",";
array += "{'name':'name" + i + "', 'surname':'surname" + i + "'}";
}
array += "]";
database.getSchema().buildVertexType().withName(className).withTotalBuckets(1).create();

String array = IntStream.range(0, 1000)
.mapToObj(i -> String.format("{'name':'name%d', 'surname':'surname%d'}", i, i))
.collect(Collectors.joining(",", "[", "]"));
ResultSet result = database.command("sql", "create vertex " + className + " content " + array);

for (int i = 0; i < 1000; i++) {
assertThat(result.hasNext()).isTrue();
final Result item = result.next();
assertThat(item).isNotNull();
assertThat(item.<String>getProperty("name").toString()).isEqualTo("name" + i);
assertThat(item.getProperty("surname").toString()).isEqualTo("surname" + i);
assertThat(item.<String>getProperty("name")).isEqualTo("name" + i);
assertThat(item.<String>getProperty("surname")).isEqualTo("surname" + i);
}
assertThat(result.hasNext()).isFalse();

Expand All @@ -67,8 +64,8 @@ public void testVerticesContentJsonArray() {
assertThat(result.hasNext()).isTrue();
Result item = result.next();
assertThat(item).isNotNull();
assertThat(item.<String>getProperty("name").toString()).isEqualTo("name" + i);
assertThat(item.getProperty("surname").toString()).isEqualTo("surname" + i);
assertThat(item.<String>getProperty("name")).isEqualTo("name" + i);
assertThat(item.<String>getProperty("surname")).isEqualTo("surname" + i);
}

assertThat(result.hasNext()).isFalse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ public void testGroupByCount() {
}
}

final ResultSet result = database.query("sql", "select address, count(*) as occurrences from InputTx where address is not null group by address limit 10");
final ResultSet result = database.query("sql", """
select address, count(*) as occurrences
from InputTx where address is not null
group by address
limit 10
""");
while (result.hasNext()) {
final Result row = result.next();
assertThat(row.<String>getProperty("address")).isNotNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,61 +11,53 @@ public class MatchInheritanceTest extends TestHelper {
public void testInheritance() {
ResultSet result = null;

String sql = "SELECT FROM Services";

result = database.command("SQL", sql);
result = database.command("SQL", "SELECT FROM Services");
int selectFromServices = 0;
while (result.hasNext()) {
Result record = result.next();
++selectFromServices;
}
assertThat(selectFromServices).isEqualTo(4);

sql = "SELECT FROM Attractions";
result = database.command("SQL", sql);
result = database.command("SQL", "SELECT FROM Attractions");
int selectFromAttractions = 0;
while (result.hasNext()) {
Result record = result.next();
++selectFromAttractions;
}
assertThat(selectFromAttractions).isEqualTo(4);

sql = "SELECT FROM Locations";

result = database.command("SQL", sql);
result = database.command("SQL", "SELECT FROM Locations");
int selectFromLocations = 0;
while (result.hasNext()) {
Result record = result.next();
++selectFromLocations;
}
assertThat(selectFromLocations).isEqualTo(8);

sql = "MATCH {type: Customers, as: customer, where: (OrderedId=1)}--{type: Monuments} " + "RETURN $pathelements";
result = database.query("SQL", sql);
result = database.query("SQL",
"MATCH {type: Customers, as: customer, where: (OrderedId=1)}--{type: Monuments} RETURN $pathelements");

assertThat(result.stream().count()).isEqualTo(2);

sql = "MATCH {type: Customers, as: customer, where: (OrderedId=1)}--{type: Services} " + "RETURN $pathelements";
result = database.query("SQL", sql);
result = database.query("SQL",
"MATCH {type: Customers, as: customer, where: (OrderedId=1)}--{type: Services} RETURN $pathelements");

assertThat(result.stream().count()).isEqualTo(8);

sql = "MATCH {type: Customers, as: customer, where: (OrderedId=1)}--{type: Attractions} " + "RETURN $pathelements";
result = database.query("SQL", sql);
result = database.query("SQL",
"MATCH {type: Customers, as: customer, where: (OrderedId=1)}--{type: Attractions} RETURN $pathelements");

assertThat(result.stream().count()).isEqualTo(8);

sql = "MATCH {type: Customers, as: customer, where: (OrderedId=1)}--{type: Locations} " + "RETURN $pathelements";
result = database.query("SQL", sql);
result = database.query("SQL",
"MATCH {type: Customers, as: customer, where: (OrderedId=1)}--{type: Locations} RETURN $pathelements");

assertThat(result.stream().count()).isEqualTo(16);
}

@Override
public void beginTest() {
StringBuilder sb = new StringBuilder();

sb.append("BEGIN;");
/*
-- Locations
-- + Services
Expand All @@ -77,95 +69,96 @@ public void beginTest() {
-- + Theatres
-- + Archaeological Sites
*/
sb.append("CREATE VERTEX TYPE Locations;");
sb.append("CREATE PROPERTY Locations.Id LONG;");
sb.append("CREATE PROPERTY Locations.Type STRING;");
sb.append("CREATE PROPERTY Locations.Name STRING;");

sb.append("CREATE INDEX ON Locations (Type) NOTUNIQUE;");
sb.append("CREATE INDEX ON Locations (Name) FULL_TEXT;");
String sqlScript = """
BEGIN;
CREATE VERTEX TYPE Locations;
CREATE PROPERTY Locations.Id LONG;
CREATE PROPERTY Locations.Type STRING;
CREATE PROPERTY Locations.Name STRING;
sb.append("CREATE VERTEX TYPE Services EXTENDS Locations;");
sb.append("CREATE VERTEX TYPE Hotels EXTENDS Services;");
sb.append("CREATE INDEX ON Hotels (Id) UNIQUE;");
CREATE INDEX ON Locations (Type) NOTUNIQUE;
CREATE INDEX ON Locations (Name) FULL_TEXT;
sb.append("CREATE VERTEX TYPE Restaurants EXTENDS Services;\n");
sb.append("CREATE INDEX ON Restaurants(Id) UNIQUE;\n");
CREATE VERTEX TYPE Services EXTENDS Locations;
CREATE VERTEX TYPE Hotels EXTENDS Services;
CREATE INDEX ON Hotels (Id) UNIQUE;
sb.append("CREATE VERTEX TYPE Attractions EXTENDS Locations;\n");
sb.append("CREATE VERTEX TYPE Monuments EXTENDS Attractions;\n");
sb.append("CREATE INDEX ON Monuments (Id) UNIQUE;\n");
CREATE VERTEX TYPE Restaurants EXTENDS Services;
CREATE INDEX ON Restaurants(Id) UNIQUE;
sb.append("CREATE VERTEX TYPE Castles EXTENDS Attractions;\n");
sb.append("CREATE INDEX ON Castles(Id) UNIQUE;\n");
CREATE VERTEX TYPE Attractions EXTENDS Locations;
CREATE VERTEX TYPE Monuments EXTENDS Attractions;
CREATE INDEX ON Monuments (Id) UNIQUE;
sb.append("CREATE VERTEX TYPE Theatres EXTENDS Attractions;\n");
sb.append("CREATE INDEX ON Theatres(Id) UNIQUE;\n");
CREATE VERTEX TYPE Castles EXTENDS Attractions;
CREATE INDEX ON Castles(Id) UNIQUE;
sb.append("CREATE VERTEX TYPE ArchaeologicalSites EXTENDS Attractions;\n");
sb.append("CREATE INDEX ON ArchaeologicalSites(Id) UNIQUE;\n");
CREATE VERTEX TYPE Theatres EXTENDS Attractions;
CREATE INDEX ON Theatres(Id) UNIQUE;
sb.append("CREATE VERTEX TYPE Customers;");
sb.append("CREATE PROPERTY Customers.OrderedId LONG;");
CREATE VERTEX TYPE ArchaeologicalSites EXTENDS Attractions;
CREATE INDEX ON ArchaeologicalSites(Id) UNIQUE;
sb.append("CREATE VERTEX TYPE Orders;");
sb.append("CREATE PROPERTY Orders.Id LONG;");
sb.append("CREATE PROPERTY Orders.Amount LONG;");
sb.append("CREATE PROPERTY Orders.OrderDate DATE;");
CREATE VERTEX TYPE Customers;
CREATE PROPERTY Customers.OrderedId LONG;
sb.append("CREATE INDEX ON Customers(OrderedId) UNIQUE;");
CREATE VERTEX TYPE Orders;
CREATE PROPERTY Orders.Id LONG;
CREATE PROPERTY Orders.Amount LONG;
CREATE PROPERTY Orders.OrderDate DATE;
sb.append("CREATE INDEX ON Orders(Id) UNIQUE;");
CREATE INDEX ON Customers(OrderedId) UNIQUE;
sb.append("CREATE EDGE TYPE HasUsedService;");
sb.append("CREATE PROPERTY HasUsedService.out LINK OF Customers;");
CREATE INDEX ON Orders(Id) UNIQUE;
sb.append("CREATE EDGE TYPE HasStayed EXTENDS HasUsedService;");
sb.append("CREATE PROPERTY HasStayed.in LINK OF Hotels;");
CREATE EDGE TYPE HasUsedService;
CREATE PROPERTY HasUsedService.out LINK OF Customers;
sb.append("CREATE EDGE TYPE HasEaten EXTENDS HasUsedService;");
sb.append("CREATE PROPERTY HasEaten.in LINK OF Restaurants;");
CREATE EDGE TYPE HasStayed EXTENDS HasUsedService;
CREATE PROPERTY HasStayed.in LINK OF Hotels;
sb.append("CREATE EDGE TYPE HasVisited;");
sb.append("CREATE PROPERTY HasVisited.out LINK OF Customers;");
sb.append("CREATE PROPERTY HasVisited.in LINK;");
sb.append("CREATE INDEX ON HasVisited (`in`, `out`) UNIQUE;");
CREATE EDGE TYPE HasEaten EXTENDS HasUsedService;
CREATE PROPERTY HasEaten.in LINK OF Restaurants;
sb.append("CREATE EDGE TYPE HasCustomer;");
sb.append("CREATE PROPERTY HasCustomer.in LINK OF Customers;");
sb.append("CREATE PROPERTY HasCustomer.out LINK OF Orders ;");
CREATE EDGE TYPE HasVisited;
CREATE PROPERTY HasVisited.out LINK OF Customers;
CREATE PROPERTY HasVisited.in LINK;
CREATE INDEX ON HasVisited (`in`, `out`) UNIQUE;
sb.append("INSERT INTO Customers SET OrderedId = 1, Phone = '+1400844724';");
sb.append("INSERT INTO Orders SET Id = 1, Amount = 536, OrderDate = '2013-05-23';");
CREATE EDGE TYPE HasCustomer;
CREATE PROPERTY HasCustomer.in LINK OF Customers;
CREATE PROPERTY HasCustomer.out LINK OF Orders;
sb.append("INSERT INTO Hotels SET Id = 730, Name = 'Toules', Type = 'alpine_hut';");
INSERT INTO Customers SET OrderedId = 1, Phone = '+1400844724';
INSERT INTO Orders SET Id = 1, Amount = 536, OrderDate = '2013-05-23';
sb.append("INSERT INTO Restaurants SET Id = 1834, Name = 'Uliassi', Type = 'restaurant';");
sb.append("INSERT INTO Restaurants SET Id = 1099, Name = 'L\\'Angelo d\\'Oro', Type = 'restaurant';");
INSERT INTO Hotels SET Id = 730, Name = 'Toules', Type = 'alpine_hut';
sb.append("INSERT INTO Restaurants SET Id = 1738, Name = 'Johnny Paranza', Type = 'fast_food';");
INSERT INTO Restaurants SET Id = 1834, Name = 'Uliassi', Type = 'restaurant';
INSERT INTO Restaurants SET Id = 1099, Name = 'L\\'Angelo d\\'Oro', Type = 'restaurant';
sb.append("INSERT INTO Castles SET Id = 127, Name = 'Haselburg', Type = 'castle';");
sb.append("INSERT INTO ArchaeologicalSites SET Id = 47, Name = 'Villa Romana', Type = 'archaeological_site';");
sb.append("INSERT INTO Monuments SET Id = 62, Name = 'Giuseppe Garibaldi', Type = 'monument';");
sb.append("INSERT INTO Theatres SET Id = 65, Name = 'Teatro Civico', Type = 'theatre';");
INSERT INTO Restaurants SET Id = 1738, Name = 'Johnny Paranza', Type = 'fast_food';
sb.append("CREATE EDGE HasStayed FROM (SELECT FROM Customers WHERE OrderedId=1) TO (SELECT FROM Hotels WHERE Id=730);");
INSERT INTO Castles SET Id = 127, Name = 'Haselburg', Type = 'castle';
INSERT INTO ArchaeologicalSites SET Id = 47, Name = 'Villa Romana', Type = 'archaeological_site';
INSERT INTO Monuments SET Id = 62, Name = 'Giuseppe Garibaldi', Type = 'monument';
INSERT INTO Theatres SET Id = 65, Name = 'Teatro Civico', Type = 'theatre';
sb.append("CREATE EDGE HasEaten FROM (SELECT FROM Customers WHERE OrderedId=1) TO (SELECT FROM Restaurants WHERE Id=1834);");
sb.append("CREATE EDGE HasEaten FROM (SELECT FROM Customers WHERE OrderedId=1) TO (SELECT FROM Restaurants WHERE Id=1099);");
sb.append("CREATE EDGE HasEaten FROM (SELECT FROM Customers WHERE OrderedId=1) TO (SELECT FROM Restaurants WHERE Id=1738);");
CREATE EDGE HasStayed FROM (SELECT FROM Customers WHERE OrderedId=1) TO (SELECT FROM Hotels WHERE Id=730);
sb.append("CREATE EDGE HasCustomer FROM (SELECT FROM Orders WHERE Id=1) TO (SELECT FROM Customers WHERE OrderedId=1);");
CREATE EDGE HasEaten FROM (SELECT FROM Customers WHERE OrderedId=1) TO (SELECT FROM Restaurants WHERE Id=1834);
CREATE EDGE HasEaten FROM (SELECT FROM Customers WHERE OrderedId=1) TO (SELECT FROM Restaurants WHERE Id=1099);
CREATE EDGE HasEaten FROM (SELECT FROM Customers WHERE OrderedId=1) TO (SELECT FROM Restaurants WHERE Id=1738);
sb.append("CREATE EDGE HasVisited FROM (SELECT FROM Customers WHERE OrderedId=1) TO (SELECT FROM Castles WHERE Id=127);");
sb.append(
"CREATE EDGE HasVisited FROM (SELECT FROM Customers WHERE OrderedId=1) TO (SELECT FROM ArchaeologicalSites WHERE Id=47);");
sb.append("CREATE EDGE HasVisited FROM (SELECT FROM Customers WHERE OrderedId=1) TO (SELECT FROM Monuments WHERE Id=62);");
sb.append("CREATE EDGE HasVisited FROM (SELECT FROM Customers WHERE OrderedId=1) TO (SELECT FROM Theatres WHERE Id=65);");
CREATE EDGE HasCustomer FROM (SELECT FROM Orders WHERE Id=1) TO (SELECT FROM Customers WHERE OrderedId=1);
sb.append("COMMIT;");
CREATE EDGE HasVisited FROM (SELECT FROM Customers WHERE OrderedId=1) TO (SELECT FROM Castles WHERE Id=127);
CREATE EDGE HasVisited FROM (SELECT FROM Customers WHERE OrderedId=1) TO (SELECT FROM ArchaeologicalSites WHERE Id=47);
CREATE EDGE HasVisited FROM (SELECT FROM Customers WHERE OrderedId=1) TO (SELECT FROM Monuments WHERE Id=62);
CREATE EDGE HasVisited FROM (SELECT FROM Customers WHERE OrderedId=1) TO (SELECT FROM Theatres WHERE Id=65);
database.command("SQLScript", sb.toString());
COMMIT;
""";
database.command("SQLScript", sqlScript);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,23 @@ public class MatchResultTest extends TestHelper {
*/
@Test
public void testIssue1689() {
database.transaction(() -> database.command("sqlscript", "CREATE VERTEX TYPE Person IF NOT EXISTS;\n"
+ "CREATE PROPERTY Person.role IF NOT EXISTS STRING;\n"
+ "CREATE VERTEX TYPE House IF NOT EXISTS;\n"
+ "CREATE EDGE TYPE LivesIn IF NOT EXISTS;\n"
// + "CREATE EDGE TYPE DummyEdge IF NOT EXISTS;\n"
// + "DELETE FROM LivesIn;\n"
// + "DELETE FROM Person;\n"
// + "DELETE FROM House;\n"
+ "CREATE VERTEX House;\n"
+ "CREATE VERTEX Person SET role='mom';\n"
+ "CREATE VERTEX Person SET role='dad';\n"
+ "CREATE VERTEX Person SET role='child';\n"
+ "CREATE EDGE LivesIn FROM (SELECT FROM Person) TO (SELECT FROM House);"));

final ResultSet resultSet = database.query("sql", "MATCH {TYPE: Person, AS: personVertex} -LivesIn-> {TYPE: House}\n"
+ ", NOT {AS: personVertex} -DummyEdge-> {TYPE: House}\n"
+ "RETURN personVertex");

database.transaction(() -> database.command("sqlscript", """
CREATE VERTEX TYPE Person IF NOT EXISTS;
CREATE PROPERTY Person.role IF NOT EXISTS STRING;
CREATE VERTEX TYPE House IF NOT EXISTS;
CREATE EDGE TYPE LivesIn IF NOT EXISTS;
CREATE VERTEX House;
CREATE VERTEX Person SET role='mom';
CREATE VERTEX Person SET role='dad';
CREATE VERTEX Person SET role='child';
CREATE EDGE LivesIn FROM (SELECT FROM Person) TO (SELECT FROM House);
"""));

final ResultSet resultSet = database.query("sql", """
MATCH {TYPE: Person, AS: personVertex} -LivesIn-> {TYPE: House}
, NOT {AS: personVertex} -DummyEdge-> {TYPE: House}
RETURN personVertex
""");
Set<RID> set = new HashSet<>();
while (resultSet.hasNext()) {
final Vertex next = resultSet.nextIfAvailable().getProperty("personVertex");
Expand Down
Loading

0 comments on commit fb21033

Please sign in to comment.