Search in sources :

Example 11 with ByteIterator

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

the class ElasticsearchRestClient method scan.

@Override
public Status scan(final String table, final String startkey, final int recordcount, final Set<String> fields, final Vector<HashMap<String, ByteIterator>> result) {
    try {
        final Response response;
        try (XContentBuilder builder = jsonBuilder()) {
            builder.startObject();
            builder.startObject("query");
            builder.startObject("range");
            builder.startObject(KEY);
            builder.field("gte", startkey);
            builder.endObject();
            builder.endObject();
            builder.endObject();
            builder.field("size", recordcount);
            builder.endObject();
            response = search(table, builder);
            @SuppressWarnings("unchecked") final Map<String, Object> map = map(response);
            @SuppressWarnings("unchecked") final Map<String, Object> hits = (Map<String, Object>) map.get("hits");
            @SuppressWarnings("unchecked") final List<Map<String, Object>> list = (List<Map<String, Object>>) hits.get("hits");
            for (final Map<String, Object> hit : list) {
                @SuppressWarnings("unchecked") final Map<String, Object> source = (Map<String, Object>) hit.get("_source");
                final HashMap<String, ByteIterator> entry;
                if (fields != null) {
                    entry = new HashMap<>(fields.size());
                    for (final String field : fields) {
                        entry.put(field, new StringByteIterator((String) source.get(field)));
                    }
                } else {
                    entry = new HashMap<>(hit.size());
                    for (final Map.Entry<String, Object> field : source.entrySet()) {
                        if (KEY.equals(field.getKey())) {
                            continue;
                        }
                        entry.put(field.getKey(), new StringByteIterator((String) field.getValue()));
                    }
                }
                result.add(entry);
            }
        }
        return Status.OK;
    } catch (final Exception e) {
        e.printStackTrace();
        return Status.ERROR;
    }
}
Also used : IOException(java.io.IOException) DBException(site.ycsb.DBException) Response(org.elasticsearch.client.Response) ByteIterator(site.ycsb.ByteIterator) StringByteIterator(site.ycsb.StringByteIterator) StringByteIterator(site.ycsb.StringByteIterator) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Collections.emptyMap(java.util.Collections.emptyMap) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 12 with ByteIterator

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

the class ZKClientTest method testZKClient.

@Test
public void testZKClient() {
    // insert
    Map<String, String> m = new HashMap<>();
    String field1 = "field_1";
    String value1 = "value_1";
    m.put(field1, value1);
    Map<String, ByteIterator> result = StringByteIterator.getByteIteratorMap(m);
    client.insert(tableName, path, result);
    // read
    result.clear();
    Status status = client.read(tableName, path, null, result);
    assertEquals(Status.OK, status);
    assertEquals(1, result.size());
    assertEquals(value1, result.get(field1).toString());
    // update(the same field)
    m.clear();
    result.clear();
    String newVal = "value_new";
    m.put(field1, newVal);
    result = StringByteIterator.getByteIteratorMap(m);
    client.update(tableName, path, result);
    assertEquals(1, result.size());
    // Verify result
    result.clear();
    status = client.read(tableName, path, null, result);
    assertEquals(Status.OK, status);
    // here we only have one field: field_1
    assertEquals(1, result.size());
    assertEquals(newVal, result.get(field1).toString());
    // update(two different field)
    m.clear();
    result.clear();
    String field2 = "field_2";
    String value2 = "value_2";
    m.put(field2, value2);
    result = StringByteIterator.getByteIteratorMap(m);
    client.update(tableName, path, result);
    assertEquals(1, result.size());
    // Verify result
    result.clear();
    status = client.read(tableName, path, null, result);
    assertEquals(Status.OK, status);
    // here we have two field: field_1 and field_2
    assertEquals(2, result.size());
    assertEquals(value2, result.get(field2).toString());
    assertEquals(newVal, result.get(field1).toString());
    // delete
    status = client.delete(tableName, path);
    assertEquals(Status.OK, status);
    // Verify result
    result.clear();
    status = client.read(tableName, path, null, result);
    // NoNode return ERROR
    assertEquals(Status.ERROR, status);
    assertEquals(0, result.size());
}
Also used : Status(site.ycsb.Status) ByteIterator(site.ycsb.ByteIterator) StringByteIterator(site.ycsb.StringByteIterator) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 13 with ByteIterator

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

