Search in sources :

Example 31 with TableSchema

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

the class HandlerProxy method dropIndex.

/**
     * Drop the index specified by the index name from the table. The table must be open
     * before this operation can be performed.
     *
     * @param indexName The name of the index to add, not null or empty
     */
public void dropIndex(String indexName) {
    Verify.isNotNullOrEmpty(indexName, "The index name is invalid");
    checkTableOpen();
    TableSchema tableSchema = store.getSchema(tableName);
    IndexSchema indexSchema = tableSchema.getIndexSchema(indexName);
    table.deleteTableIndex(indexSchema);
    store.dropIndex(tableName, indexName);
}
Also used : AvroTableSchema(com.nearinfinity.honeycomb.mysql.gen.AvroTableSchema) TableSchema(com.nearinfinity.honeycomb.mysql.schema.TableSchema) IndexSchema(com.nearinfinity.honeycomb.mysql.schema.IndexSchema)

Example 32 with TableSchema

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

the class HandlerProxy method indexContainsDuplicate.

/**
     * Check whether the index contains a row with the same field values and a
     * distinct UUID.
     *
     * @param indexName
     * @param serializedRow
     * @return True If a duplicate is found, False otherwise
     */
public boolean indexContainsDuplicate(String indexName, byte[] serializedRow) {
    // This method must get its own table because it may be called during
    // a full table scan.
    Verify.isNotNullOrEmpty(indexName);
    checkNotNull(serializedRow);
    Row row = Row.deserialize(serializedRow);
    Table t = store.openTable(tableName);
    TableSchema schema = store.getSchema(tableName);
    IndexSchema indexSchema = schema.getIndexSchema(indexName);
    QueryKey key = new QueryKey(indexName, QueryType.EXACT_KEY, row.getRecords());
    Scanner scanner = t.indexScanExact(key);
    try {
        while (scanner.hasNext()) {
            Row next = Row.deserialize(scanner.next());
            if (!next.getUUID().equals(row.getUUID())) {
                // Special case for inserting nulls
                for (String column : indexSchema.getColumns()) {
                    boolean isNullInRecord = !row.getRecords().containsKey(column);
                    if (isNullInRecord) {
                        return false;
                    }
                }
                return true;
            }
        }
        return false;
    } finally {
        Util.closeQuietly(scanner);
        Util.closeQuietly(t);
    }
}
Also used : Scanner(com.nearinfinity.honeycomb.Scanner) Table(com.nearinfinity.honeycomb.Table) AvroTableSchema(com.nearinfinity.honeycomb.mysql.gen.AvroTableSchema) TableSchema(com.nearinfinity.honeycomb.mysql.schema.TableSchema) IndexSchema(com.nearinfinity.honeycomb.mysql.schema.IndexSchema)

Example 33 with TableSchema

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

the class RowOperationsIT method testUpdateNullRows.

@Test
public void testUpdateNullRows() {
    HandlerProxy proxy = factory.createHandlerProxy();
    List<ColumnSchema> columns = Lists.newArrayList();
    List<IndexSchema> indices = Lists.newArrayList();
    columns.add(ColumnSchema.builder(TestConstants.COLUMN1, ColumnType.LONG).build());
    TableSchema schema = new TableSchema(columns, indices);
    String tableName = AdapterType.HBASE.getName() + "/t1";
    int iterations = 10;
    proxy.createTable(tableName, schema.serialize(), 0);
    proxy.openTable(tableName);
    Row row = new Row(Maps.<String, ByteBuffer>newHashMap(), TestConstants.ZERO_UUID);
    List<Row> rows = new ArrayList<Row>();
    for (int j = 0; j < 50; j++) {
        for (int i = 0; i < iterations; i++) {
            proxy.insertRow(row.serialize());
        }
        proxy.flush();
        proxy.startTableScan();
        for (int i = 0; i < iterations; i++) {
            Row deserialized = Row.deserialize(proxy.getNextRow());
            deserialized.getRecords().put(TestConstants.COLUMN1, ITUtils.encodeValue(0));
            rows.add(deserialized);
        }
        proxy.endScan();
        for (Row r : rows) {
            proxy.updateRow(r.serialize(), r.serialize());
        }
        proxy.flush();
        rows.clear();
        proxy.startTableScan();
        for (int i = 0; i < iterations; i++) {
            byte[] bytes = proxy.getNextRow();
            assertNotNull(bytes);
            assertThat(Row.deserialize(bytes).getRecords().get(TestConstants.COLUMN1), equalTo(ITUtils.encodeValue(0)));
        }
        assertNull(proxy.getNextRow());
        proxy.endScan();
        proxy.truncateTable();
    }
    proxy.closeTable();
    proxy.dropTable(tableName);
}
Also used : TableSchema(com.nearinfinity.honeycomb.mysql.schema.TableSchema) HandlerProxy(com.nearinfinity.honeycomb.mysql.HandlerProxy) ArrayList(java.util.ArrayList) ColumnSchema(com.nearinfinity.honeycomb.mysql.schema.ColumnSchema) IndexSchema(com.nearinfinity.honeycomb.mysql.schema.IndexSchema) Row(com.nearinfinity.honeycomb.mysql.Row) HoneycombIntegrationTest(integrationtests.HoneycombIntegrationTest) Test(org.junit.Test)

Example 34 with TableSchema

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

the class VerifyTest method testHasAutoIncrementColumnNotAutoInc.

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

Aggregations

TableSchema (com.nearinfinity.honeycomb.mysql.schema.TableSchema)34 Test (org.junit.Test)17 IndexSchema (com.nearinfinity.honeycomb.mysql.schema.IndexSchema)12 ColumnSchema (com.nearinfinity.honeycomb.mysql.schema.ColumnSchema)9 IndexRowKey (com.nearinfinity.honeycomb.hbase.rowkey.IndexRowKey)5 AvroTableSchema (com.nearinfinity.honeycomb.mysql.gen.AvroTableSchema)5 Predicate (com.google.common.base.Predicate)1 ImmutableList (com.google.common.collect.ImmutableList)1 UnsignedBytes (com.google.common.primitives.UnsignedBytes)1 MockHTable (com.nearinfinity.honeycomb.MockHTable)1 Scanner (com.nearinfinity.honeycomb.Scanner)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 HoneycombIntegrationTest (integrationtests.HoneycombIntegrationTest)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1