use of com.orientechnologies.orient.core.record.ORecord in project YCSB by brianfrankcooper.
the class OrientDBClient method read.
@Override
public Status read(String table, String key, Set<String> fields, HashMap<String, ByteIterator> result) {
try (ODatabaseDocumentTx db = databasePool.acquire()) {
final ODictionary<ORecord> dictionary = db.getMetadata().getIndexManager().getDictionary();
final ODocument document = dictionary.get(key);
if (document != null) {
if (fields != null) {
for (String field : fields) {
result.put(field, new StringByteIterator((String) document.field(field)));
}
} else {
for (String field : document.fieldNames()) {
result.put(field, new StringByteIterator((String) document.field(field)));
}
}
return Status.OK;
}
} catch (Exception e) {
e.printStackTrace();
}
return Status.ERROR;
}
use of com.orientechnologies.orient.core.record.ORecord 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.record.ORecord in project YCSB by brianfrankcooper.
the class OrientDBClientTest method deleteTest.
@Test
public void deleteTest() {
String user0 = "user0";
String user1 = "user1";
String user2 = "user2";
insertRow(user0);
insertRow(user1);
insertRow(user2);
orientDBClient.delete(CLASS, user1);
OPartitionedDatabasePool pool = orientDBClient.getDatabasePool();
try (ODatabaseDocumentTx db = pool.acquire()) {
ODictionary<ORecord> dictionary = db.getDictionary();
assertNotNull("Assert user0 still exists", dictionary.get(user0));
assertNull("Assert user1 does not exist", dictionary.get(user1));
assertNotNull("Assert user2 still exists", dictionary.get(user2));
}
}
use of com.orientechnologies.orient.core.record.ORecord in project YCSB by brianfrankcooper.
the class OrientDBClientTest method insertTest.
@Test
public void insertTest() {
String insertKey = "user0";
Map<String, ByteIterator> insertMap = insertRow(insertKey);
OPartitionedDatabasePool pool = orientDBClient.getDatabasePool();
try (ODatabaseDocumentTx db = pool.acquire()) {
ODictionary<ORecord> dictionary = db.getDictionary();
ODocument result = dictionary.get(insertKey);
assertTrue("Assert a row was inserted.", result != null);
for (int i = 0; i < NUM_FIELDS; i++) {
assertEquals("Assert all inserted columns have correct values.", result.field(FIELD_PREFIX + i), insertMap.get(FIELD_PREFIX + i).toString());
}
}
}
use of com.orientechnologies.orient.core.record.ORecord in project orientdb by orientechnologies.
the class OFieldTransformer method executeTransform.
@Override
public Object executeTransform(final Object input) {
if (input instanceof OIdentifiable) {
final ORecord rec = ((OIdentifiable) input).getRecord();
if (rec instanceof ODocument) {
final ODocument doc = (ODocument) rec;
if (setOperation) {
final Object newValue;
if (expression != null) {
if (sqlFilter == null)
// ONLY THE FIRST TIME
sqlFilter = new OSQLFilter(expression, context, null);
newValue = sqlFilter.evaluate(doc, null, context);
} else
newValue = value;
// SET THE TRANSFORMED FIELD BACK
doc.field(fieldName, newValue);
log(OETLProcessor.LOG_LEVELS.DEBUG, "set %s=%s in document=%s", fieldName, newValue, doc);
} else {
if (fieldName != null) {
final Object prev = doc.removeField(fieldName);
log(OETLProcessor.LOG_LEVELS.DEBUG, "removed %s (value=%s) from document=%s", fieldName, prev, doc);
} else {
for (String f : fieldNames) {
final Object prev = doc.removeField(f);
log(OETLProcessor.LOG_LEVELS.DEBUG, "removed %s (value=%s) from document=%s", f, prev, doc);
}
}
}
if (save) {
log(OETLProcessor.LOG_LEVELS.DEBUG, "saving record %s", doc);
final ODatabaseDocument db = super.pipeline.getDocumentDatabase();
db.save(doc);
}
}
}
return input;
}
Aggregations