Search in sources :

Example 6 with IndexSchema

use of com.nearinfinity.honeycomb.mysql.schema.IndexSchema 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 7 with IndexSchema

use of com.nearinfinity.honeycomb.mysql.schema.IndexSchema in project honeycomb by altamiracorp.

the class MySqlBugIT method getTableSchema.

/**
     * Provides the {@link com.nearinfinity.honeycomb.mysql.schema.TableSchema} to use for a test case
     *
     * @return The schema used for testing
     */
@Override
protected TableSchema getTableSchema() {
    final List<ColumnSchema> columns = Lists.newArrayList();
    final List<IndexSchema> indices = Lists.newArrayList();
    // Add nullable, non-autoincrementing columns
    columns.add(ColumnSchema.builder(TestConstants.COLUMN1, ColumnType.LONG).build());
    columns.add(ColumnSchema.builder(TestConstants.COLUMN2, ColumnType.LONG).build());
    // Add non-unique index on one column
    indices.add(new IndexSchema(TestConstants.INDEX1, Lists.newArrayList(TestConstants.COLUMN1), false));
    // Add non-unique compound index on (c1, c2)
    indices.add(new IndexSchema(TestConstants.INDEX2, Lists.newArrayList(TestConstants.COLUMN1, TestConstants.COLUMN2), false));
    // Add unique index on one column
    indices.add(new IndexSchema(TestConstants.INDEX3, Lists.newArrayList(TestConstants.COLUMN1), true));
    return new TableSchema(columns, indices);
}
Also used : TableSchema(com.nearinfinity.honeycomb.mysql.schema.TableSchema) ColumnSchema(com.nearinfinity.honeycomb.mysql.schema.ColumnSchema) IndexSchema(com.nearinfinity.honeycomb.mysql.schema.IndexSchema)

Example 8 with IndexSchema

use of com.nearinfinity.honeycomb.mysql.schema.IndexSchema in project honeycomb by altamiracorp.

the class Verify method isValidIndexSchema.

/**
     * Verifies that the index schema only index columns for columns that are available
     * @param indices A mapping of the index details, not null
     * @param columns A mapping of column details, not null
     * @throws NullPointerException Thrown if the indices or columns container is null
     * @throws IllegalArgumentException Thrown if a {@link IndexSchema} indexes
     *                                  a column that is not an available column
     */
public static void isValidIndexSchema(final Collection<IndexSchema> indices, final Collection<ColumnSchema> columns) {
    checkNotNull(indices);
    checkNotNull(columns);
    Set<String> columnNames = Sets.newHashSet();
    for (ColumnSchema column : columns) {
        columnNames.add(column.getColumnName());
    }
    for (final IndexSchema index : indices) {
        for (final String column : index.getColumns()) {
            if (!columnNames.contains(column)) {
                throw new IllegalArgumentException("Only columns in the table may be indexed.");
            }
        }
    }
}
Also used : ColumnSchema(com.nearinfinity.honeycomb.mysql.schema.ColumnSchema) IndexSchema(com.nearinfinity.honeycomb.mysql.schema.IndexSchema)

Example 9 with IndexSchema

use of com.nearinfinity.honeycomb.mysql.schema.IndexSchema in project honeycomb by altamiracorp.

the class HandlerProxyTest method testAddUniqueIndex.

@Test(expected = IllegalArgumentException.class)
public void testAddUniqueIndex() {
    when(storeFactory.createStore(anyString())).thenReturn(storageMock);
    when(storageMock.openTable(anyString())).thenReturn(tableMock);
    proxy.openTable(TEST_TABLE_NAME);
    verify(storeFactory, times(1)).createStore(eq(TEST_TABLE_NAME));
    verify(storageMock, times(1)).openTable(eq(TEST_TABLE_NAME));
    final IndexSchema uniqueIndex = new IndexSchema("uniqueIdx", ImmutableList.<String>of(TEST_COLUMN), true);
    proxy.addIndex(TEST_INDEX, uniqueIndex.serialize());
    verify(storageMock, never()).addIndex(eq(TEST_TABLE_NAME), eq(INDEX_SCHEMA));
    verify(tableMock, never()).insertTableIndex(eq(INDEX_SCHEMA));
    verify(tableMock, never()).flush();
}
Also used : IndexSchema(com.nearinfinity.honeycomb.mysql.schema.IndexSchema) Test(org.junit.Test)

Example 10 with IndexSchema

use of com.nearinfinity.honeycomb.mysql.schema.IndexSchema in project honeycomb by altamiracorp.

the class VerifyTest method testIsValidTableSchemaValidSchema.

@Test
public void testIsValidTableSchemaValidSchema() {
    final List<ColumnSchema> columns = ImmutableList.<ColumnSchema>of(ColumnSchema.builder(COLUMN_B, ColumnType.LONG).setIsAutoIncrement(true).build());
    Verify.isValidTableSchema(new TableSchema(columns, ImmutableList.<IndexSchema>of()));
}
Also used : TableSchema(com.nearinfinity.honeycomb.mysql.schema.TableSchema) ColumnSchema(com.nearinfinity.honeycomb.mysql.schema.ColumnSchema) IndexSchema(com.nearinfinity.honeycomb.mysql.schema.IndexSchema) Test(org.junit.Test)

Aggregations

IndexSchema (com.nearinfinity.honeycomb.mysql.schema.IndexSchema)22 TableSchema (com.nearinfinity.honeycomb.mysql.schema.TableSchema)12 Test (org.junit.Test)10 ColumnSchema (com.nearinfinity.honeycomb.mysql.schema.ColumnSchema)5 QueryKey (com.nearinfinity.honeycomb.mysql.QueryKey)3 AvroTableSchema (com.nearinfinity.honeycomb.mysql.gen.AvroTableSchema)3 HoneycombIntegrationTest (integrationtests.HoneycombIntegrationTest)3 Scanner (com.nearinfinity.honeycomb.Scanner)2 ByteBuffer (java.nio.ByteBuffer)2 UnsignedBytes (com.google.common.primitives.UnsignedBytes)1 Table (com.nearinfinity.honeycomb.Table)1 IndexRowKeyBuilder (com.nearinfinity.honeycomb.hbase.rowkey.IndexRowKeyBuilder)1 RowKey (com.nearinfinity.honeycomb.hbase.rowkey.RowKey)1 HandlerProxy (com.nearinfinity.honeycomb.mysql.HandlerProxy)1 Row (com.nearinfinity.honeycomb.mysql.Row)1 ArrayList (java.util.ArrayList)1 Bytes (org.apache.hadoop.hbase.util.Bytes)1