Skip to content

Commit 7e1596c

Browse files
committed
fix: fixed index on list property with null values inside
1 parent 0b1cd2f commit 7e1596c

3 files changed

Lines changed: 48 additions & 21 deletions

File tree

engine/src/main/java/com/arcadedb/query/sql/parser/RebuildIndexStatement.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ else if (entry.getKey().toString().equalsIgnoreCase("maxAttempts"))
106106

107107
} catch (Exception e) {
108108
LogManager.instance().log(this, Level.SEVERE, "Error on rebuilding index '%s'", e, indexName);
109-
throw new IndexException("Error on rebuilding index '" + indexName + "'", e);
109+
throw new IndexException("Error on rebuilding index '" + name.getValue() + "'", e);
110110
}
111111

112112
// SUCCESS

engine/src/main/java/com/arcadedb/serializer/BinaryComparator.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,9 +409,13 @@ public static boolean equalsBytes(final byte[] buffer1, final byte[] buffer2, fi
409409
public static int compareTo(final Object a, final Object b) {
410410
if (a == null && b == null)
411411
return 0;
412-
if (a instanceof String && b instanceof String)
412+
else if (a != null && b == null)
413+
return 1;
414+
else if (a == null && b != null)
415+
return -1;
416+
else if (a instanceof String && b instanceof String)
413417
return compareBytes(((String) a).getBytes(), ((String) b).getBytes(DatabaseFactory.getDefaultCharset()));
414-
if (a instanceof byte[] && b instanceof byte[])
418+
else if (a instanceof byte[] && b instanceof byte[])
415419
return compareBytes((byte[]) a, (byte[]) b);
416420
return ((Comparable<Object>) a).compareTo(b);
417421
}

engine/src/test/java/com/arcadedb/index/MultipleTypesIndexTest.java

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,47 @@ public void testCollection() {
7575
});
7676
}
7777

78+
@Test
79+
public void testNullItemInCollection() {
80+
database.transaction(() -> {
81+
final Index index = database.getSchema().getIndexByName(TYPE_NAME + "[keywords]");
82+
83+
MutableVertex v = database.newVertex(TYPE_NAME);
84+
v.set("id", TOT+1);
85+
v.set("firstName", "Mark");
86+
v.set("lastName", "Zuck");
87+
88+
final List<Object> list = new ArrayList<>();
89+
list.add(null);
90+
v.set("keywords", list);
91+
92+
v.save();
93+
94+
IndexCursor cursor = index.get(new Object[] { list });
95+
Assertions.assertTrue(cursor.hasNext());
96+
Assertions.assertEquals("Zuck", cursor.next().asVertex().getString("lastName"));
97+
Assertions.assertFalse(cursor.hasNext());
98+
});
99+
}
100+
101+
// Issue https://github.com/ArcadeData/arcadedb/issues/812
102+
@Test
103+
public void testUpdateCompositeKeyIndex() {
104+
VertexType type = database.getSchema().createVertexType("IndexedVertex");
105+
type.createProperty("counter", Type.INTEGER);
106+
type.createProperty("status", Type.STRING);
107+
type.createTypeIndex(Schema.INDEX_TYPE.LSM_TREE, true, "status", "counter");
108+
109+
database.transaction(() -> {
110+
database.newVertex("IndexedVertex").set("id", "test1").set("status", "on").set("counter", 1).save();
111+
database.newVertex("IndexedVertex").set("id", "test2").set("status", "on").set("counter", 2).save();
112+
database.newVertex("IndexedVertex").set("id", "test3").set("status", "on").set("counter", 3).save();
113+
114+
database.command("SQL", "update IndexedVertex set status = 'off' where counter = 2");
115+
database.command("SQL", "update IndexedVertex set status = 'off' where counter = 3");
116+
});
117+
}
118+
78119
protected void beginTest() {
79120
database.transaction(() -> {
80121
Assertions.assertFalse(database.getSchema().existsType(TYPE_NAME));
@@ -115,22 +156,4 @@ protected void beginTest() {
115156
database.begin();
116157
});
117158
}
118-
119-
// Issue https://github.com/ArcadeData/arcadedb/issues/812
120-
@Test
121-
public void testUpdateCompositeKeyIndex() {
122-
VertexType type = database.getSchema().createVertexType("IndexedVertex");
123-
type.createProperty("counter", Type.INTEGER);
124-
type.createProperty("status", Type.STRING);
125-
type.createTypeIndex(Schema.INDEX_TYPE.LSM_TREE, true, "status", "counter");
126-
127-
database.transaction(() -> {
128-
database.newVertex("IndexedVertex").set("id", "test1").set("status", "on").set("counter", 1).save();
129-
database.newVertex("IndexedVertex").set("id", "test2").set("status", "on").set("counter", 2).save();
130-
database.newVertex("IndexedVertex").set("id", "test3").set("status", "on").set("counter", 3).save();
131-
132-
database.command("SQL", "update IndexedVertex set status = 'off' where counter = 2");
133-
database.command("SQL", "update IndexedVertex set status = 'off' where counter = 3");
134-
});
135-
}
136159
}

0 commit comments

Comments
 (0)