Search in sources :

Example 16 with ByteIterator

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

the class S3Client method scanFromStorage.

/**
 * Perform an emulation of a database scan operation on a S3 bucket.
 *
 * @param bucket
 *            The name of the bucket
 * @param startkey
 *            The file key of the first file to read.
 * @param recordcount
 *            The number of files 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 file
 */
protected Status scanFromStorage(String bucket, String startkey, int recordcount, Vector<HashMap<String, ByteIterator>> result, SSECustomerKey ssecLocal) {
    int counter = 0;
    ObjectListing listing = s3Client.listObjects(bucket);
    List<S3ObjectSummary> summaries = listing.getObjectSummaries();
    List<String> keyList = new ArrayList();
    int startkeyNumber = 0;
    int numberOfIteration = 0;
    // getting the list of files in the bucket
    while (listing.isTruncated()) {
        listing = s3Client.listNextBatchOfObjects(listing);
        summaries.addAll(listing.getObjectSummaries());
    }
    for (S3ObjectSummary summary : summaries) {
        String summaryKey = summary.getKey();
        keyList.add(summaryKey);
    }
    // Sorting the list of files in Alphabetical order
    // sorting the list
    Collections.sort(keyList);
    // Getting the position of the startingfile for the scan
    for (String key : keyList) {
        if (key.equals(startkey)) {
            startkeyNumber = counter;
        } else {
            counter = counter + 1;
        }
    }
    // if not using the total number of Files
    if (recordcount < keyList.size()) {
        numberOfIteration = recordcount;
    } else {
        numberOfIteration = keyList.size();
    }
    // of the Files or Till the recordcount number
    for (int i = startkeyNumber; i < numberOfIteration; i++) {
        HashMap<String, ByteIterator> resultTemp = new HashMap<String, ByteIterator>();
        readFromStorage(bucket, keyList.get(i), resultTemp, ssecLocal);
        result.add(resultTemp);
    }
    return Status.OK;
}
Also used : ByteIterator(site.ycsb.ByteIterator) ByteArrayByteIterator(site.ycsb.ByteArrayByteIterator) HashMap(java.util.HashMap) ObjectListing(com.amazonaws.services.s3.model.ObjectListing) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary)

Example 17 with ByteIterator

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

the class ScyllaCQLClient 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.
 *
 * scylla CQL uses "token" method for range scan which doesn't always yield
 * intuitive results.
 *
 * @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 {
        PreparedStatement stmt = (fields == null) ? SCAN_ALL_STMT.get() : SCAN_STMTS.get(fields);
        // Prepare statement on demand
        if (stmt == null) {
            Select.Builder selectBuilder;
            if (fields == null) {
                selectBuilder = QueryBuilder.select().all();
            } else {
                selectBuilder = QueryBuilder.select();
                for (String col : fields) {
                    ((Select.Selection) selectBuilder).column(col);
                }
            }
            Select selectStmt = selectBuilder.from(table);
            // The statement builder is not setup right for tokens.
            // So, we need to build it manually.
            String initialStmt = selectStmt.toString();
            String scanStmt = initialStmt.substring(0, initialStmt.length() - 1) + " WHERE " + QueryBuilder.token(YCSB_KEY) + " >= token(" + QueryBuilder.bindMarker() + ")" + " LIMIT " + QueryBuilder.bindMarker();
            stmt = session.prepare(scanStmt);
            stmt.setConsistencyLevel(readConsistencyLevel);
            if (trace) {
                stmt.enableTracing();
            }
            PreparedStatement prevStmt = (fields == null) ? SCAN_ALL_STMT.getAndSet(stmt) : SCAN_STMTS.putIfAbsent(new HashSet<>(fields), stmt);
            if (prevStmt != null) {
                stmt = prevStmt;
            }
        }
        LOGGER.debug(stmt.getQueryString());
        LOGGER.debug("startKey = {}, recordcount = {}", startkey, recordcount);
        ResultSet rs = session.execute(stmt.bind(startkey, recordcount));
        HashMap<String, ByteIterator> tuple;
        while (!rs.isExhausted()) {
            Row row = rs.one();
            tuple = new HashMap<>();
            ColumnDefinitions cd = row.getColumnDefinitions();
            for (ColumnDefinitions.Definition def : cd) {
                ByteBuffer val = row.getBytesUnsafe(def.getName());
                if (val != null) {
                    tuple.put(def.getName(), new ByteArrayByteIterator(val.array()));
                } else {
                    tuple.put(def.getName(), null);
                }
            }
            result.add(tuple);
        }
        return Status.OK;
    } catch (Exception e) {
        LOGGER.error(MessageFormatter.format("Error scanning with startkey: {}", startkey).getMessage(), e);
        return Status.ERROR;
    }
}
Also used : ByteBuffer(java.nio.ByteBuffer) DBException(site.ycsb.DBException) ByteArrayByteIterator(site.ycsb.ByteArrayByteIterator) ByteIterator(site.ycsb.ByteIterator) ByteArrayByteIterator(site.ycsb.ByteArrayByteIterator) HashSet(java.util.HashSet)

