Search in sources :

Example 6 with ByteIterator

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

the class ElasticsearchIntegTestBase method testUpdate.

/**
 * Test of update method, of class ElasticsearchClient.
 */
@Test
public void testUpdate() {
    final HashMap<String, ByteIterator> newValues = new HashMap<>(10);
    for (int i = 1; i <= 10; i++) {
        newValues.put(FIELD_PREFIX + i, new StringByteIterator("newvalue" + i));
    }
    final Status updateResult = db.update(MOCK_TABLE, "1", newValues);
    assertEquals(Status.OK, updateResult);
    // validate that the values changed
    final HashMap<String, ByteIterator> resultParam = new HashMap<>(10);
    final Status readResult = db.read(MOCK_TABLE, "1", MOCK_DATA.keySet(), resultParam);
    assertEquals(Status.OK, readResult);
    for (int i = 1; i <= 10; 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) Test(org.junit.Test)

Example 7 with ByteIterator

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

the class GoogleBigtableClient method scan.

@Override
public Status scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
    setTable(table);
    RowFilter filter = RowFilter.newBuilder().setFamilyNameRegexFilterBytes(ByteStringer.wrap(columnFamilyBytes)).build();
    if (fields != null && fields.size() > 0) {
        Builder filterChain = RowFilter.Chain.newBuilder();
        filterChain.addFilters(filter);
        filterChain.addFilters(RowFilter.newBuilder().setCellsPerColumnLimitFilter(1).build());
        int count = 0;
        // usually "field#" so pre-alloc
        final StringBuilder regex = new StringBuilder(fields.size() * 6);
        for (final String field : fields) {
            if (count++ > 0) {
                regex.append("|");
            }
            regex.append(field);
        }
        filterChain.addFilters(RowFilter.newBuilder().setColumnQualifierRegexFilter(ByteStringer.wrap(regex.toString().getBytes()))).build();
        filter = RowFilter.newBuilder().setChain(filterChain.build()).build();
    }
    final RowRange range = RowRange.newBuilder().setStartKeyClosed(ByteStringer.wrap(startkey.getBytes())).build();
    final RowSet rowSet = RowSet.newBuilder().addRowRanges(range).build();
    final ReadRowsRequest.Builder rrr = ReadRowsRequest.newBuilder().setTableNameBytes(ByteStringer.wrap(lastTableBytes)).setFilter(filter).setRows(rowSet);
    List<Row> rows;
    try {
        rows = client.readRowsAsync(rrr.build()).get();
        if (rows == null || rows.isEmpty()) {
            return Status.NOT_FOUND;
        }
        int numResults = 0;
        for (final Row row : rows) {
            final HashMap<String, ByteIterator> rowResult = new HashMap<String, ByteIterator>(fields != null ? fields.size() : 10);
            for (final Family family : row.getFamiliesList()) {
                if (Arrays.equals(family.getNameBytes().toByteArray(), columnFamilyBytes)) {
                    for (final Column column : family.getColumnsList()) {
                        // we should only have a single cell per column
                        rowResult.put(column.getQualifier().toString(UTF8_CHARSET), new ByteArrayByteIterator(column.getCells(0).getValue().toByteArray()));
                        if (debug) {
                            System.out.println("Result for field: " + column.getQualifier().toString(UTF8_CHARSET) + " is: " + column.getCells(0).getValue().toString(UTF8_CHARSET));
                        }
                    }
                }
            }
            result.add(rowResult);
            numResults++;
            if (numResults >= recordcount) {
                // if hit recordcount, bail out
                break;
            }
        }
        return Status.OK;
    } catch (InterruptedException e) {
        System.err.println("Interrupted during scan: " + e);
        Thread.currentThread().interrupt();
        return Status.ERROR;
    } catch (ExecutionException e) {
        System.err.println("Exception during scan: " + e);
        return Status.ERROR;
    }
}
Also used : HashMap(java.util.HashMap) Builder(com.google.bigtable.v2.RowFilter.Chain.Builder) RowSet(com.google.bigtable.v2.RowSet) ReadRowsRequest(com.google.bigtable.v2.ReadRowsRequest) ByteString(com.google.protobuf.ByteString) ByteArrayByteIterator(site.ycsb.ByteArrayByteIterator) RowFilter(com.google.bigtable.v2.RowFilter) ByteIterator(site.ycsb.ByteIterator) ByteArrayByteIterator(site.ycsb.ByteArrayByteIterator) RowRange(com.google.bigtable.v2.RowRange) Column(com.google.bigtable.v2.Column) Family(com.google.bigtable.v2.Family) Row(com.google.bigtable.v2.Row) DeleteFromRow(com.google.bigtable.v2.Mutation.DeleteFromRow) ExecutionException(java.util.concurrent.ExecutionException)

Example 8 with ByteIterator

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

