Search in sources :

Example 6 with ColumnSchema

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

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

the class ColumnSchemaGenerator method next.

@Override
public ColumnSchema next() {
    ColumnType type = typeGen.next();
    ColumnSchema.Builder builder = ColumnSchema.builder(MYSQL_NAME_GEN.next(), type);
    switch(type) {
        case STRING:
        case BINARY:
            builder.setMaxLength(lengthGen.next());
            break;
        case LONG:
        case ULONG:
        case DOUBLE:
            builder.setIsAutoIncrement(RAND.nextBoolean());
            break;
        case DECIMAL:
            int precision = RAND.nextInt(66);
            int scale = RAND.nextInt(Math.max(31, precision));
            builder.setPrecision(precision).setScale(scale);
            break;
        default:
            break;
    }
    return builder.build();
}
Also used : ColumnType(com.nearinfinity.honeycomb.mysql.gen.ColumnType) ColumnSchema(com.nearinfinity.honeycomb.mysql.schema.ColumnSchema)

Example 8 with ColumnSchema

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

the class TableSchemaGenerator method next.

@Override
public TableSchema next() {
    final List<ColumnSchema> columnSchemas = COLUMNS_GEN.next();
    ImmutableList.Builder<String> columns = ImmutableList.builder();
    for (ColumnSchema columnSchema : columnSchemas) {
        columns.add(columnSchema.getColumnName());
    }
    final Generator<List<IndexSchema>> indexGen = CombinedGenerators.lists(new IndexSchemaGenerator(columns.build()), numIndicesGen);
    return new TableSchema(columnSchemas, indexGen.next());
}
Also used : TableSchema(com.nearinfinity.honeycomb.mysql.schema.TableSchema) ImmutableList(com.google.common.collect.ImmutableList) ColumnSchema(com.nearinfinity.honeycomb.mysql.schema.ColumnSchema) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList)

Example 9 with ColumnSchema

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

Example 10 with ColumnSchema

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

the class VerifyTest method testHasAutoIncrementColumn.

@Test
public void testHasAutoIncrementColumn() {
    final List<ColumnSchema> columns = ImmutableList.<ColumnSchema>of(ColumnSchema.builder(COLUMN_B, ColumnType.LONG).setIsAutoIncrement(true).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