Package com.nearinfinity.honeycomb.mysql.schema

Examples of com.nearinfinity.honeycomb.mysql.schema.IndexSchema


        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();
    }
View Full Code Here


    }

    @Test(expected = IllegalArgumentException.class)
    public void testIsValidIndexSchemaInvalidColumn() {
        final List<IndexSchema> indices = ImmutableList.of(
                new IndexSchema("index_name", ImmutableList.of("invalid"), false)
        );

        Verify.isValidIndexSchema(indices, COLUMNS);
    }
View Full Code Here

    @Test
    public void testLookupIndexIdsValidTableId() {
        final TableSchema tableSchema = new TableSchema(
                COLUMN_SCHEMAS,
                ImmutableList.of(new IndexSchema(INDEX_NAME, Lists.newArrayList(COLUMN_NAME), false))
        );

        hbaseMetadata.createTable(TABLE_NAME, tableSchema);
        final long tableId = hbaseMetadata.getTableId(TABLE_NAME);
View Full Code Here

    public void testCreateIndexEmptyIndexName() {
        hbaseMetadata.createTableIndex(1, getIndexEmpty(""));
    }

    private IndexSchema getIndexEmpty(String indexName) {
        return new IndexSchema(indexName, new ArrayList<String>(), false);
    }
View Full Code Here

        assertNotNull(schemaBefore);
        assertTrue(schemaBefore.getIndices().isEmpty());

        // Add a new index to the table
        hbaseMetadata.createTableIndex(tableId,
                new IndexSchema(INDEX_NAME, ImmutableList.<String>of(COLUMN_NAME), false));

        // Verify that the table schema has been correctly updated

        final TableSchema schemaAfter = hbaseMetadata.getSchema(tableId);
        assertNotNull(schemaAfter);

        final Collection<IndexSchema> schemaIndices = schemaAfter.getIndices();
        assertEquals(1, schemaIndices.size());


        final IndexSchema newIndexDetails = Iterables.find(schemaIndices, indexPredicate);
        assertNotNull(newIndexDetails);

        final List<String> indexColumns = newIndexDetails.getColumns();
        assertEquals(1, indexColumns.size());
        assertEquals(COLUMN_NAME, indexColumns.get(0));

        assertEquals(false, newIndexDetails.getIsUnique());

        // Verify that the new index has been stored correctly
        final Map<String, Long> tableIndexInfo = hbaseMetadata.getIndexIds(tableId);
        assertEquals(1, tableIndexInfo.size());
        assertTrue(tableIndexInfo.containsKey(INDEX_NAME));
View Full Code Here

    @Test
    public void testDeleteIndex() {
        final TableSchema tableSchema =
                new TableSchema(COLUMN_SCHEMAS,
                        ImmutableList.<IndexSchema>of(
                                new IndexSchema(INDEX_NAME, Lists.newArrayList(COLUMN_NAME), false)));

        // Create a new table with the configured details
        hbaseMetadata.createTable(TABLE_NAME, tableSchema);
        final long tableId = hbaseMetadata.getTableId(TABLE_NAME);


        // Verify that the table schema contains indices after creation

        final TableSchema schemaBefore = hbaseMetadata.getSchema(tableId);
        assertNotNull(schemaBefore);

        final Collection<IndexSchema> schemaIndices = schemaBefore.getIndices();
        assertEquals(1, schemaIndices.size());

        final IndexSchema newIndexDetails = Iterables.find(schemaIndices, indexPredicate);
        assertNotNull(newIndexDetails);

        final List<String> indexColumns = newIndexDetails.getColumns();
        assertEquals(1, indexColumns.size());
        assertEquals(COLUMN_NAME, indexColumns.get(0));

        // Verify that the index exists after table creation
        final Map<String, Long> tableIndexInfo = hbaseMetadata.getIndexIds(tableId);
View Full Code Here

    @Test
    public void testIndexRowKeyStrings() {
        String columnName = "c1";
        String indexName = "i1";
        ColumnSchema columnSchema = ColumnSchema.builder("default", ColumnType.DATETIME).build();
        IndexSchema indexSchema = new IndexSchema(indexName, ImmutableList.of(columnName), false);
        TableSchema tableSchema = new TableSchema(ImmutableList.of(columnSchema), ImmutableList.of(indexSchema));

        Generator<RowKey> rowkeysGen = RowKeyGenerator.getAscIndexRowKeyGenerator(tableSchema);
        List<RowKey> rowkeys = Lists.newArrayList(Iterables.toIterable(rowkeysGen));
        Collections.sort(rowkeys);
View Full Code Here

    public void addIndex(String indexName, byte[] serializedSchema) {
        Verify.isNotNullOrEmpty(indexName, "The index name is invalid");
        checkNotNull(serializedSchema, "Schema cannot be null");
        checkTableOpen();

        IndexSchema schema = IndexSchema.deserialize(serializedSchema, indexName);
        checkArgument(!schema.getIsUnique(), "Honeycomb does not support adding unique indices without a table rebuild.");

        store.addIndex(tableName, schema);
        table.insertTableIndex(schema);
        table.flush();
    }
View Full Code Here

    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);
    }
View Full Code Here

        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;
                        }
                    }
View Full Code Here

TOP

Related Classes of com.nearinfinity.honeycomb.mysql.schema.IndexSchema

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.