Search in sources :

Example 1 with QueryKey

use of com.nearinfinity.honeycomb.mysql.QueryKey in project honeycomb by altamiracorp.

the class ITUtils method assertRowCount.

/**
     * Check that the table open on the proxy has the expected number of data rows
     * and index rows on each index (checks both ascending and descending
     * directions).  Note: this could be very slow for big tables.
     * @param proxy HandlerProxy with table already open
     * @param schema TableSchema of open table
     * @param expectedRowCount Expected number of rows
     */
public static void assertRowCount(final HandlerProxy proxy, final TableSchema schema, final long expectedRowCount) {
    checkState(proxy.getTableName() != null, "Proxy must have an open table.");
    checkNotNull(schema);
    verifyRowCount(expectedRowCount);
    proxy.startTableScan();
    assertResultCount(proxy, expectedRowCount);
    proxy.endScan();
    QueryKey queryKey;
    for (IndexSchema indexSchema : schema.getIndices()) {
        queryKey = new QueryKey(indexSchema.getIndexName(), QueryType.INDEX_FIRST, ImmutableMap.<String, ByteBuffer>of());
        proxy.startIndexScan(queryKey.serialize());
        assertResultCount(proxy, expectedRowCount);
        proxy.endScan();
        queryKey = new QueryKey(indexSchema.getIndexName(), QueryType.INDEX_LAST, ImmutableMap.<String, ByteBuffer>of());
        proxy.startIndexScan(queryKey.serialize());
        assertResultCount(proxy, expectedRowCount);
        proxy.endScan();
    }
}
Also used : QueryKey(com.nearinfinity.honeycomb.mysql.QueryKey) IndexSchema(com.nearinfinity.honeycomb.mysql.schema.IndexSchema) ByteBuffer(java.nio.ByteBuffer)

Example 2 with QueryKey

use of com.nearinfinity.honeycomb.mysql.QueryKey in project honeycomb by altamiracorp.

the class MySqlBugIT method testInsertBuildsIndexCorrectlyOnNullColumns.

/*
    DROP TABLE if exists t1;
    CREATE TABLE t1(c1 BIGINT SIGNED NULL,c2 BIGINT SIGNED NULL , INDEX(c1, c2));
    INSERT INTO t1 VALUES
    (4611686018427387903, NULL),
    (4611686018427387903, NULL);

    SELECT * FROM t1 WHERE c1 = 4611686018427387903 AND c2 is null ORDER BY c1 ASC;
    Expected two rows
    Actual was zero rows
     */
@Test
public void testInsertBuildsIndexCorrectlyOnNullColumns() {
    final Map<String, ByteBuffer> map = Maps.newHashMap();
    map.put(TestConstants.COLUMN1, ITUtils.encodeValue(INDEX_COL_VALUE));
    final Row row = new Row(map, UUID.randomUUID());
    proxy.insertRow(row.serialize());
    proxy.flush();
    HashMap<String, ByteBuffer> keys = Maps.newHashMap();
    keys.put(TestConstants.COLUMN1, ITUtils.encodeValue(INDEX_COL_VALUE));
    keys.put(TestConstants.COLUMN2, null);
    final QueryKey key = new QueryKey(TestConstants.INDEX2, QueryType.EXACT_KEY, keys);
    ITUtils.assertReceivingDifferentRows(proxy, key, ROW_COUNT);
}
Also used : QueryKey(com.nearinfinity.honeycomb.mysql.QueryKey) Row(com.nearinfinity.honeycomb.mysql.Row) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 3 with QueryKey

use of com.nearinfinity.honeycomb.mysql.QueryKey in project honeycomb by altamiracorp.

the class MySqlBugIT method testUpdateNotChangingIndicesWhenUpdatedColumnNotInIndex.

/*
    DROP TABLE IF EXISTS t1;
    CREATE TABLE t1(c1 INT, c2 INT, INDEX(c1));
    INSERT INTO t1 VALUES(NULL, 1);
    UPDATE t1 SET c2=2 WHERE c1 IS NULL;
    Index scan: Null, 1
    Table scan: Null, 2
     */
