/** * Add an index schema to the table schema * * @param indices New index schemas [Not null] */ public void addIndices(Collection<IndexSchema> indices) { checkNotNull(indices); for (IndexSchema entry : indices) { this.indices.add(entry); avroTableSchema.getIndices().put(entry.getIndexName(), entry.getAvroValue()); if (entry.getIsUnique()) { uniqueIndexCount++; } } }
/** * Remove an index schema from the table schema * * @param indexName Name of index schema [Not null, Not empty] */ public void removeIndex(String indexName) { Verify.isNotNullOrEmpty(indexName); IndexSchema schema = getIndexSchema(indexName); checkNotNull(schema); indices.remove(schema); avroTableSchema.getIndices().remove(indexName); if (schema.getIsUnique()) { uniqueIndexCount--; } }
/** * Construct a table schema from a map of column schemas and index schemas. * * @param columns Column schemas map [Not null] * @param indices Index schema map [Not null] */ public TableSchema(Collection<ColumnSchema> columns, Collection<IndexSchema> indices) { checkArgument(columns.size() > 0, "Table must have at least one column."); checkNotNull(indices); Map<String, AvroColumnSchema> columnSchemaMap = Maps.newHashMap(); for (ColumnSchema columnSchema : columns) { columnSchemaMap.put(columnSchema.getColumnName(), columnSchema.getAvroValue()); } Map<String, AvroIndexSchema> indexSchemaMap = Maps.newHashMap(); for (IndexSchema indexSchema : indices) { indexSchemaMap.put(indexSchema.getIndexName(), indexSchema.getAvroValue()); if (indexSchema.getIsUnique()) { uniqueIndexCount++; } } avroTableSchema = AvroTableSchema.newBuilder() .setColumns(columnSchemaMap) .setIndices(indexSchemaMap) .build(); this.columns = new LinkedList<ColumnSchema>(columns); this.indices = new LinkedList<IndexSchema>(indices); }
/** * Add the provided index information to 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 * @param serializedSchema The byte representation of the {@link IndexSchema} for this index, not null */ 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(); }