Search in sources :

Example 1 with TableQuery

use of com.microsoft.azure.storage.table.TableQuery in project YCSB by brianfrankcooper.

the class AzureClient method scan.

@Override
public Status scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
    try {
        String whereStr = String.format("(PartitionKey eq '%s') and (RowKey ge '%s')", partitionKey, startkey);
        TableQuery<DynamicTableEntity> scanQuery = new TableQuery<DynamicTableEntity>(DynamicTableEntity.class).where(whereStr).take(recordcount);
        int cnt = 0;
        for (DynamicTableEntity entity : cloudTable.execute(scanQuery)) {
            HashMap<String, EntityProperty> properties = entity.getProperties();
            HashMap<String, ByteIterator> cur = new HashMap<String, ByteIterator>();
            for (Entry<String, EntityProperty> entry : properties.entrySet()) {
                String fieldName = entry.getKey();
                ByteIterator fieldVal = new ByteArrayByteIterator(entry.getValue().getValueAsByteArray());
                if (fields == null || fields.contains(fieldName)) {
                    cur.put(fieldName, fieldVal);
                }
            }
            result.add(cur);
            if (++cnt == recordcount) {
                break;
            }
        }
        return Status.OK;
    } catch (Exception e) {
        return Status.ERROR;
    }
}
Also used : HashMap(java.util.HashMap) DBException(com.yahoo.ycsb.DBException) DynamicTableEntity(com.microsoft.azure.storage.table.DynamicTableEntity) EntityProperty(com.microsoft.azure.storage.table.EntityProperty) ByteArrayByteIterator(com.yahoo.ycsb.ByteArrayByteIterator) ByteArrayByteIterator(com.yahoo.ycsb.ByteArrayByteIterator) ByteIterator(com.yahoo.ycsb.ByteIterator) TableQuery(com.microsoft.azure.storage.table.TableQuery)

Aggregations

DynamicTableEntity (com.microsoft.azure.storage.table.DynamicTableEntity)1 EntityProperty (com.microsoft.azure.storage.table.EntityProperty)1 TableQuery (com.microsoft.azure.storage.table.TableQuery)1 ByteArrayByteIterator (com.yahoo.ycsb.ByteArrayByteIterator)1 ByteIterator (com.yahoo.ycsb.ByteIterator)1 DBException (com.yahoo.ycsb.DBException)1 HashMap (java.util.HashMap)1