diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/executor/InsertIntoIndexStep.java b/core/src/main/java/com/orientechnologies/orient/core/sql/executor/InsertIntoIndexStep.java index de9c0902b1a..8cb7d720422 100755 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/executor/InsertIntoIndexStep.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/executor/InsertIntoIndexStep.java @@ -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 { @@ -68,7 +68,7 @@ private OResultInternal produce(OCommandContext ctx) { return result; } - private int handleKeyValues( + private long handleKeyValues( List identifierList, List> setExpressions, OIndex index, @@ -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 valList : setExpressions) { if (identifierList.size() != valList.size()) { throw new OCommandExecutionException("Invalid insert expression"); @@ -100,7 +100,7 @@ private int handleKeyValues( return count; } - private int handleSet(List setExps, OIndex index, OCommandContext ctx) { + private long handleSet(List setExps, OIndex index, OCommandContext ctx) { OExpression keyExp = null; OExpression valueExp = null; for (OInsertSetExpression exp : setExps) { @@ -118,9 +118,9 @@ private int handleSet(List 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) { diff --git a/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OInsertStatementExecutionTest.java b/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OInsertStatementExecutionTest.java index 75b21ca137d..df8942fcf1e 100755 --- a/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OInsertStatementExecutionTest.java +++ b/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OInsertStatementExecutionTest.java @@ -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; @@ -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()); + } + } }