Skip to content

Commit 095a58c

Browse files
authored
Add tests to cover relation index manipulations (#382)
## Usage and product changes Test queries based on relations with multiple players, covering multiple combinations of cardinalities, leading or not leading to relation index creation. These tests will help catch index-related bugs in future optimizations and already cover fixes to the recently discovered bugs in schema migration. ## Implementation New tests: * Test that concentrates on similar changes of cards from "indexed" to "not indexed" states within a single transaction (with intermediate reads and final all-transaction-based reads) * Test that concentrates on permutations of different operations in different types of transactions, switching between schema, write, and read transactions for all possible operations and a couple of indexing cases. * Test that combines `owns`, `relates`, and `plays` cardinalities (in case we introduce more indices) and runs tricky queries (+ fires on another BUG!) * Same as above, but in `migration` to test database export + import!
1 parent 85079e8 commit 095a58c

File tree

2 files changed

+2515
-189
lines changed

2 files changed

+2515
-189
lines changed

driver/migration.feature

Lines changed: 392 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,3 +1224,395 @@ Feature: Driver Migration
12241224
match $e isa person, has name $a;
12251225
"""
12261226
When transaction closes
1227+
1228+
1229+
Scenario: Export and import of a database with different cardinalities and relation indices work
1230+
When connection open schema transaction for database: typedb
1231+
When typeql schema query
1232+
"""
1233+
define
1234+
entity person,
1235+
plays parentship:parent @card(0..3),
1236+
plays parentship:child @card(0..1),
1237+
plays friendship:friend @card(0..),
1238+
owns name @card(0..3),
1239+
owns age @card(0..1),
1240+
owns email @card(0..);
1241+
1242+
relation parentship,
1243+
relates parent @card(0..3),
1244+
relates child @card(0..1);
1245+
1246+
relation friendship,
1247+
relates friend @card(0..);
1248+
1249+
attribute name value string;
1250+
attribute age value integer;
1251+
attribute email value string;
1252+
"""
1253+
When typeql write query
1254+
"""
1255+
insert
1256+
$p1 isa person,
1257+
has name "P1",
1258+
has name "P1 Name",
1259+
has name "P1 Name Full",
1260+
has age 101,
1261+
has email "[email protected]",
1262+
has email "[email protected]";
1263+
$p2 isa person,
1264+
has name "P2",
1265+
has name "P2 Name",
1266+
has age 102,
1267+
has email "[email protected]",
1268+
has email "[email protected]";
1269+
$p3 isa person,
1270+
has name "P3",
1271+
has email "[email protected]";
1272+
$p4 isa person,
1273+
has name "P4";
1274+
$p5 isa person,
1275+
has name "P5";
1276+
(parent: $p1, parent: $p2, parent: $p3, child: $p4) isa parentship;
1277+
(parent: $p1, parent: $p2, child: $p3) isa parentship;
1278+
(parent: $p5, child: $p2) isa parentship;
1279+
(child: $p1) isa parentship;
1280+
(friend: $p1, friend: $p4) isa friendship;
1281+
(friend: $p1) isa friendship;
1282+
"""
1283+
When get answers of typeql read query
1284+
"""
1285+
match
1286+
$p isa person;
1287+
($p) isa parentship;
1288+
"""
1289+
Then answer size is: 5
1290+
When get answers of typeql read query
1291+
"""
1292+
match
1293+
$p isa person;
1294+
(parent: $p) isa parentship;
1295+
"""
1296+
Then answer size is: 4
1297+
When get answers of typeql read query
1298+
"""
1299+
match
1300+
$p isa person;
1301+
(child: $p) isa parentship;
1302+
"""
1303+
Then answer size is: 4
1304+
When get answers of typeql read query
1305+
"""
1306+
match
1307+
$p isa person;
1308+
(parent: $p, parent: $_) isa parentship;
1309+
"""
1310+
Then answer size is: 3
1311+
When get answers of typeql read query
1312+
"""
1313+
match
1314+
$p isa person;
1315+
(child: $p, child: $_) isa parentship;
1316+
"""
1317+
Then answer size is: 0
1318+
When get answers of typeql read query
1319+
"""
1320+
match
1321+
$p isa person;
1322+
(child: $p, parent: $_) isa parentship;
1323+
"""
1324+
Then answer size is: 3
1325+
When get answers of typeql read query
1326+
"""
1327+
match
1328+
$p isa person, has name "P1";
1329+
(parent: $p, parent: $_) isa parentship;
1330+
"""
1331+
Then answer size is: 1
1332+
When get answers of typeql read query
1333+
"""
1334+
match
1335+
$p isa person, has name "P1";
1336+
(parent: $p, parent: $_, parent: $_) isa parentship;
1337+
"""
1338+
Then answer size is: 1
1339+
When get answers of typeql read query
1340+
"""
1341+
match
1342+
$p isa person, has name "P1";
1343+
(parent: $p, parent: $_, parent: $_, child: $_) isa parentship;
1344+
"""
1345+
Then answer size is: 1
1346+
When get answers of typeql read query
1347+
"""
1348+
match
1349+
$p1 isa person, has name "P1";
1350+
$p2 isa person, has name "P2";
1351+
(parent: $p1, parent: $p2) isa parentship;
1352+
"""
1353+
Then answer size is: 1
1354+
When get answers of typeql read query
1355+
"""
1356+
match
1357+
$p1 isa person, has name "P1";
1358+
$p2 isa person, has name "P2";
1359+
$parentship isa parentship, links (parent: $p1, parent: $p2);
1360+
"""
1361+
Then answer size is: 2
1362+
When get answers of typeql read query
1363+
"""
1364+
match
1365+
$p1 isa person, has name "P1";
1366+
$p3 isa person, has name "P3";
1367+
$parentship isa parentship, links (parent: $p1, parent: $p3);
1368+
"""
1369+
Then answer size is: 1
1370+
When get answers of typeql read query
1371+
"""
1372+
match
1373+
$p1 isa person, has name "P1";
1374+
"""
1375+
Then answer size is: 1
1376+
When get answers of typeql read query
1377+
"""
1378+
match
1379+
$p2 isa person, has name "P2";
1380+
"""
1381+
Then answer size is: 1
1382+
When get answers of typeql read query
1383+
"""
1384+
match
1385+
$p4 isa person, has name "P4";
1386+
"""
1387+
Then answer size is: 1
1388+
When get answers of typeql read query
1389+
"""
1390+
match
1391+
$p isa person, has name "P1", has name "P1 Name";
1392+
"""
1393+
Then answer size is: 1
1394+
When get answers of typeql read query
1395+
"""
1396+
match
1397+
$p isa person, has name "P1", has name "P2 Name";
1398+
"""
1399+
Then answer size is: 0
1400+
When get answers of typeql read query
1401+
"""
1402+
match
1403+
$p isa person, has name "P1", has name "P2 Name";
1404+
"""
1405+
Then answer size is: 0
1406+
When get answers of typeql read query
1407+
"""
1408+
match
1409+
$p isa person, has name "P1", has email "[email protected]";
1410+
"""
1411+
Then answer size is: 1
1412+
When get answers of typeql read query
1413+
"""
1414+
match
1415+
$p isa person, has name "P1", has email "[email protected]";
1416+
"""
1417+
Then answer size is: 0
1418+
When get answers of typeql read query
1419+
"""
1420+
match
1421+
$p isa person, has name "P1", has email $e;
1422+
"""
1423+
Then answer size is: 2
1424+
When get answers of typeql read query
1425+
"""
1426+
match
1427+
$p isa person, has name "P1", has name $n;
1428+
"""
1429+
Then answer size is: 3
1430+
When get answers of typeql read query
1431+
"""
1432+
match
1433+
$p isa person, has name "P4", has email $n;
1434+
"""
1435+
Then answer size is: 0
1436+
When transaction commits
1437+
1438+
When connection get database(typedb) export to schema file(schema.tql), data file(data.typedb)
1439+
Then connection import database(typedb-clone) from schema file(schema.tql), data file(data.typedb)
1440+
1441+
Then connection get database(typedb-clone) has schema:
1442+
"""
1443+
define
1444+
entity person,
1445+
plays parentship:parent @card(0..3),
1446+
plays parentship:child @card(0..1),
1447+
plays friendship:friend @card(0..),
1448+
owns name @card(0..3),
1449+
owns age @card(0..1),
1450+
owns email @card(0..);
1451+
1452+
relation parentship,
1453+
relates parent @card(0..3),
1454+
relates child @card(0..1);
1455+
1456+
relation friendship,
1457+
relates friend @card(0..);
1458+
1459+
attribute name value string;
1460+
attribute age value integer;
1461+
attribute email value string;
1462+
"""
1463+
1464+
When connection open read transaction for database: typedb-clone
1465+
When get answers of typeql read query
1466+
"""
1467+
match
1468+
$p isa person;
1469+
($p) isa parentship;
1470+
"""
1471+
Then answer size is: 5
1472+
When get answers of typeql read query
1473+
"""
1474+
match
1475+
$p isa person;
1476+
(parent: $p) isa parentship;
1477+
"""
1478+
Then answer size is: 4
1479+
When get answers of typeql read query
1480+
"""
1481+
match
1482+
$p isa person;
1483+
(child: $p) isa parentship;
1484+
"""
1485+
Then answer size is: 4
1486+
When get answers of typeql read query
1487+
"""
1488+
match
1489+
$p isa person;
1490+
(parent: $p, parent: $_) isa parentship;
1491+
"""
1492+
Then answer size is: 3
1493+
When get answers of typeql read query
1494+
"""
1495+
match
1496+
$p isa person;
1497+
(child: $p, child: $_) isa parentship;
1498+
"""
1499+
Then answer size is: 0
1500+
When get answers of typeql read query
1501+
"""
1502+
match
1503+
$p isa person;
1504+
(child: $p, parent: $_) isa parentship;
1505+
"""
1506+
Then answer size is: 3
1507+
When get answers of typeql read query
1508+
"""
1509+
match
1510+
$p isa person, has name "P1";
1511+
(parent: $p, parent: $_) isa parentship;
1512+
"""
1513+
Then answer size is: 1
1514+
# TODO: https://github.com/typedb/typedb/issues/7597
1515+
# When get answers of typeql read query
1516+
# """
1517+
# match
1518+
# $p isa person, has name "P1";
1519+
# (parent: $p, parent: $_, parent: $_) isa parentship;
1520+
# """
1521+
# Then answer size is: 1
1522+
# When get answers of typeql read query
1523+
# """
1524+
# match
1525+
# $p isa person, has name "P1";
1526+
# (parent: $p, parent: $_, parent: $_, child: $_) isa parentship;
1527+
# """
1528+
# Then answer size is: 1
1529+
When get answers of typeql read query
1530+
"""
1531+
match
1532+
$p1 isa person, has name "P1";
1533+
$p2 isa person, has name "P2";
1534+
(parent: $p1, parent: $p2) isa parentship;
1535+
"""
1536+
Then answer size is: 1
1537+
When get answers of typeql read query
1538+
"""
1539+
match
1540+
$p1 isa person, has name "P1";
1541+
$p2 isa person, has name "P2";
1542+
$parentship isa parentship, links (parent: $p1, parent: $p2);
1543+
"""
1544+
Then answer size is: 2
1545+
When get answers of typeql read query
1546+
"""
1547+
match
1548+
$p1 isa person, has name "P1";
1549+
$p3 isa person, has name "P3";
1550+
$parentship isa parentship, links (parent: $p1, parent: $p3);
1551+
"""
1552+
Then answer size is: 1
1553+
When get answers of typeql read query
1554+
"""
1555+
match
1556+
$p1 isa person, has name "P1";
1557+
"""
1558+
Then answer size is: 1
1559+
When get answers of typeql read query
1560+
"""
1561+
match
1562+
$p2 isa person, has name "P2";
1563+
"""
1564+
Then answer size is: 1
1565+
When get answers of typeql read query
1566+
"""
1567+
match
1568+
$p4 isa person, has name "P4";
1569+
"""
1570+
Then answer size is: 1
1571+
When get answers of typeql read query
1572+
"""
1573+
match
1574+
$p isa person, has name "P1", has name "P1 Name";
1575+
"""
1576+
Then answer size is: 1
1577+
When get answers of typeql read query
1578+
"""
1579+
match
1580+
$p isa person, has name "P1", has name "P2 Name";
1581+
"""
1582+
Then answer size is: 0
1583+
When get answers of typeql read query
1584+
"""
1585+
match
1586+
$p isa person, has name "P1", has name "P2 Name";
1587+
"""
1588+
Then answer size is: 0
1589+
When get answers of typeql read query
1590+
"""
1591+
match
1592+
$p isa person, has name "P1", has email "[email protected]";
1593+
"""
1594+
Then answer size is: 1
1595+
When get answers of typeql read query
1596+
"""
1597+
match
1598+
$p isa person, has name "P1", has email "[email protected]";
1599+
"""
1600+
Then answer size is: 0
1601+
When get answers of typeql read query
1602+
"""
1603+
match
1604+
$p isa person, has name "P1", has email $e;
1605+
"""
1606+
Then answer size is: 2
1607+
When get answers of typeql read query
1608+
"""
1609+
match
1610+
$p isa person, has name "P1", has name $n;
1611+
"""
1612+
Then answer size is: 3
1613+
When get answers of typeql read query
1614+
"""
1615+
match
1616+
$p isa person, has name "P4", has email $n;
1617+
"""
1618+
Then answer size is: 0

0 commit comments

Comments
 (0)