/** * Deserialize a byte array into an index schema. * * @param serializedIndexSchema Byte array of the index schema [Not null] * @param indexName Name of the index [Not null, Not empty] * @return An index schema for the byte array. */ public static IndexSchema deserialize(byte[] serializedIndexSchema, String indexName) { checkNotNull(serializedIndexSchema); Verify.isNotNullOrEmpty(indexName); return new IndexSchema(indexName, Util.deserializeAvroObject(serializedIndexSchema, reader)); }
/** * Retrieve an index schema by name. * * @param indexName Name of index schema [Not null, Not empty] * @return Index schema by name indexName */ public IndexSchema getIndexSchema(String indexName) { Verify.isNotNullOrEmpty(indexName); AvroIndexSchema indexSchema = avroTableSchema.getIndices().get(indexName); return new IndexSchema(indexName, indexSchema); }
private TableSchema(AvroTableSchema avroTableSchema) { this.avroTableSchema = avroTableSchema; columns = Lists.newArrayList(); for (Map.Entry<String, AvroColumnSchema> entry : avroTableSchema.getColumns().entrySet()) { columns.add(new ColumnSchema(entry.getKey(), entry.getValue())); } indices = Lists.newArrayList(); for (Map.Entry<String, AvroIndexSchema> entry : avroTableSchema.getIndices().entrySet()) { indices.add(new IndexSchema(entry.getKey(), entry.getValue())); if (entry.getValue().getIsUnique()) { uniqueIndexCount++; } } }
@Test public void testIndexSchemaCreation() { new IndexSchema(INDEX_A, ImmutableList.<String>of(), true); }
@Test(expected = IllegalArgumentException.class) public void testIndexSchemaCreationEmptyIndexName() { new IndexSchema("", ImmutableList.<String>of(), true); }
@Test(expected = NullPointerException.class) public void testIndexSchemaCreationInvalidColumns() { new IndexSchema(INDEX_A, null, true); }
@Test(expected = NullPointerException.class) public void testIndexSchemaCreationNullIndexName() { new IndexSchema(null, ImmutableList.<String>of(), true); }
@Override public IndexSchema next() { Collections.shuffle(columnNames); List<String> columns = columnNames.subList(0, Math.min(lengthGen.next(), columnNames.size())); return new IndexSchema(MYSQL_NAME_GEN.next(), columns, RAND.nextBoolean()); } }
@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); }
@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(); }