Search in sources :

Example 96 with ByteIterator

use of site.ycsb.ByteIterator in project YCSB by brianfrankcooper.

the class ScyllaCQLClientTest method testReadSingleColumn.

@Test
public void testReadSingleColumn() {
    insertRow();
    final HashMap<String, ByteIterator> result = new HashMap<>();
    final Set<String> fields = Sets.newHashSet("field1");
    final Status status = client.read(TABLE, DEFAULT_ROW_KEY, fields, result);
    assertThat(status, is(Status.OK));
    assertThat(result.entrySet(), hasSize(1));
    final Map<String, String> strResult = StringByteIterator.getStringMap(result);
    assertThat(strResult, hasEntry("field1", "value2"));
}
Also used : Status(site.ycsb.Status) ByteIterator(site.ycsb.ByteIterator) StringByteIterator(site.ycsb.StringByteIterator) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 97 with ByteIterator

use of site.ycsb.ByteIterator in project YCSB by brianfrankcooper.

the class CloudSpannerClient method scan.

@Override
public Status scan(String table, String startKey, int recordCount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
    if (queriesForReads) {
        return scanUsingQuery(table, startKey, recordCount, fields, result);
    }
    Iterable<String> columns = fields == null ? STANDARD_FIELDS : fields;
    KeySet keySet = KeySet.newBuilder().addRange(KeyRange.closedClosed(Key.of(startKey), Key.of())).build();
    try (ResultSet resultSet = dbClient.singleUse(timestampBound).read(table, keySet, columns, Options.limit(recordCount))) {
        while (resultSet.next()) {
            HashMap<String, ByteIterator> row = new HashMap<>();
            decodeStruct(columns, resultSet, row);
            result.add(row);
        }
        return Status.OK;
    } catch (Exception e) {
        LOGGER.log(Level.INFO, "scan()", e);
        return Status.ERROR;
    }
}
Also used : KeySet(com.google.cloud.spanner.KeySet) ByteIterator(site.ycsb.ByteIterator) StringByteIterator(site.ycsb.StringByteIterator) HashMap(java.util.HashMap) ResultSet(com.google.cloud.spanner.ResultSet) DBException(site.ycsb.DBException)

Example 98 with ByteIterator

use of site.ycsb.ByteIterator in project YCSB by brianfrankcooper.

the class CloudSpannerClient method scanUsingQuery.

private Status scanUsingQuery(String table, String startKey, int recordCount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
    Iterable<String> columns = fields == null ? STANDARD_FIELDS : fields;
    Statement query;
    if (fields == null || fields.size() == fieldCount) {
        query = Statement.newBuilder(standardScan).bind("startKey").to(startKey).bind("count").to(recordCount).build();
    } else {
        Joiner joiner = Joiner.on(',');
        query = Statement.newBuilder("SELECT ").append(joiner.join(fields)).append(" FROM ").append(table).append(" WHERE id>=@startKey LIMIT @count").bind("startKey").to(startKey).bind("count").to(recordCount).build();
    }
    try (ResultSet resultSet = dbClient.singleUse(timestampBound).executeQuery(query)) {
        while (resultSet.next()) {
            HashMap<String, ByteIterator> row = new HashMap<>();
            decodeStruct(columns, resultSet, row);
            result.add(row);
        }
        return Status.OK;
    } catch (Exception e) {
        LOGGER.log(Level.INFO, "scanUsingQuery()", e);
        return Status.ERROR;
    }
}
Also used : Joiner(com.google.common.base.Joiner) ByteIterator(site.ycsb.ByteIterator) StringByteIterator(site.ycsb.StringByteIterator) HashMap(java.util.HashMap) Statement(com.google.cloud.spanner.Statement) ResultSet(com.google.cloud.spanner.ResultSet) DBException(site.ycsb.DBException)

Example 99 with ByteIterator

use of site.ycsb.ByteIterator in project YCSB by brianfrankcooper.

the class AzureCosmosClient method scan.

/**
 * Perform a range scan for a set of records in the database. Each field/value
 * pair from the result will be stored in a HashMap.
 *
 * @param table       The name of the table
 * @param startkey    The record key of the first record to read.
 * @param recordcount The number of records to read
 * @param fields      The list of fields to read, or null for all of them
 * @param result      A Vector of HashMaps, where each HashMap is a set
 *                    field/value pairs for one record
 * @return Zero on success, a non-zero error code on error
 */