@Test
public void testUpdateNotChangingIndicesWhenUpdatedColumnNotInIndex() {
    Map<String, ByteBuffer> values = Maps.newHashMap();
    values.put(TestConstants.COLUMN2, ITUtils.encodeValue(1));
    Row row = new Row(values, UUID.randomUUID());
    proxy.insertRow(row.serialize());
    proxy.flush();
    proxy.startTableScan();
    byte[] nextRow = proxy.getNextRow();
    row = Row.deserialize(nextRow);
    proxy.endScan();
    // update t1 set c2=2 where c1 is null
    row.getRecords().put(TestConstants.COLUMN2, ITUtils.encodeValue(2));
    proxy.updateRow(nextRow, row.serialize());
    Map<String, ByteBuffer> searchMap = Maps.newHashMap();
    searchMap.put(TestConstants.COLUMN1, null);
    QueryKey key = new QueryKey(TestConstants.INDEX1, QueryType.EXACT_KEY, searchMap);
    proxy.startIndexScan(key.serialize());
    Row result = Row.deserialize(proxy.getNextRow());
    assertEquals(result.getRecords().get(TestConstants.COLUMN2).getLong(), ITUtils.encodeValue(2).getLong());
    proxy.endScan();
}
Also used : QueryKey(com.nearinfinity.honeycomb.mysql.QueryKey) Row(com.nearinfinity.honeycomb.mysql.Row) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 4 with QueryKey

use of com.nearinfinity.honeycomb.mysql.QueryKey in project honeycomb by altamiracorp.

the class RowOperationsIT method testUpdateRow.

@Test
public void testUpdateRow() {
    final Map<String, ByteBuffer> map = Maps.newHashMap();
    map.put(TestConstants.COLUMN1, ITUtils.encodeValue(INDEX_COL_VALUE));
    map.put(TestConstants.COLUMN2, ITUtils.encodeValue(6));
    final Row row = new Row(map, UUID.randomUUID());
    proxy.insertRow(row.serialize());
    proxy.flush();
    final QueryKey key = ITUtils.createKey(INDEX_COL_VALUE, QueryType.EXACT_KEY);
    proxy.startIndexScan(key.serialize());
    final Row r = Row.deserialize(proxy.getNextRow());
    map.put(TestConstants.COLUMN1, ITUtils.encodeValue(3));
    final Row newRow = new Row(map, r.getUUID());
    proxy.updateRow(r.serialize(), newRow.serialize());
    proxy.flush();
    final byte[] result = proxy.getRow(Util.UUIDToBytes(r.getUUID()));
    assertThat(Row.deserialize(result), equalTo(newRow));
}
Also used : QueryKey(com.nearinfinity.honeycomb.mysql.QueryKey) Row(com.nearinfinity.honeycomb.mysql.Row) ByteBuffer(java.nio.ByteBuffer) HoneycombIntegrationTest(integrationtests.HoneycombIntegrationTest) Test(org.junit.Test)

Example 5 with QueryKey

use of com.nearinfinity.honeycomb.mysql.QueryKey in project honeycomb by altamiracorp.

the class ScanOperationsIT method testBeforeKeyScan.

@Test
public void testBeforeKeyScan() {
    ITUtils.insertData(proxy, 1, INDEX_COL_VALUE, TestConstants.FULL_UUID);
    ITUtils.insertData(proxy, 1, INDEX_COL_VALUE - 1, TestConstants.ZERO_UUID);
    ITUtils.insertData(proxy, ROW_COUNT, INDEX_COL_VALUE - 1);
    final QueryKey key = ITUtils.createKey(INDEX_COL_VALUE, QueryType.BEFORE_KEY);
    ITUtils.assertReceivingDifferentRows(proxy, key, ROW_COUNT + 1);
}
Also used : QueryKey(com.nearinfinity.honeycomb.mysql.QueryKey) HoneycombIntegrationTest(integrationtests.HoneycombIntegrationTest) Test(org.junit.Test)

Aggregations

QueryKey (com.nearinfinity.honeycomb.mysql.QueryKey)17 Test (org.junit.Test)16 HoneycombIntegrationTest (integrationtests.HoneycombIntegrationTest)14 Row (com.nearinfinity.honeycomb.mysql.Row)6 ByteBuffer (java.nio.ByteBuffer)6 IndexSchema (com.nearinfinity.honeycomb.mysql.schema.IndexSchema)3