Search in sources :

Example 1 with EntityProperty

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

the class AzureClient method insertOrUpdate.

private Status insertOrUpdate(String key, HashMap<String, ByteIterator> values) {
    HashMap<String, EntityProperty> properties = new HashMap<String, EntityProperty>();
    for (Entry<String, ByteIterator> entry : values.entrySet()) {
        String fieldName = entry.getKey();
        byte[] fieldVal = entry.getValue().toArray();
        properties.put(fieldName, new EntityProperty(fieldVal));
    }
    DynamicTableEntity entity = new DynamicTableEntity(partitionKey, key, properties);
    TableOperation insertOrReplace = TableOperation.insertOrReplace(entity);
    try {
        cloudTable.execute(insertOrReplace);
        return Status.OK;
    } catch (Exception e) {
        return Status.ERROR;
    }
}
Also used : EntityProperty(com.microsoft.azure.storage.table.EntityProperty) DynamicTableEntity(com.microsoft.azure.storage.table.DynamicTableEntity) ByteArrayByteIterator(com.yahoo.ycsb.ByteArrayByteIterator) ByteIterator(com.yahoo.ycsb.ByteIterator) HashMap(java.util.HashMap) TableOperation(com.microsoft.azure.storage.table.TableOperation) DBException(com.yahoo.ycsb.DBException)

Example 2 with EntityProperty

use of com.microsoft.azure.storage.table.EntityProperty 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)

Example 3 with EntityProperty

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

the class AzureClient method insertBatch.

private Status insertBatch(String key, HashMap<String, ByteIterator> values) {
    HashMap<String, EntityProperty> properties = new HashMap<String, EntityProperty>();
    for (Entry<String, ByteIterator> entry : values.entrySet()) {
        String fieldName = entry.getKey();
        byte[] fieldVal = entry.getValue().toArray();
        properties.put(fieldName, new EntityProperty(fieldVal));
    }
    DynamicTableEntity entity = new DynamicTableEntity(partitionKey, key, properties);
    BATCH_OPERATION.insertOrReplace(entity);
    if (++curIdx == batchSize) {
        try {
            cloudTable.execute(BATCH_OPERATION);
            BATCH_OPERATION.clear();
            curIdx = 0;
        } catch (Exception e) {
            return Status.ERROR;
        }
    }
    return Status.OK;
}
Also used : EntityProperty(com.microsoft.azure.storage.table.EntityProperty) DynamicTableEntity(com.microsoft.azure.storage.table.DynamicTableEntity) ByteArrayByteIterator(com.yahoo.ycsb.ByteArrayByteIterator) ByteIterator(com.yahoo.ycsb.ByteIterator) HashMap(java.util.HashMap) DBException(com.yahoo.ycsb.DBException)

Example 4 with EntityProperty

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

the class AzureClient method readEntity.

private Status readEntity(String key, HashMap<String, ByteIterator> result) {
    try {
        // firstly, retrieve the entity to be deleted
        TableOperation retrieveOp = TableOperation.retrieve(partitionKey, key, DynamicTableEntity.class);
        DynamicTableEntity entity = cloudTable.execute(retrieveOp).getResultAsType();
        HashMap<String, EntityProperty> properties = entity.getProperties();
        for (Entry<String, EntityProperty> entry : properties.entrySet()) {
            String fieldName = entry.getKey();
            ByteIterator fieldVal = new ByteArrayByteIterator(entry.getValue().getValueAsByteArray());
            result.put(fieldName, fieldVal);
        }
        return Status.OK;
    } catch (Exception e) {
        return Status.ERROR;
    }
}
Also used : 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) TableOperation(com.microsoft.azure.storage.table.TableOperation) DBException(com.yahoo.ycsb.DBException)

Example 5 with EntityProperty

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

the class AzureClient method readSubset.

/*
   * Read subset of properties instead of full fields with projection.
   */
public Status readSubset(String key, Set<String> fields, HashMap<String, ByteIterator> result) {
    String whereStr = String.format("RowKey eq '%s'", key);
    TableQuery<TableServiceEntity> projectionQuery = TableQuery.from(TableServiceEntity.class).where(whereStr).select(fields.toArray(new String[0]));
    EntityResolver<HashMap<String, ByteIterator>> resolver = new EntityResolver<HashMap<String, ByteIterator>>() {

        public HashMap<String, ByteIterator> resolve(String partitionkey, String rowKey, Date timeStamp, HashMap<String, EntityProperty> properties, String etag) {
            HashMap<String, ByteIterator> tmp = new HashMap<String, ByteIterator>();
            for (Entry<String, EntityProperty> entry : properties.entrySet()) {
                String key = entry.getKey();
                ByteIterator val = new ByteArrayByteIterator(entry.getValue().getValueAsByteArray());
                tmp.put(key, val);
            }
            return tmp;
        }
    };
    try {
        for (HashMap<String, ByteIterator> tmp : cloudTable.execute(projectionQuery, resolver)) {
            for (Entry<String, ByteIterator> entry : tmp.entrySet()) {
                String fieldName = entry.getKey();
                ByteIterator fieldVal = entry.getValue();
                result.put(fieldName, fieldVal);
            }
        }
        return Status.OK;
    } catch (Exception e) {
        return Status.ERROR;
    }
}
Also used : HashMap(java.util.HashMap) EntityResolver(com.microsoft.azure.storage.table.EntityResolver) TableServiceEntity(com.microsoft.azure.storage.table.TableServiceEntity) Date(java.util.Date) DBException(com.yahoo.ycsb.DBException) EntityProperty(com.microsoft.azure.storage.table.EntityProperty) ByteArrayByteIterator(com.yahoo.ycsb.ByteArrayByteIterator) ByteArrayByteIterator(com.yahoo.ycsb.ByteArrayByteIterator) ByteIterator(com.yahoo.ycsb.ByteIterator)

Aggregations

EntityProperty (com.microsoft.azure.storage.table.EntityProperty)5 ByteArrayByteIterator (com.yahoo.ycsb.ByteArrayByteIterator)5 ByteIterator (com.yahoo.ycsb.ByteIterator)5 DBException (com.yahoo.ycsb.DBException)5 DynamicTableEntity (com.microsoft.azure.storage.table.DynamicTableEntity)4 HashMap (java.util.HashMap)4 TableOperation (com.microsoft.azure.storage.table.TableOperation)2 EntityResolver (com.microsoft.azure.storage.table.EntityResolver)1 TableQuery (com.microsoft.azure.storage.table.TableQuery)1 TableServiceEntity (com.microsoft.azure.storage.table.TableServiceEntity)1 Date (java.util.Date)1