use of com.orientechnologies.orient.core.index.OIndexCursor in project orientdb by orientechnologies.
the class IndexTxAwareOneValueGetValuesTest method testMultiPut.
@Test
public void testMultiPut() {
database.getMetadata().getIndexManager().reload();
database.begin();
final OIndex<?> index = database.getMetadata().getIndexManager().getIndex("idxTxAwareOneValueGetValuesTest");
Assert.assertTrue(index instanceof OIndexTxAwareOneValue);
final int clusterId = database.getDefaultClusterId();
index.put(1, new ORecordId(clusterId, 1));
index.put(1, new ORecordId(clusterId, 1));
index.put(2, new ORecordId(clusterId, 2));
Assert.assertNotNull(database.getTransaction().getIndexChanges("idxTxAwareOneValueGetValuesTest"));
Set<OIdentifiable> result = new HashSet<OIdentifiable>();
OIndexCursor cursor = index.iterateEntries(Arrays.asList(1, 2), true);
cursorToSet(cursor, result);
Assert.assertEquals(result.size(), 2);
database.commit();
cursor = index.iterateEntries(Arrays.asList(1, 2), true);
cursorToSet(cursor, result);
Assert.assertEquals(result.size(), 2);
}
use of com.orientechnologies.orient.core.index.OIndexCursor in project orientdb by orientechnologies.
the class OQueryOperatorMinor method executeIndexQuery.
@Override
public OIndexCursor executeIndexQuery(OCommandContext iContext, OIndex<?> index, List<Object> keyParams, boolean ascSortOrder) {
final OIndexDefinition indexDefinition = index.getDefinition();
final OIndexInternal<?> internalIndex = index.getInternal();
if (!internalIndex.canBeUsedInEqualityOperators() || !internalIndex.hasRangeQuerySupport())
return null;
final OIndexCursor cursor;
if (indexDefinition.getParamCount() == 1) {
final Object key;
if (indexDefinition instanceof OIndexDefinitionMultiValue)
key = ((OIndexDefinitionMultiValue) indexDefinition).createSingleValue(keyParams.get(0));
else
key = indexDefinition.createValue(keyParams);
if (key == null)
return null;
cursor = index.iterateEntriesMinor(key, false, ascSortOrder);
} else {
// if we have situation like "field1 = 1 AND field2 < 2"
// then we fetch collection which left included boundary is the smallest composite key in the
// index that contains key with value field1=1 and which right not included boundary
// is the biggest composite key in the index that contains key with values field1=1 and field2=2.
final OCompositeIndexDefinition compositeIndexDefinition = (OCompositeIndexDefinition) indexDefinition;
final Object keyOne = compositeIndexDefinition.createSingleValue(keyParams.subList(0, keyParams.size() - 1));
if (keyOne == null)
return null;
final Object keyTwo = compositeIndexDefinition.createSingleValue(keyParams);
if (keyTwo == null)
return null;
cursor = index.iterateEntriesBetween(keyOne, true, keyTwo, false, ascSortOrder);
}
updateProfiler(iContext, index, keyParams, indexDefinition);
return cursor;
}
use of com.orientechnologies.orient.core.index.OIndexCursor in project orientdb by orientechnologies.
the class TruncateClassTest method testTruncateClass.
@SuppressWarnings("unchecked")
@Test
public void testTruncateClass() {
OSchema schema = database.getMetadata().getSchema();
OClass testClass = getOrCreateClass(schema);
final OIndex<?> index = getOrCreateIndex(testClass);
schema.save();
database.command(new OCommandSQL("truncate class test_class")).execute();
database.save(new ODocument(testClass).field("name", "x").field("data", Arrays.asList(1, 2)));
database.save(new ODocument(testClass).field("name", "y").field("data", Arrays.asList(3, 0)));
database.command(new OCommandSQL("truncate class test_class")).execute();
database.save(new ODocument(testClass).field("name", "x").field("data", Arrays.asList(5, 6, 7)));
database.save(new ODocument(testClass).field("name", "y").field("data", Arrays.asList(8, 9, -1)));
List<ODocument> result = database.query(new OSQLSynchQuery<ODocument>("select from test_class"));
Assert.assertEquals(result.size(), 2);
Set<Integer> set = new HashSet<Integer>();
for (ODocument document : result) {
set.addAll((Collection<Integer>) document.field("data"));
}
Assert.assertTrue(set.containsAll(Arrays.asList(5, 6, 7, 8, 9, -1)));
Assert.assertEquals(index.getSize(), 6);
OIndexCursor cursor = index.cursor();
Map.Entry<Object, OIdentifiable> entry = cursor.nextEntry();
while (entry != null) {
Assert.assertTrue(set.contains((Integer) entry.getKey()));
entry = cursor.nextEntry();
}
schema.dropClass("test_class");
}
use of com.orientechnologies.orient.core.index.OIndexCursor in project YCSB by brianfrankcooper.
the class OrientDBClient method scan.
@Override
public Status scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
if (isRemote) {
// Iterator methods needed for scanning are Unsupported for remote database connections.
LOG.warn("OrientDB scan operation is not implemented for remote database connections.");
return Status.NOT_IMPLEMENTED;
}
try (ODatabaseDocumentTx db = databasePool.acquire()) {
final ODictionary<ORecord> dictionary = db.getMetadata().getIndexManager().getDictionary();
final OIndexCursor entries = dictionary.getIndex().iterateEntriesMajor(startkey, true, true);
int currentCount = 0;
while (entries.hasNext()) {
final ODocument document = entries.next().getRecord();
final HashMap<String, ByteIterator> map = new HashMap<>();
result.add(map);
if (fields != null) {
for (String field : fields) {
map.put(field, new StringByteIterator((String) document.field(field)));
}
} else {
for (String field : document.fieldNames()) {
map.put(field, new StringByteIterator((String) document.field(field)));
}
}
currentCount++;
if (currentCount >= recordcount) {
break;
}
}
return Status.OK;
} catch (Exception e) {
e.printStackTrace();
}
return Status.ERROR;
}
use of com.orientechnologies.orient.core.index.OIndexCursor in project orientdb by orientechnologies.
the class OQueryOperatorBetween method executeIndexQuery.
@Override
public OIndexCursor executeIndexQuery(OCommandContext iContext, OIndex<?> index, List<Object> keyParams, boolean ascSortOrder) {
final OIndexDefinition indexDefinition = index.getDefinition();
OIndexCursor cursor;
final OIndexInternal<?> internalIndex = index.getInternal();
if (!internalIndex.canBeUsedInEqualityOperators() || !internalIndex.hasRangeQuerySupport())
return null;
if (indexDefinition.getParamCount() == 1) {
final Object[] betweenKeys = (Object[]) keyParams.get(0);
final Object keyOne = indexDefinition.createValue(Collections.singletonList(OSQLHelper.getValue(betweenKeys[0])));
final Object keyTwo = indexDefinition.createValue(Collections.singletonList(OSQLHelper.getValue(betweenKeys[2])));
if (keyOne == null || keyTwo == null)
return null;
cursor = index.iterateEntriesBetween(keyOne, leftInclusive, keyTwo, rightInclusive, ascSortOrder);
} else {
final OCompositeIndexDefinition compositeIndexDefinition = (OCompositeIndexDefinition) indexDefinition;
final Object[] betweenKeys = (Object[]) keyParams.get(keyParams.size() - 1);
final Object betweenKeyOne = OSQLHelper.getValue(betweenKeys[0]);
if (betweenKeyOne == null)
return null;
final Object betweenKeyTwo = OSQLHelper.getValue(betweenKeys[2]);
if (betweenKeyTwo == null)
return null;
final List<Object> betweenKeyOneParams = new ArrayList<Object>(keyParams.size());
betweenKeyOneParams.addAll(keyParams.subList(0, keyParams.size() - 1));
betweenKeyOneParams.add(betweenKeyOne);
final List<Object> betweenKeyTwoParams = new ArrayList<Object>(keyParams.size());
betweenKeyTwoParams.addAll(keyParams.subList(0, keyParams.size() - 1));
betweenKeyTwoParams.add(betweenKeyTwo);
final Object keyOne = compositeIndexDefinition.createSingleValue(betweenKeyOneParams);
if (keyOne == null)
return null;
final Object keyTwo = compositeIndexDefinition.createSingleValue(betweenKeyTwoParams);
if (keyTwo == null)
return null;
cursor = index.iterateEntriesBetween(keyOne, leftInclusive, keyTwo, rightInclusive, ascSortOrder);
}
updateProfiler(iContext, index, keyParams, indexDefinition);
return cursor;
}
Aggregations