Skip to content

Commit

Permalink
test: add test cases for insert into index operations
Browse files Browse the repository at this point in the history
  • Loading branch information
tglman committed Oct 23, 2023
1 parent 61ed0ce commit 4ac62e8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private OResultInternal produce(OCommandContext ctx) {
if (body.getContent() != null) {
throw new OCommandExecutionException("Invalid expression: INSERT INTO INDEX:... CONTENT ...");
}
int count;
long count;
if (setExps != null) {
count = handleSet(setExps, index, ctx);
} else {
Expand All @@ -68,7 +68,7 @@ private OResultInternal produce(OCommandContext ctx) {
return result;
}

private int handleKeyValues(
private long handleKeyValues(
List<OIdentifier> identifierList,
List<List<OExpression>> setExpressions,
OIndex index,
Expand All @@ -78,7 +78,7 @@ private int handleKeyValues(
if (identifierList == null || setExpressions == null) {
throw new OCommandExecutionException("Invalid insert expression");
}
int count = 0;
long count = 0;
for (List<OExpression> valList : setExpressions) {
if (identifierList.size() != valList.size()) {
throw new OCommandExecutionException("Invalid insert expression");
Expand All @@ -100,7 +100,7 @@ private int handleKeyValues(
return count;
}

private int handleSet(List<OInsertSetExpression> setExps, OIndex index, OCommandContext ctx) {
private long handleSet(List<OInsertSetExpression> setExps, OIndex index, OCommandContext ctx) {
OExpression keyExp = null;
OExpression valueExp = null;
for (OInsertSetExpression exp : setExps) {
Expand All @@ -118,9 +118,9 @@ private int handleSet(List<OInsertSetExpression> setExps, OIndex index, OCommand
return doExecute(index, ctx, keyExp, valueExp);
}

private int doExecute(
private long doExecute(
OIndex index, OCommandContext ctx, OExpression keyExp, OExpression valueExp) {
int count = 0;
long count = 0;
Object key = keyExp.execute((OResult) null, ctx);
Object value = valueExp.execute((OResult) null, ctx);
if (value instanceof OIdentifiable) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.orientechnologies.orient.core.sql.executor;

import static com.orientechnologies.orient.core.sql.executor.ExecutionPlanPrintUtils.printExecutionPlan;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

import com.orientechnologies.BaseMemoryDatabase;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.id.ORecordId;
import com.orientechnologies.orient.core.record.impl.ODocument;
import java.util.Collection;
import java.util.HashMap;
Expand Down Expand Up @@ -457,4 +460,22 @@ public void testQuotedCharactersInJson() {
Assert.assertFalse(result.hasNext());
result.close();
}

@Test
public void testInsertIndexTest() {
db.command("CREATE INDEX testInsert UNIQUE STRING ");

try (OResultSet insert = db.command("INSERT INTO index:testInsert set key='one', rid=#5:0")) {
assertEquals((long) insert.next().getProperty("count"), 1L);
assertFalse(insert.hasNext());
}

try (OResultSet result = db.query("SELECT FROM index:testInsert ")) {

OResult item = result.next();
assertEquals(item.getProperty("key"), "one");
assertEquals(item.getProperty("rid"), new ORecordId(5, 0));
assertFalse(result.hasNext());
}
}
}

0 comments on commit 4ac62e8

Please sign in to comment.