Example 18 with ByteIterator

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

the class ScyllaCQLClientTest method testRead.

@Test
public void testRead() {
    insertRow();
    final HashMap<String, ByteIterator> result = new HashMap<>();
    final Status status = client.read(TABLE, DEFAULT_ROW_KEY, null, result);
    assertThat(status, is(Status.OK));
    assertThat(result.entrySet(), hasSize(11));
    assertThat(result, hasEntry("field2", null));
    final HashMap<String, String> strResult = new HashMap<>();
    for (final Map.Entry<String, ByteIterator> e : result.entrySet()) {
        if (e.getValue() != null) {
            strResult.put(e.getKey(), e.getValue().toString());
        }
    }
    assertThat(strResult, hasEntry(ScyllaCQLClient.YCSB_KEY, DEFAULT_ROW_KEY));
    assertThat(strResult, hasEntry("field0", "value1"));
    assertThat(strResult, hasEntry("field1", "value2"));
}
Also used : Status(site.ycsb.Status) ByteIterator(site.ycsb.ByteIterator) StringByteIterator(site.ycsb.StringByteIterator) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 19 with ByteIterator

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

the class VoltDBClientTest method scanReadTest.

@Test
public void scanReadTest() {
    Assume.assumeTrue(haveDb);
    try {
        for (int z = 0; z < SCAN_RECORD_COUNT; z++) {
            // Create some test data
            final String insertKey = SCAN_KEY_PREFIX + z;
            // Insert row
            HashMap<String, ByteIterator> insertMap = new HashMap<String, ByteIterator>();
            for (int i = 0; i < NUM_FIELDS; i++) {
                insertMap.put(FIELD_PREFIX + i, new StringByteIterator("Data for " + SCAN_KEY_PREFIX + z + " element " + i));
            }
            voltClient.insert(TABLE_NAME, insertKey, insertMap);
        }
        final String firstInsertKey = SCAN_KEY_PREFIX + 0;
        final String lastInsertKey = SCAN_KEY_PREFIX + (SCAN_RECORD_COUNT - 1);
        final String beyondLastInsertKey = SCAN_KEY_PREFIX + (SCAN_RECORD_COUNT + 1);
        final String oneHundredFromEndInsertKey = SCAN_KEY_PREFIX + (SCAN_RECORD_COUNT - 101);
        final String fiftyFromEndInsertKey = SCAN_KEY_PREFIX + (SCAN_RECORD_COUNT - 101);
        // test non existent records
        singleScanReadTest(NON_EXISTENT_KEY, 1000, 0, NON_EXISTENT_KEY);
        // test single record
        singleScanReadTest(firstInsertKey, 1, 1, firstInsertKey);
        // test scan of SCAN_RECORD_COUNT records
        singleScanReadTest(firstInsertKey, SCAN_RECORD_COUNT, SCAN_RECORD_COUNT, lastInsertKey);
        // test single record in middle
        singleScanReadTest(oneHundredFromEndInsertKey, 1, 1, oneHundredFromEndInsertKey);
        // test request of 100 starting 50 from end.
        singleScanReadTest(fiftyFromEndInsertKey, 100, 50, lastInsertKey);
        // test request of 100 starting beyond the end
        singleScanReadTest(beyondLastInsertKey, 100, 0, lastInsertKey);
    } catch (Exception e) {
        e.printStackTrace();
        fail("Failed scanReadTest");
    }
}
Also used : ByteIterator(site.ycsb.ByteIterator) StringByteIterator(site.ycsb.StringByteIterator) HashMap(java.util.HashMap) StringByteIterator(site.ycsb.StringByteIterator) Assume.assumeNoException(org.junit.Assume.assumeNoException) DBException(site.ycsb.DBException)

Example 20 with ByteIterator

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

the class RestClientTest method insert_404.

@Test
public void insert_404() {
    HashMap<String, ByteIterator> data = new HashMap<String, ByteIterator>();
    data.put(DATA_TAG, new StringByteIterator(INPUT_DATA));
    Status status = rc.insert(null, ABSENT_RESOURCE, data);
    assertEquals(Status.NOT_FOUND, status);
}
Also used : Status(site.ycsb.Status) ByteIterator(site.ycsb.ByteIterator) StringByteIterator(site.ycsb.StringByteIterator) HashMap(java.util.HashMap) StringByteIterator(site.ycsb.StringByteIterator) Test(org.junit.Test)

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