/** * Create a {@link ColumnSchema} based on fields in the builder. * * @return Column Schema */ public ColumnSchema build() { return new ColumnSchema(columnName, type, isNullable, isAutoIncrement, maxLength, scale, precision); } }
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++; } } }
/** * Retrieve a column schema by name. * * @param columnName Name of index schema [Not null, Not empty] * @return Index schema by name indexName */ public ColumnSchema getColumnSchema(String columnName) { Verify.isNotNullOrEmpty(columnName); AvroColumnSchema columnSchema = avroTableSchema.getColumns().get(columnName); return new ColumnSchema(columnName, columnSchema); }
/** * Deserialize a byte array into a column schema. * * @param serializedColumnSchema Byte array of the column schema * @param columnName Column name * @return An column schema for the byte array. */ public static ColumnSchema deserialize(byte[] serializedColumnSchema, String columnName) { checkNotNull(serializedColumnSchema); Verify.isNotNullOrEmpty(columnName); return new ColumnSchema(columnName, Util.deserializeAvroObject(serializedColumnSchema, reader)); }
@Test(expected = NullPointerException.class) public void testColumnSchemaCreationInvalidColumnSchema() { new ColumnSchema(TEST_COLUMN, null); }