Search in sources :

Example 26 with ColumnSchema

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

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

the class BulkLoadMapper method checkSqlColumnsMatch.

private void checkSqlColumnsMatch(String sqlTable) {
    Set<String> expectedColumns = Sets.newHashSet();
    for (ColumnSchema column : schema.getColumns()) {
        expectedColumns.add(column.getColumnName());
    }
    List<String> invalidColumns = Lists.newLinkedList();
    for (String column : columns) {
        if (!expectedColumns.contains(column)) {
            LOG.error("Found non-existent column " + column);
            invalidColumns.add(column);
        }
    }
    if (invalidColumns.size() > 0) {
        String expectedColumnString = Joiner.on(",").join(expectedColumns);
        String invalidColumnString = Joiner.on(",").join(invalidColumns);
        String message = String.format("In table %s following columns (%s)" + " are not valid columns. Expected columns (%s)", sqlTable, invalidColumnString, expectedColumnString);
        throw new IllegalStateException(message);
    }
}
Also used : ColumnSchema(com.nearinfinity.honeycomb.mysql.schema.ColumnSchema)

Example 28 with ColumnSchema

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

ColumnSchema (com.nearinfinity.honeycomb.mysql.schema.ColumnSchema)28 Test (org.junit.Test)22 TableSchema (com.nearinfinity.honeycomb.mysql.schema.TableSchema)9 IndexSchema (com.nearinfinity.honeycomb.mysql.schema.IndexSchema)5 Predicate (com.google.common.base.Predicate)1 ImmutableList (com.google.common.collect.ImmutableList)1 UnsignedBytes (com.google.common.primitives.UnsignedBytes)1 RowKey (com.nearinfinity.honeycomb.hbase.rowkey.RowKey)1 HandlerProxy (com.nearinfinity.honeycomb.mysql.HandlerProxy)1 Row (com.nearinfinity.honeycomb.mysql.Row)1 ColumnType (com.nearinfinity.honeycomb.mysql.gen.ColumnType)1 HoneycombIntegrationTest (integrationtests.HoneycombIntegrationTest)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 HTableInterface (org.apache.hadoop.hbase.client.HTableInterface)1 Bytes (org.apache.hadoop.hbase.util.Bytes)1