/** * 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++; } } }
/** * 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); }