Search in sources :

Example 61 with ByteIterator

use of com.yahoo.ycsb.ByteIterator in project YCSB by brianfrankcooper.

the class HBaseClient10Test method testReadMissingRow.

@Test
public void testReadMissingRow() throws Exception {
    final HashMap<String, ByteIterator> result = new HashMap<String, ByteIterator>();
    final Status status = client.read(tableName, "Missing row", null, result);
    assertEquals(Status.NOT_FOUND, status);
    assertEquals(0, result.size());
}
Also used : Status(com.yahoo.ycsb.Status) StringByteIterator(com.yahoo.ycsb.StringByteIterator) ByteIterator(com.yahoo.ycsb.ByteIterator) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 62 with ByteIterator

use of com.yahoo.ycsb.ByteIterator in project YCSB by brianfrankcooper.

the class HBaseClient10Test method testScan.

@Test
public void testScan() throws Exception {
    // Fill with data
    final String colStr = "row_number";
    final byte[] col = Bytes.toBytes(colStr);
    final int n = 10;
    final List<Put> puts = new ArrayList<Put>(n);
    for (int i = 0; i < n; i++) {
        final byte[] key = Bytes.toBytes(String.format("%05d", i));
        final byte[] value = java.nio.ByteBuffer.allocate(4).putInt(i).array();
        final Put p = new Put(key);
        p.addColumn(Bytes.toBytes(COLUMN_FAMILY), col, value);
        puts.add(p);
    }
    table.put(puts);
    // Test
    final Vector<HashMap<String, ByteIterator>> result = new Vector<HashMap<String, ByteIterator>>();
    // Scan 5 records, skipping the first
    client.scan(tableName, "00001", 5, null, result);
    assertEquals(5, result.size());
    for (int i = 0; i < 5; i++) {
        final HashMap<String, ByteIterator> row = result.get(i);
        assertEquals(1, row.size());
        assertTrue(row.containsKey(colStr));
        final byte[] bytes = row.get(colStr).toArray();
        final ByteBuffer buf = ByteBuffer.wrap(bytes);
        final int rowNum = buf.getInt();
        assertEquals(i + 1, rowNum);
    }
}
Also used : StringByteIterator(com.yahoo.ycsb.StringByteIterator) ByteIterator(com.yahoo.ycsb.ByteIterator) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Vector(java.util.Vector) ByteBuffer(java.nio.ByteBuffer) Put(org.apache.hadoop.hbase.client.Put) Test(org.junit.Test)

Example 63 with ByteIterator

use of com.yahoo.ycsb.ByteIterator in project YCSB by brianfrankcooper.

the class HypertableClient 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) {
    // SELECT _columnFamily:fields FROM table WHERE (ROW >= startkey)
    // LIMIT recordcount MAX_VERSIONS 1;
    ScanSpec spec = new ScanSpec();
    RowInterval elem = new RowInterval();
    elem.setStart_inclusive(true);
    elem.setStart_row(startkey);
    spec.addToRow_intervals(elem);
    if (null != fields) {
        for (String field : fields) {
            spec.addToColumns(columnFamily + ":" + field);
        }
    }
    spec.setVersions(1);
    spec.setRow_limit(recordcount);
    SerializedCellsReader reader = new SerializedCellsReader(null);
    try {
        long sc = connection.scanner_open(ns, table, spec);
        String lastRow = null;
        boolean eos = false;
        while (!eos) {
            reader.reset(connection.scanner_get_cells_serialized(sc));
            while (reader.next()) {
                String currentRow = new String(reader.get_row());
                if (!currentRow.equals(lastRow)) {
                    result.add(new HashMap<String, ByteIterator>());
                    lastRow = currentRow;
                }
                result.lastElement().put(new String(reader.get_column_qualifier()), new ByteArrayByteIterator(reader.get_value()));
            }
            eos = reader.eos();
            if (debug) {
                System.out.println("Number of rows retrieved so far: " + result.size());
            }
        }
        connection.scanner_close(sc);
    } catch (ClientException e) {
        if (debug) {
            System.err.println("Error doing scan: " + e.message);
        }
        return Status.ERROR;
    } catch (TException e) {
        if (debug) {
            System.err.println("Error doing scan");
        }
        return Status.ERROR;
    }
    return Status.OK;
}
Also used : TException(org.apache.thrift.TException) ByteArrayByteIterator(com.yahoo.ycsb.ByteArrayByteIterator) ByteArrayByteIterator(com.yahoo.ycsb.ByteArrayByteIterator) ByteIterator(com.yahoo.ycsb.ByteIterator) ClientException(org.hypertable.thriftgen.ClientException) RowInterval(org.hypertable.thriftgen.RowInterval) SerializedCellsReader(org.hypertable.thrift.SerializedCellsReader) ScanSpec(org.hypertable.thriftgen.ScanSpec)