the class SeaweedClient method update.

/**
 * Update a file in the table. Any field/value pairs in the specified
 * values HashMap will be written into the file with the specified file
 * key, overwriting any existing values with the same field name.
 *
 * @param tableName The name of the table
 * @param key  The file key of the file to write.
 * @param values A HashMap of field/value pairs to update in the record
 * @return OK on success, ERORR otherwise.
 */
@Override
public Status update(String tableName, String key, Map<String, ByteIterator> values) {
    Map<String, ByteIterator> existingValues = new HashMap<>();
    Status readStatus = readFromStorage(tableName, key, null, existingValues);
    if (readStatus != Status.OK) {
        return readStatus;
    }
    existingValues.putAll(values);
    return writeToStorage(tableName, key, existingValues);
}
Also used : Status(site.ycsb.Status) ByteIterator(site.ycsb.ByteIterator) StringByteIterator(site.ycsb.StringByteIterator) HashMap(java.util.HashMap)

Example 14 with ByteIterator

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

the class SolrClient 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. See this class's description for a
 *         discussion of error codes.
 */
@Override
public Status scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
    try {
        Boolean returnFields = false;
        String[] fieldList = null;
        if (fields != null) {
            returnFields = true;
            fieldList = fields.toArray(new String[fields.size()]);
        }
        SolrQuery query = new SolrQuery();
        query.setQuery("*:*");
        query.setParam("fq", "id:[ " + startkey + " TO * ]");
        if (returnFields) {
            query.setFields(fieldList);
        }
        query.setRows(recordcount);
        final QueryResponse response = client.query(table, query);
        SolrDocumentList results = response.getResults();
        HashMap<String, ByteIterator> entry;
        for (SolrDocument hit : results) {
            entry = new HashMap<>((int) results.getNumFound());
            for (String field : hit.getFieldNames()) {
                entry.put(field, new StringByteIterator(String.valueOf(hit.getFirstValue(field))));
            }
            result.add(entry);
        }
        return checkStatus(response.getStatus());
    } catch (IOException | SolrServerException e) {
        e.printStackTrace();
    }
    return Status.ERROR;
}
Also used : SolrServerException(org.apache.solr.client.solrj.SolrServerException) SolrDocumentList(org.apache.solr.common.SolrDocumentList) IOException(java.io.IOException) SolrQuery(org.apache.solr.client.solrj.SolrQuery) SolrDocument(org.apache.solr.common.SolrDocument) ByteIterator(site.ycsb.ByteIterator) StringByteIterator(site.ycsb.StringByteIterator) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) StringByteIterator(site.ycsb.StringByteIterator)

Example 15 with ByteIterator

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

the class SolrClientBaseTest method testUpdate.

@Test
public void testUpdate() throws Exception {
    HashMap<String, ByteIterator> newValues = new HashMap<>(NUM_RECORDS);
    for (int i = 0; i < NUM_RECORDS; i++) {
        newValues.put(FIELD_PREFIX + i, new StringByteIterator("newvalue" + i));
    }
    Status result = instance.update(MOCK_TABLE, MOCK_KEY1, newValues);
    assertEquals(Status.OK, result);
    // validate that the values changed
    HashMap<String, ByteIterator> resultParam = new HashMap<>(NUM_RECORDS);
    instance.read(MOCK_TABLE, MOCK_KEY1, MOCK_DATA.keySet(), resultParam);
    for (int i = 0; i < NUM_RECORDS; i++) {
        assertEquals("newvalue" + i, resultParam.get(FIELD_PREFIX + i).toString());
    }
}
Also used : Status(site.ycsb.Status) ByteIterator(site.ycsb.ByteIterator) StringByteIterator(site.ycsb.StringByteIterator) HashMap(java.util.HashMap) StringByteIterator(site.ycsb.StringByteIterator)

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