@Override
public Status scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
    try {
        CosmosQueryRequestOptions queryOptions = new CosmosQueryRequestOptions();
        queryOptions.setMaxDegreeOfParallelism(AzureCosmosClient.maxDegreeOfParallelism);
        queryOptions.setMaxBufferedItemCount(AzureCosmosClient.maxBufferedItemCount);
        CosmosContainer container = AzureCosmosClient.containerCache.get(table);
        if (container == null) {
            container = AzureCosmosClient.database.getContainer(table);
            AzureCosmosClient.containerCache.put(table, container);
        }
        List<SqlParameter> paramList = new ArrayList<>();
        paramList.add(new SqlParameter("@startkey", startkey));
        SqlQuerySpec querySpec = new SqlQuerySpec(this.createSelectTop(fields, recordcount) + " FROM root r WHERE r.id >= @startkey", paramList);
        CosmosPagedIterable<ObjectNode> pagedIterable = container.queryItems(querySpec, queryOptions, ObjectNode.class);
        Iterator<FeedResponse<ObjectNode>> pageIterator = pagedIterable.iterableByPage(AzureCosmosClient.preferredPageSize).iterator();
        while (pageIterator.hasNext()) {
            List<ObjectNode> pageDocs = pageIterator.next().getResults();
            for (ObjectNode doc : pageDocs) {
                Map<String, String> stringResults = new HashMap<>(doc.size());
                Iterator<Map.Entry<String, JsonNode>> nodeIterator = doc.fields();
                while (nodeIterator.hasNext()) {
                    Entry<String, JsonNode> pair = nodeIterator.next();
                    stringResults.put(pair.getKey().toString(), pair.getValue().toString());
                }
                HashMap<String, ByteIterator> byteResults = new HashMap<>(doc.size());
                StringByteIterator.putAllAsByteIterators(byteResults, stringResults);
                result.add(byteResults);
            }
        }
        return Status.OK;
    } catch (CosmosException e) {
        if (!AzureCosmosClient.includeExceptionStackInLog) {
            e = null;
        }
        LOGGER.error("Failed to query key {} from collection {} in database {}", startkey, table, AzureCosmosClient.databaseName, e);
    }
    return Status.ERROR;
}
Also used : SqlParameter(com.azure.cosmos.models.SqlParameter) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) CosmosContainer(com.azure.cosmos.CosmosContainer) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) FeedResponse(com.azure.cosmos.models.FeedResponse) CosmosQueryRequestOptions(com.azure.cosmos.models.CosmosQueryRequestOptions) Entry(java.util.Map.Entry) SqlQuerySpec(com.azure.cosmos.models.SqlQuerySpec) ByteIterator(site.ycsb.ByteIterator) StringByteIterator(site.ycsb.StringByteIterator) CosmosException(com.azure.cosmos.CosmosException)

Example 100 with ByteIterator

use of site.ycsb.ByteIterator 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, Map<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(site.ycsb.DBException) EntityProperty(com.microsoft.azure.storage.table.EntityProperty) ByteArrayByteIterator(site.ycsb.ByteArrayByteIterator) ByteIterator(site.ycsb.ByteIterator) ByteArrayByteIterator(site.ycsb.ByteArrayByteIterator)

Aggregations

ByteIterator (site.ycsb.ByteIterator)131 HashMap (java.util.HashMap)98 StringByteIterator (site.ycsb.StringByteIterator)92 Status (site.ycsb.Status)62 Test (org.junit.Test)53 ByteArrayByteIterator (site.ycsb.ByteArrayByteIterator)34 DBException (site.ycsb.DBException)30 Map (java.util.Map)20 IOException (java.io.IOException)10 Put (org.apache.hadoop.hbase.client.Put)8 ArrayList (java.util.ArrayList)7 Vector (java.util.Vector)7 ByteBuffer (java.nio.ByteBuffer)6 HashSet (java.util.HashSet)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 NumericByteIterator (site.ycsb.NumericByteIterator)5 EntityProperty (com.microsoft.azure.storage.table.EntityProperty)4 Properties (java.util.Properties)4 Assume.assumeNoException (org.junit.Assume.assumeNoException)4 DB (site.ycsb.DB)4