Example 64 with ByteIterator

use of com.yahoo.ycsb.ByteIterator in project YCSB by brianfrankcooper.

the class HypertableClient method read.

/**
   * Read a record from the database. Each field/value pair from the result will
   * be stored in a HashMap.
   *
   * @param table
   *          The name of the table
   * @param key
   *          The record key of the record to read.
   * @param fields
   *          The list of fields to read, or null for all of them
   * @param result
   *          A HashMap of field/value pairs for the result
   * @return Zero on success, a non-zero error code on error
   */
@Override
public Status read(String table, String key, Set<String> fields, HashMap<String, ByteIterator> result) {
    if (debug) {
        System.out.println("Doing read from Hypertable columnfamily " + columnFamily);
        System.out.println("Doing read for key: " + key);
    }
    try {
        if (null != fields) {
            Vector<HashMap<String, ByteIterator>> resMap = new Vector<HashMap<String, ByteIterator>>();
            if (!scan(table, key, 1, fields, resMap).equals(Status.OK)) {
                return Status.ERROR;
            }
            if (!resMap.isEmpty()) {
                result.putAll(resMap.firstElement());
            }
        } else {
            SerializedCellsReader reader = new SerializedCellsReader(null);
            reader.reset(connection.get_row_serialized(ns, table, key));
            while (reader.next()) {
                result.put(new String(reader.get_column_qualifier()), new ByteArrayByteIterator(reader.get_value()));
            }
        }
    } catch (ClientException e) {
        if (debug) {
            System.err.println("Error doing read: " + e.message);
        }
        return Status.ERROR;
    } catch (TException e) {
        if (debug) {
            System.err.println("Error doing read");
        }
        return Status.ERROR;
    }
    return Status.OK;
}
Also used : TException(org.apache.thrift.TException) ByteArrayByteIterator(com.yahoo.ycsb.ByteArrayByteIterator) ByteArrayByteIterator(com.yahoo.ycsb.ByteArrayByteIterator) ByteIterator(com.yahoo.ycsb.ByteIterator) HashMap(java.util.HashMap) ClientException(org.hypertable.thriftgen.ClientException) Vector(java.util.Vector) SerializedCellsReader(org.hypertable.thrift.SerializedCellsReader)

Example 65 with ByteIterator

use of com.yahoo.ycsb.ByteIterator in project YCSB by brianfrankcooper.

the class JdbcDBClientTest method insertRow.

/*
        Inserts a row of deterministic values for the given insertKey using the jdbcDBClient.
     */
private HashMap<String, ByteIterator> insertRow(String insertKey) {
    HashMap<String, ByteIterator> insertMap = new HashMap<String, ByteIterator>();
    for (int i = 0; i < 3; i++) {
        insertMap.put(FIELD_PREFIX + i, new StringByteIterator(buildDeterministicValue(insertKey, FIELD_PREFIX + i)));
    }
    jdbcDBClient.insert(TABLE_NAME, insertKey, insertMap);
    return insertMap;
}
Also used : StringByteIterator(com.yahoo.ycsb.StringByteIterator) ByteIterator(com.yahoo.ycsb.ByteIterator) HashMap(java.util.HashMap) StringByteIterator(com.yahoo.ycsb.StringByteIterator)

Aggregations

ByteIterator (com.yahoo.ycsb.ByteIterator)87 HashMap (java.util.HashMap)70 StringByteIterator (com.yahoo.ycsb.StringByteIterator)52 Status (com.yahoo.ycsb.Status)33 ByteArrayByteIterator (com.yahoo.ycsb.ByteArrayByteIterator)30 Test (org.junit.Test)30 DBException (com.yahoo.ycsb.DBException)20 Map (java.util.Map)14 IOException (java.io.IOException)8 EntityProperty (com.microsoft.azure.storage.table.EntityProperty)5 Vector (java.util.Vector)5 BaseDocument (com.arangodb.entity.BaseDocument)4 DynamicTableEntity (com.microsoft.azure.storage.table.DynamicTableEntity)4 DB (com.yahoo.ycsb.DB)4 ByteBuffer (java.nio.ByteBuffer)4 ArrayList (java.util.ArrayList)4 Put (org.apache.hadoop.hbase.client.Put)4 MongoCollection (com.allanbank.mongodb.MongoCollection)3 DocumentBuilder (com.allanbank.mongodb.bson.builder.DocumentBuilder)3 ArangoDBException (com.arangodb.ArangoDBException)3