the class TimeSeriesWorkload method verifyRow.

/**
 * Parses the values returned by a read or scan operation and determines whether
 * or not the integer value matches the hash and timestamp of the original timestamp.
 * Only works for raw data points, will not work for group-by's or downsampled data.
 * @param key The time series key.
 * @param cells The cells read by the DB.
 * @return {@link Status#OK} if the data matched or {@link Status#UNEXPECTED_STATE} if
 * the data did not match.
 */
protected Status verifyRow(final String key, final Map<String, ByteIterator> cells) {
    Status verifyStatus = Status.UNEXPECTED_STATE;
    long startTime = System.nanoTime();
    double value = 0;
    long timestamp = 0;
    final TreeMap<String, String> validationTags = new TreeMap<String, String>();
    for (final Entry<String, ByteIterator> entry : cells.entrySet()) {
        if (entry.getKey().equals(timestampKey)) {
            final NumericByteIterator it = (NumericByteIterator) entry.getValue();
            timestamp = it.getLong();
        } else if (entry.getKey().equals(valueKey)) {
            final NumericByteIterator it = (NumericByteIterator) entry.getValue();
            value = it.isFloatingPoint() ? it.getDouble() : it.getLong();
        } else {
            validationTags.put(entry.getKey(), entry.getValue().toString());
        }
    }
    if (validationFunction(key, timestamp, validationTags) == value) {
        verifyStatus = Status.OK;
    }
    long endTime = System.nanoTime();
    measurements.measure("VERIFY", (int) (endTime - startTime) / 1000);
    measurements.reportStatus("VERIFY", verifyStatus);
    return verifyStatus;
}
Also used : Status(site.ycsb.Status) NumericByteIterator(site.ycsb.NumericByteIterator) ByteIterator(site.ycsb.ByteIterator) StringByteIterator(site.ycsb.StringByteIterator) NumericByteIterator(site.ycsb.NumericByteIterator) TreeMap(java.util.TreeMap)

Example 9 with ByteIterator

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

the class RestWorkload method doTransactionUpdate.

@Override
public void doTransactionUpdate(DB db) {
    HashMap<String, ByteIterator> value = new HashMap<String, ByteIterator>();
    // Create random bytes of update data with a specific size.
    value.put("data", new RandomByteIterator(fieldlengthgenerator.nextValue().longValue()));
    db.update(null, getNextURL(4), value);
}
Also used : RandomByteIterator(site.ycsb.RandomByteIterator) ByteIterator(site.ycsb.ByteIterator) HashMap(java.util.HashMap) RandomByteIterator(site.ycsb.RandomByteIterator)

Example 10 with ByteIterator

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

the class TestTimeSeriesWorkload method verifyRow.

@Test
public void verifyRow() throws Exception {
    final Properties p = getUTProperties();
    final TimeSeriesWorkload wl = getWorkload(p, true);
    final TreeMap<String, String> validationTags = new TreeMap<String, String>();
    final HashMap<String, ByteIterator> cells = new HashMap<String, ByteIterator>();
    validationTags.put("AA", "AAAA");
    cells.put("AA", new StringByteIterator("AAAA"));
    validationTags.put("AB", "AAAB");
    cells.put("AB", new StringByteIterator("AAAB"));
    long hash = wl.validationFunction("AAAA", 1451606400L, validationTags);
    cells.put(TimeSeriesWorkload.TIMESTAMP_KEY_PROPERTY_DEFAULT, new NumericByteIterator(1451606400L));
    cells.put(TimeSeriesWorkload.VALUE_KEY_PROPERTY_DEFAULT, new NumericByteIterator(hash));
    assertEquals(wl.verifyRow("AAAA", cells), Status.OK);
    // tweak the last value a bit
    for (final ByteIterator it : cells.values()) {
        it.reset();
    }
    cells.put(TimeSeriesWorkload.VALUE_KEY_PROPERTY_DEFAULT, new NumericByteIterator(hash + 1));
    assertEquals(wl.verifyRow("AAAA", cells), Status.UNEXPECTED_STATE);
    // no value cell, returns an unexpected state
    for (final ByteIterator it : cells.values()) {
        it.reset();
    }
    cells.remove(TimeSeriesWorkload.VALUE_KEY_PROPERTY_DEFAULT);
    assertEquals(wl.verifyRow("AAAA", cells), Status.UNEXPECTED_STATE);
}
Also used : NumericByteIterator(site.ycsb.NumericByteIterator) ByteIterator(site.ycsb.ByteIterator) NumericByteIterator(site.ycsb.NumericByteIterator) StringByteIterator(site.ycsb.StringByteIterator) HashMap(java.util.HashMap) StringByteIterator(site.ycsb.StringByteIterator) Properties(java.util.Properties) TreeMap(java.util.TreeMap) Test(org.testng.annotations.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